|
|
import pandas as pd |
|
|
from prophet import Prophet |
|
|
from sklearn.metrics import mean_absolute_error |
|
|
import joblib |
|
|
from utils.preprocessing import preprocess_data |
|
|
from huggingface_hub import HfApi, login |
|
|
import os |
|
|
|
|
|
def train_time_series(): |
|
|
"""Train the time-series model for optimal posting times.""" |
|
|
|
|
|
df = pd.read_json("data/raw/engagement_metrics.json") |
|
|
df = preprocess_data(df) |
|
|
|
|
|
|
|
|
time_series_data = df.groupby('posting_time').agg({'engagement_rate': 'mean'}).reset_index() |
|
|
time_series_data = time_series_data.rename(columns={'posting_time': 'ds', 'engagement_rate': 'y'}) |
|
|
|
|
|
|
|
|
prophet_model = Prophet() |
|
|
prophet_model.fit(time_series_data) |
|
|
|
|
|
|
|
|
joblib.dump(prophet_model, "prophet_model.pkl") |
|
|
|