CommencerCommencer gratuitement

Fitting a linear regression model

An anonymous salary survey has been conducted annually since 2015 among European IT specialists. In 2018, hundreds of respondents volunteered to participate. Included in the survey data are the number of years of experience respondents had and their current salary.

You are going to analyze the relationship between these two variables to find out if more years of experience results in higher or lower salary.

Your independent variable is experience_years, and your dependent variable is current_salary.

The data has been loaded for you as data, along with statsmodels.api and pandas, as sm and pd, respectively.

Cet exercice fait partie du cours

Analyzing Survey Data in Python

Afficher le cours

Instructions

  • Define the variables, x and y.
  • Add the constant term.
  • Perform the OLS() regression and .fit() the model.
  • Print the summary table.

Exercice interactif pratique

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

# Define variable, x and y
x = salary_survey.____.____
y = salary_survey.____.____

# Add the constant term
x = ____.____(x)

# Perform .OLS() regression and fit
result = ____.____(y,x).____()

# Print the summary table
print(____.____())
Modifier et exécuter le code