Variazione attorno alla tendenza
I dati non devono essere perfettamente lineari: ci può essere una certa variazione casuale o "dispersione" nelle misurazioni, che si traduce in variazione dei parametri del modello. Questa variazione sul parametro è quantificata dall'"errore standard" e si interpreta come "incertezza" nella stima del parametro del modello.
In questo esercizio userai ols da statsmodels per costruire un modello ed estrarre l'errore standard per ciascun parametro di quel modello.

Questo esercizio fa parte del corso
Introduzione alla modellazione lineare in Python
Istruzioni dell'esercizio
- Memorizza i dati precaricati in un DataFrame
df, etichettandox_datacometimesey_datacomedistances. - Usa
model_fit = ols().fit()per adattare un modello lineare della formaformula="distances ~ times"aidata=df. - Estrai l'intercetta stimata con
model_fit.params['Intercept']e l'errore standard dell'intercetta damodel_fit.bse['Intercept']. - Ripeti per il coefficiente angolare (slope) e poi stampa tutti e 4 con nomi esplicativi.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Store x_data and y_data, as times and distances, in df, and use ols() to fit a model to it.
df = pd.DataFrame(dict(____=x_data, ____=y_data))
model_fit = ols(____="distances ~ times", data=____).____()
# Extact the model parameters and their uncertainties
a0 = model_fit.____['Intercept']
e0 = model_fit.____['Intercept']
a1 = model_fit.____['times']
e1 = model_fit.____['times']
# Print the results with more meaningful names
print('Estimate of the intercept = {:0.2f}'.format(____))
print('Uncertainty of the intercept = {:0.2f}'.format(____))
print('Estimate of the slope = {:0.2f}'.format(____))
print('Uncertainty of the slope = {:0.2f}'.format(____))