Model Optimization

Introduction to Linear Modeling in Python

Jason Vestuto

Data Scientist

Residuals

2 panel figure, top plot scatter of sea level versus time and line plot of model, then bottom plot of residuals, showing difference between data and model from the top plot

 

residuals = y_model - y_data
len(residuals) == len(y_data)
True
Introduction to Linear Modeling in Python

Residuals Summed

2 panel figure, top plot scatter of sea level versus time and line plot of model, then bottom plot of residuals, showing difference between data and model from the top plot

 

residuals = y_model - y_data
print(np.sum(residuals))
0.0
Introduction to Linear Modeling in Python

Residuals Squared

2 panel figure, top plot scatter of sea level versus time and line plot of a poor model of constant value, then bottom plot of residuals as green dot markers and squared residuals as blue square markers

residuals_squared = np.square(y_model - y_data)
print(np.sum(residuals_squared))
65.1
Introduction to Linear Modeling in Python

RSS

2 panel figure, top plot scatter of sea level versus time and line plot of a poor model of constant value, then bottom plot of residuals as green dot markers and squared residuals as blue square markers

 

resid_squared = np.square(y_model - y_data)
RSS = np.sum(resid_squared)
Introduction to Linear Modeling in Python

RSS

2 panel figure, top plot scatter of sea level versus time and line plot of a better model, then bottom plot of residuals as green dot markers and squared residuals as blue square markers, but with a much better fit

 

RSS = np.sum(np.square(y_model - y_data))
print(RSS)
5.9
Introduction to Linear Modeling in Python

Variation of RSS

Plot of RSS y-axis values versus slope x-axis values, shaped as an up-turned parabola or well, with minimum at the bottom near slope=25

  • Minimum value of RSS gives minimum residuals
  • Minimum residuals give the best model
Introduction to Linear Modeling in Python

Let's practice!

Introduction to Linear Modeling in Python

Preparing Video For Download...