Wednesday, July 3, 2024
HomeLanguagesPythonsklearn.metrics.max_error() function in Python

sklearn.metrics.max_error() function in Python

The max_error() function computes the maximum residual error. A metric that captures the worst-case error between the predicted value and the true value. This function compares each element (index wise) of both lists, tuples or data frames and returns the count of unmatched elements.

Syntax: sklearn.metrics.max_error(y_true, y_pred)

Parameters:

y_true: It accepts the true (correct) target values.

y_pred: It accepts the estimate target value.

Returns:

max_error:<float>: A positive floating-point value.

Example 1:

Python3




# Import required module
from sklearn.metrics import max_error
  
# Assign data
y_true = [6, 2, 5, 1]
y_pred = [4, 2, 7, 1]
  
# Compute max_error
print(max_error(y_true, y_pred))


Output :

2

In the above example, the elements in lists y_true and y_pred are different at index 0 and 2 only. Hence, 2 is the max_error.

Example 2:

Python3




# Import required module
from sklearn.metrics import max_error
  
# Assign data
y_true = [3.13,'GFG',56,57667]
y_pred = ['Geeks','for','Geeks',3000]
  
# Compute max_error
print(max_error(y_true, y_pred))


Output :

UFuncTypeError: ufunc ‘subtract’ did not contain a loop with signature
matching types (dtype(‘<U32’), dtype(‘<U32’)) -> dtype(‘<U32’)

In order to use max_error(), the elements of both the lists, tuple, data frame etc. should be of similar type.

Example 3:

Python3




# Import required module
from sklearn.metrics import max_error
  
# Assign data
List = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y_true = List
y_pred = List[::-1]
  
# Compute max_error
print(max_error(y_true, y_pred))


Output :

8

Here, there is only 1 matched element.

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments