ComeçarComece de graça

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.

Este exercício faz parte do curso

Analyzing Survey Data in Python

Ver curso

Instruções do exercício

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

Exercício interativo prático

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

# 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(____.____())
Editar e executar o código