LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Analyzing Survey Data in Python

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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(____.____())
Code bearbeiten und ausführen