This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def train_node_classifier(model, graph, optimizer, criterion, n_epochs=200): | |
| for epoch in range(1, n_epochs + 1): | |
| model.train() | |
| optimizer.zero_grad() | |
| out = model(graph) | |
| loss = criterion(out[graph.train_mask], graph.y[graph.train_mask]) | |
| loss.backward() | |
| optimizer.step() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch.nn as nn | |
| class MLP(nn.Module): | |
| def __init__(self): | |
| super().__init__() | |
| self.layers = nn.Sequential( | |
| nn.Linear(dataset.num_node_features, 64), | |
| nn.ReLU(), | |
| nn.Linear(64, 32), | |
| nn.ReLU(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.ensemble import GradientBoostingClassifier | |
| from sklearn.metrics import log_loss | |
| custom_gbm = CustomGradientBoostingClassifier( | |
| n_estimators=20, | |
| learning_rate=0.1, | |
| max_depth=1 | |
| ) | |
| custom_gbm.fit(x, y) | |
| custom_gbm_log_loss = log_loss(y, custom_gbm.predict_proba(x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomGradientBoostingClassifier: | |
| def __init__(self, learning_rate, n_estimators, max_depth=1): | |
| self.learning_rate = learning_rate | |
| self.n_estimators = n_estimators | |
| self.max_depth = max_depth | |
| self.trees = [] | |
| def fit(self, X, y): | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.ensemble import GradientBoostingRegressor | |
| from sklearn.metrics import mean_squared_error | |
| custom_gbm = CustomGradientBoostingRegressor( | |
| n_estimators=20, | |
| learning_rate=0.1, | |
| max_depth=1 | |
| ) | |
| custom_gbm.fit(x, y) | |
| custom_gbm_rmse = mean_squared_error(y, custom_gbm.predict(x), squared=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomGradientBoostingRegressor: | |
| def __init__(self, learning_rate, n_estimators, max_depth=1): | |
| self.learning_rate = learning_rate | |
| self.n_estimators = n_estimators | |
| self.max_depth = max_depth | |
| self.trees = [] | |
| def fit(self, X, y): | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fbprophet import Prophet | |
| al_train_pp = al_train.to_timestamp(freq="M").reset_index() | |
| # Prophet requires specific column names: ds and y | |
| al_train_pp.columns = ["ds", "y"] | |
| # turning on only yearly seasonality as this is monthly data. | |
| # As the seasonality effects varies across years, we need multiplicative seasonality mode | |
| m = Prophet( | |
| seasonality_mode="multiplicative", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sktime.transformations.series.detrend import Deseasonalizer | |
| def create_forecaster_w_desesonalizer(sp=12, degree=1): | |
| # creating forecaster with LightGBM | |
| regressor = lgb.LGBMRegressor() | |
| forecaster = TransformedTargetForecaster( | |
| [ | |
| ("deseasonalize", Deseasonalizer(model="multiplicative", sp=sp)), | |
| ("detrend", Detrender(forecaster=PolynomialTrendForecaster(degree=degree))), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fh = np.arange(test_len) + 1 | |
| forecast = forecaster.predict(fh=fh) | |
| forecast_int = forecaster.predict_interval(fh=fh, coverage=coverage)['Coverage'][coverage] | |
| al_arima_mae, al_arima_mape = plot_forecast(al_train, al_test, forecast, forecast_int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| test_len = int(len(ts_al) * 0.3) | |
| al_train, al_test = ts_al.iloc[:-test_len], ts_al.iloc[-test_len:] | |
| forecaster = AutoARIMA(sp=12, suppress_warnings=True) | |
| forecaster.fit(al_train) | |
| forecaster.summary() |