Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions machine_learning/forecasting/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from sklearn.preprocessing import Normalizer
from sklearn.svm import SVR
from statsmodels.tsa.statespace.sarimax import SARIMAX
Expand Down Expand Up @@ -78,6 +79,29 @@ def support_vector_regressor(x_train: list, x_test: list, train_user: list) -> f
return float(y_pred[0])


def random_forest_regressor(x_train: list, x_test: list, train_user: list) -> float:
"""
Fourth method: Random Forest Regressor
Random Forest is an ensemble learning method for regression that operates
by constructing a multitude of decision trees at training time and outputting
the mean prediction of the individual trees.

It is more robust than a single decision tree and less prone to overfitting.
Good for capturing nonlinear relationships in data.

input : training data (date, total_event) in list of float
where x = list of set (date and total event)
output : list of total user prediction in float

>>> random_forest_regressor([[5,2],[1,5],[6,2]], [[3,2]], [2,1,4])
1.95
"""
model = RandomForestRegressor(n_estimators=100, random_state=42)
model.fit(x_train, train_user)
prediction = model.predict(x_test)
return float(prediction[0])
Comment thread
poyea marked this conversation as resolved.


def interquartile_range_checker(train_user: list) -> float:
"""
Optional method: interquatile range
Expand Down Expand Up @@ -155,6 +179,7 @@ def data_safety_checker(list_vote: list, actual_result: float) -> bool:
),
sarimax_predictor(train_user, train_match, test_match),
support_vector_regressor(x_train, x_test, train_user),
random_forest_regressor(x_train, x_test, train_user),
]

# check the safety of today's data
Expand Down
Loading