CommencerCommencer gratuitement

Plotting data and linear model fit

In the previous exercises you have practiced how to fit and interpret the Poisson regression model. In this exercise you will visually analyze the crab data and then the model fit.

First, you will plot a linear fit to the data, which later on you will use to compare to Poisson regression fitted values.

Cet exercice fait partie du cours

Generalized Linear Models in Python

Afficher le cours

Instructions

  • Import seaborn and matplotlib libraries.
  • Using crab dataset plot the data points with width on the x-axis and sat on the y-axis, with jitter of 0.3 for the sat variable.
  • Add a linear model fit by setting the argument fit_reg to True.
  • Set 'color' of the line fit as 'green' and the 'label' as 'LM fit'.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Import libraries
import ____ as sns
import ____.pyplot as plt

# Plot the data points and linear model fit
sns.regplot(____, ____, data = ____,
            y_jitter = ____,
            fit_reg = ____,
            line_kws = {'color':____, 
                        'label':____})

# Print plot
plt.show()
Modifier et exécuter le code