Get startedGet started for free

Train a simple model

As you determined, you are dealing with a regression problem. So, now you're ready to build a model for a subsequent submission. But now, instead of building the simplest Linear Regression model as in the slides, let's build an out-of-box Random Forest model.

You will use the RandomForestRegressor class from the scikit-learn library.

Your objective is to train a Random Forest model with default parameters on the "store" and "item" features.

This exercise is part of the course

Winning a Kaggle Competition in Python

View Course

Exercise instructions

  • Read the train data using pandas.
  • Create a Random Forest object.
  • Train the Random Forest model on the "store" and "item" features with "sales" as a target.

Hands-on interactive exercise

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

import pandas as pd
from sklearn.ensemble import RandomForestRegressor

# Read the train data
train = ____.____('train.csv')

# Create a Random Forest object
rf = ____()

# Train a model
rf.fit(X=train[['store', ____]], y=train['____'])
Edit and Run Code