Goodness-of-Fit

Introduction to Linear Modeling in Python

Jason Vestuto

Data Scientist

3 Different R's

Building Models:

  • RSS

Evaluating Models:

  • RMSE
  • R-squared
Introduction to Linear Modeling in Python

RMSE

residuals = y_model - y_data
RSS = np.sum( np.square(residuals) )
mean_squared_residuals = np.sum( np.square(residuals) ) / len(residuals)
MSE = np.mean( np.square(residuals) )
RMSE = np.sqrt(np.mean( np.square(residuals)))
RMSE = np.std(residuals)
Introduction to Linear Modeling in Python

R-Squared in Code

Deviations:

deviations = np.mean(y_data) - y_data
VAR = np.sum(np.square(deviations))

Residuals:

residuals = y_model - y_data
RSS = np.sum(np.square(residuals))

R-squared:

r_squared = 1 - (RSS / VAR)
r = correlation(y_data, y_model)
Introduction to Linear Modeling in Python

R-Squared in Data

Scatter plot of altitude versus distance with model line in red passing though points, both horizontal with zero slope

Introduction to Linear Modeling in Python

R-Squared in Data

Scatter plot of altitude versus distance with model line in red passing though points, both with small slight slope

Introduction to Linear Modeling in Python

R-Squared in Data

Scatter plot of altitude versus distance with model line in red passing though points, both with moderate slope, seen as a moderate incline

Introduction to Linear Modeling in Python

R-Squared in Data

Scatter plot of altitude versus distance with model line in red passing though points, both with moderate slope, seen as a steep incline

Introduction to Linear Modeling in Python

RMSE vs R-Squared

  • RMSE: how much variation is residual
  • R-squared: what fraction of variation is linear
Introduction to Linear Modeling in Python

Let's practice!

Introduction to Linear Modeling in Python

Preparing Video For Download...