Get startedGet started for free

Fitting a simple model: regression

In this exercise, you'll practice fitting a regression model using data from the California housing market. A DataFrame called housing is available in your workspace. It contains many variables of data (stored as columns). Can you find a relationship between the following two variables?

  • "MedHouseVal": the median house value for California districts (in $100,000s of dollars)
  • "AveRooms" : average number of rooms per dwelling

This exercise is part of the course

Machine Learning for Time Series Data in Python

View Course

Exercise instructions

  • Prepare X and y DataFrames using the data in housing.
    • X should be the Median House Value, y average number of rooms per dwelling.
  • Fit a regression model that uses these variables (remember to shape the variables correctly!).
  • Don't forget that each variable must be the correct shape for scikit-learn to use it!

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from sklearn import linear_model

# Prepare input and output DataFrames
X = ____
y = ____

# Fit the model
model = linear_model.LinearRegression()
model.fit(____)
Edit and Run Code