Open In App

sklearn.metrics.max_error() function in Python

Last Updated : 01 Nov, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads