Download scripts/train_time_series.py from Fred808/Insta-AI: direct link, hf CLI and curl.
- Browser
- Download file 814 Bytes
-
https://huggingface.co/spaces/Fred808/Insta-AI/resolve/main/scripts/train_time_series.py
- Command line
-
hf download hf://spaces/Fred808/Insta-AI/scripts/train_time_series.py
-
curl -L -o train_time_series.py https://huggingface.co/spaces/Fred808/Insta-AI/resolve/main/scripts/train_time_series.py
814 Bytes
| 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") | |