File size: 814 Bytes
40fb94f 827161e 40fb94f 827161e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
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."""
# Load data
df = pd.read_json("data/raw/engagement_metrics.json")
df = preprocess_data(df)
# Prepare time-series data
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'})
# Train Prophet model
prophet_model = Prophet()
prophet_model.fit(time_series_data)
# Save the model locally
joblib.dump(prophet_model, "prophet_model.pkl")
|