LoslegenKostenlos loslegen

Explore model coefficients

You will now explore the model performance from a different angle, and only on the training data. One thing you learned in the latest lesson is that not all model coefficients are statistically significant and we should look at the model summary table to explore their significance. Fortunately, the statsmodels library provides this functionality. Once you print the model summary table, explore which variables have the p-value lower than 0.05 (i.e. lower than 5%) to make sure the coefficient is significant.

The training features are loaded as train_X, and the target variable as train_Y which was converted to a numpy array.

Diese Übung ist Teil des Kurses

Machine Learning for Marketing in Python

Kurs anzeigen

Anleitung zur Übung

  • Import the statsmodels.api module.
  • Initialize a model instance on the training data using the OLS() function.
  • Fit the model.
  • Print model summary using the .summary() method.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Import `statsmodels.api` module
import ___.___ as sm

# Initialize model instance on the training data
olsreg = sm.___(train_Y, train_X)

# Fit the model
olsreg = olsreg.___()

# Print model summary
print(olsreg.___())
Code bearbeiten und ausführen