-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[single_assessment] feat: add a base class for prediction evaluation
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score | ||
|
||
class PredictionsEvaluator: | ||
def __init__(self, predictions, ground_truths): | ||
self.predictions = predictions | ||
self.ground_truths = ground_truths | ||
self.metrics = self._evaluate_predictions() | ||
|
||
def _evaluate_predictions(self): | ||
metrics = {} | ||
metrics['mse'] = mean_squared_error(self.ground_truths, self.predictions) | ||
metrics['mae'] = mean_absolute_error(self.ground_truths, self.predictions) | ||
metrics['r2'] = r2_score(self.ground_truths, self.predictions) | ||
return metrics | ||
|
||
def get_metrics(self): | ||
return self.metrics |