Title: Create Baseline Regression Model
Slug: create_baseline_regression_model
Summary: How to create a baseline regression model in scikit-learn for machine learning in Python.
Date: 2017-09-14 12:00
Category: Machine Learning
Tags: Model Evaluation
Authors: Chris Albon
In [23]:
# Load libraries
from sklearn.datasets import load_boston
from sklearn.dummy import DummyRegressor
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
In [24]:
# Load data
boston = load_boston()
# Create features
X, y = boston.data, boston.target
In [25]:
# Make test and training split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
In [26]:
# Create a dummy regressor
dummy_mean = DummyRegressor(strategy='mean')
# "Train" dummy regressor
dummy_mean.fit(X_train, y_train)
Out[26]:
In [27]:
# Create a dummy regressor
dummy_constant = DummyRegressor(strategy='constant', constant=20)
# "Train" dummy regressor
dummy_constant.fit(X_train, y_train)
Out[27]:
In [28]:
# Get R-squared score
dummy_constant.score(X_test, y_test)
Out[28]: