ComeçarComece de graça

Visualize model fit using regplot()

After having fitted and analyzed the model we can visualize it by plotting the observation points and the fitted logistic regression.

Using the plot you can visually understand the relationship of the explanatory variable and the response for the range of values of the explanatory variable.

We can use the regplot() function from the seaborn module for this. The regplot() function takes an argument logistic, which allows you to specify whether you wish to estimate the logistic regression model for the given data using True or False values. This will also produce the plot of the fit.

Recall that the model that you fitted previously:
$$ \log\bigg(\frac{y}{1-y}\bigg) = -0.3055 + 0.3791*\text{arsenic} $$

The dataset wells is already loaded in your workspace.

Este exercício faz parte do curso

Generalized Linear Models in Python

Ver curso

Instruções do exercício

  • Using the data wells to plot arsenic on the x-axis and switch on the y-axis.
  • Apply y_jitter of 0.03 to spread the values of the response for easier visualization.
  • Use True for argument logistic for the plot to overlay the logistic function on the given data and set confidence intervals argument ci to None which will not display confidence interval, but it will speed up the computation.
  • Display the plot using the plt.show().

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Plot arsenic and switch and add overlay with the logistic fit
sns.regplot(x = ____, y = ____, 
            y_jitter = ____,
            data = ____, 
            logistic = ____,
            ci = ____)

# Display the plot
____
Editar e executar o código