Model Optimization

Introduzione alla modellazione lineare 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
Introduzione alla modellazione lineare 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
Introduzione alla modellazione lineare 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
Introduzione alla modellazione lineare 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)
Introduzione alla modellazione lineare 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
Introduzione alla modellazione lineare 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
Introduzione alla modellazione lineare in Python

Let's practice!

Introduzione alla modellazione lineare in Python

Preparing Video For Download...