Professional Documents
Culture Documents
Lab No. 10
The students will be able to learn Regression Evaluation Methods
In [76]: data.head(3)
In [78]: X.shape
Out[78]: (200, 3)
In [79]: type(X)
Out[79]: pandas.core.frame.DataFrame
In [80]: y = data['Sales']
y.head()
Out[80]: 0 22.1
1 10.4
2 9.3
3 18.5
4 12.9
Name: Sales, dtype: float64
In [81]: print(y.shape)
(200,)
In [82]: print(type(y))
<class 'pandas.core.series.Series'>
In [85]: print(X_train.shape)
print(y_train.shape)
print(X_test.shape)
print(y_test.shape)
(140, 3)
(140,)
(60, 3)
(60,)
In [87]: lr = LinearRegression()
58 23.8
40 16.6
34 9.5
102 14.8
184 17.6
Name: Actual, dtype: float64
0 21.663183
1 16.441379
2 7.691446
3 17.916317
4 18.670471
Name: Predicted, dtype: float64
Evaluation Metric
In [106]: # Mean Absolute Error
from sklearn import metrics
import numpy as np
1.0548328405073326
1.9289249074665733
1.388857410775697
Lab Tasks:
1. Compare MAE, MSE and RMSE
2. Describe these evaluation techniques mathematically
Task 1
Mean absolute error (MAE) is a measure of difference between two continuous variables. ... The
Mean Absolute Error is given by: It is possible to express MAE as the sum of two components:
Quantity Disagreement and Allocation Disagreement.
The mean squared error tells you how close a regression line is to a set of points. It does this by
taking the distances from the points to the regression line (these distances are the “errors”) and
squaring them. The squaring is necessary to remove any negative signs. It also gives more weight
to larger differences. It’s called the mean squared error as you’re finding the average of a set of
errors.
Root Mean Square Error (RMSE) measures how much error there is between two data sets. In
other words, it compares a predicted value and an observed or known value. It's also known as
Root Mean Square Deviation and is one of the most widely used statistics in GIS
Task 2
Where:
xi is the measurement,
x is the true value.
The Mean Absolute Error(MAE) is the average of all absolute errors. The formula is: mean
absolute error
In [ ]: