mirror of
https://github.com/Hestia-Homes/ML.git
synced 2026-06-08 11:17:25 +00:00
add smape
This commit is contained in:
parent
7a1b9aed5f
commit
8dd784255a
1 changed files with 14 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ Implementation of MLMetrics, all of which will have two methods:
|
|||
- Generate Plot Suite
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from typing import Union
|
||||
from sklearn.metrics import (
|
||||
|
|
@ -14,6 +15,18 @@ from sklearn.metrics import (
|
|||
)
|
||||
from core.interface.InterfaceMetrics import MLMetrics
|
||||
|
||||
# Define the function to return the SMAPE value
|
||||
def symmetric_mape(actual, predicted) -> float:
|
||||
|
||||
# Convert actual and predicted to numpy
|
||||
# array data type if not already
|
||||
if not all([isinstance(actual, np.ndarray), isinstance(predicted, np.ndarray)]):
|
||||
actual, predicted = np.array(actual), np.array(predicted)
|
||||
|
||||
return np.mean(
|
||||
np.abs(predicted - actual) / ((np.abs(predicted) + np.abs(actual)) / 2)
|
||||
)
|
||||
|
||||
|
||||
def metrics_factory(metrics_type: str) -> MLMetrics:
|
||||
metrics = {
|
||||
|
|
@ -34,7 +47,7 @@ class RegressionMetrics:
|
|||
median_absolute_error,
|
||||
mean_squared_error,
|
||||
mean_absolute_percentage_error,
|
||||
# max_error
|
||||
symmetric_mape,
|
||||
]
|
||||
|
||||
def generate_metrics(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue