2021-11-14 23:50:25 +01:00
|
|
|
from math import sqrt
|
2021-11-16 10:02:02 +01:00
|
|
|
from sklearn.metrics import mean_squared_error, mean_absolute_error, accuracy_score
|
|
|
|
|
from sklearn.metrics import confusion_matrix
|
2021-12-01 09:28:24 +01:00
|
|
|
import pandas as pd
|
|
|
|
|
|
2021-11-16 10:02:02 +01:00
|
|
|
def print_regression_metrics(y_true, y_pred):
|
2021-11-14 23:50:25 +01:00
|
|
|
rmse = sqrt(mean_squared_error(y_true, y_pred))
|
|
|
|
|
print("RMSE: %.2f" % rmse)
|
|
|
|
|
|
|
|
|
|
mae = mean_absolute_error(y_true, y_pred)
|
2021-11-16 10:02:02 +01:00
|
|
|
print("MAE: %.2f" % mae)
|
|
|
|
|
|
|
|
|
|
def print_classification_metrics(y_true, y_pred):
|
|
|
|
|
print("Accuracy: %.2f" % accuracy_score(y_true, y_pred))
|
2021-12-01 09:28:24 +01:00
|
|
|
print("Confusion Matrix: \n", confusion_matrix(y_true, y_pred))
|
|
|
|
|
|
|
|
|
|
def format_data_for_backtest(aggregated_data: pd.DataFrame, returns_col: str, only_test_data: pd.DataFrame, preds) -> pd.DataFrame:
|
|
|
|
|
backtest_data = aggregated_data.iloc[-only_test_data.shape[0]:].copy()[returns_col]
|
|
|
|
|
assert backtest_data.shape[0] == only_test_data.shape[0]
|
|
|
|
|
backtest_data = backtest_data.reset_index(drop=True)
|
|
|
|
|
return pd.concat([backtest_data, pd.Series(preds)], axis='columns')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def backtest()
|