Get startedGet started for free

Predicting house prices

Perhaps the most useful feature of statistical models like linear regression is that you can make predictions. That is, you specify values for each of the explanatory variables, feed them to the model, and get a prediction for the corresponding response variable. The code flow is as follows.

explanatory_data = pd.DataFrame({"explanatory_var": list_of_values})
predictions = model.predict(explanatory_data)
prediction_data = explanatory_data.assign(response_var=predictions)

Here, you'll make predictions for the house prices in the Taiwan real estate dataset.

taiwan_real_estate is available. The fitted linear regression model of house price versus number of convenience stores is available as mdl_price_vs_conv. For future exercises, when a model is available, it will also be fitted.

This exercise is part of the course

Introduction to Regression with statsmodels in Python

View Course

Hands-on interactive exercise

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

# Import numpy with alias np
____

# Create the explanatory_data 
explanatory_data = pd.____({'____': np.____(____)})

# Print it
____
Edit and Run Code