29 lines
921 B
Python
29 lines
921 B
Python
import numpy as np
|
|
import pandas as pd
|
|
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
|
|
|
|
|
|
def mse(real_data: pd.Series, predictions: pd.Series) -> float:
|
|
"""
|
|
Calculates the mean squared error between the real data and the predictions.
|
|
"""
|
|
return round(
|
|
mean_squared_error(real_data.astype(np.float64), predictions.astype(np.float64)), 2
|
|
)
|
|
|
|
|
|
def mae(real_data: pd.Series, predictions: pd.Series) -> float:
|
|
"""
|
|
Calculates the mean absolute error between the real data and the predictions.
|
|
"""
|
|
return round(
|
|
mean_absolute_error(real_data.astype(np.float64), predictions.astype(np.float64)), 2
|
|
)
|
|
|
|
|
|
def r2(real_data: pd.Series, predictions: pd.Series) -> float:
|
|
"""
|
|
Calculates the R2 score between the real data and the predictions.
|
|
"""
|
|
return round(r2_score(real_data.astype(np.float64), predictions.astype(np.float64)), 2)
|