- Univariate Regression - Open in Colab
- Multiple_regression - Open in Colab
- Demand Forecasting - Open in Colab
- ml_forecast_pymodeltime - Open in Colab
!pip install git+https://github.com/business-science/pymodeltime.git
from pymodeltime import ArimaReg, ProphetReg
from pymodeltime import ModelTimeTable, ModelTimeAccuracy, ModelTimeCalibration, ModelTimeForecast, ModelTimeRefit
from pymodeltime import MLModelWrapper, H2OAutoMLWrapper
from sklearn.ensemble import RandomForestRegressor
from xgboost import XGBRegressor
rf_model = RandomForestRegressor()
ml_rf_wrapper = MLModelWrapper(rf_model, feature_columns, "Random Forest")
##Machine Learning Model Integration
xgb_model = XGBRegressor()
ml_xgb_wrapper = MLModelWrapper(xgb_model, feature_columns, "XGBoost")
# Fit the models
ml_rf_wrapper.fit(train_data, y_train)
ml_xgb_wrapper.fit(train_data, y_train)
from pymodeltime import AutoGluonTabularWrapper
auto_gluon_wrapper = AutoGluonTabularWrapper(target_column="GDP")
auto_gluon_wrapper.fit(train_data)
quantile_predictions = auto_gluon_wrapper.predict_quantiles(test_data)
h2o.init()
# Convert to H2OFrame and train
h2o_train = h2o.H2OFrame(train_data)
automl = H2OAutoML(max_models=10, seed=1, max_runtime_secs=300)
automl.train(x=feature_columns, y='GDP', training_frame=h2o_train)
# Extract the leaderboard
lb = automl.leaderboard
lb_df = lb.as_data_frame()
print(lb_df.head())
# Get the best model
best_h2o_model = automl.leader
h2o_automl_wrapper = H2OAutoMLWrapper(best_h2o_model, target_column='GDP')
prophet_model_multi = ProphetReg(seasonality_yearly=True, seasonality_weekly=True,
seasonality_daily=False, changepoint_range=0.5,
prior_scale_seasonality=5.0, season='multiplicative',
interval_width=0.95)
prophet_model_multi.fit(train_data, target_column='GDP', date_column='date', regressors=feature_columns)
modeltime_table = ModelTimeTable(h2o_automl_wrapper, ml_xgb_wrapper, ml_rf_wrapper, prophet_model_multi)
model_time_calibrator = ModelTimeCalibration(modeltime_table, test_data, target_column='GDP')
model_time_calibrator.calibrate()
calibration_results_df = model_time_calibrator.get_calibration_results()
print(calibration_results_df)
modeltime_accuracy = ModelTimeAccuracy(modeltime_table, test_data, target_column='GDP')
accuracy_results = modeltime_accuracy.calculate_accuracy()
print(accuracy_results)