Answers for "cannot import name 'mean_absolute_percentage_error' from 'sklearn.metrics' (C:\Users\Sergej\anaconda3\lib\site-packages\sklearn\metrics\__init__.py)"

1

mAPE python

def percentage_error(actual, predicted):
    res = np.empty(actual.shape)
    for j in range(actual.shape[0]):
        if actual[j] != 0:
            res[j] = (actual[j] - predicted[j]) / actual[j]
        else:
            res[j] = predicted[j] / np.mean(actual)
    return res

def mean_absolute_percentage_error(y_true, y_pred): 
    return np.mean(np.abs(percentage_error(np.asarray(y_true), np.asarray(y_pred)))) * 100
Posted by: Guest on June-07-2020

Code answers related to "cannot import name 'mean_absolute_percentage_error' from 'sklearn.metrics' (C:\Users\Sergej\anaconda3\lib\site-packages\sklearn\metrics\__init__.py)"

Python Answers by Framework

Browse Popular Code Answers by Language