v Create Baseline Regression Model - Machine Learning

Create Baseline Regression Model

Preliminaries

# 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

Load Boston Housing Dataset

# Load data
boston = load_boston()

# Create features
X, y = boston.data, boston.target

Split Data Into Training And Test Set

# Make test and training split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

Create Dummy Regression Always Predicts The Mean Value Of Target

# Create a dummy regressor
dummy_mean = DummyRegressor(strategy='mean')

# "Train" dummy regressor
dummy_mean.fit(X_train, y_train)
DummyRegressor(constant=None, quantile=None, strategy='mean')

Create Dummy Regression Always Predicts A Constant Value

# Create a dummy regressor
dummy_constant = DummyRegressor(strategy='constant', constant=20)

# "Train" dummy regressor
dummy_constant.fit(X_train, y_train)
DummyRegressor(constant=array(20), quantile=None, strategy='constant')

Evaluate Performance Metric

# Get R-squared score
dummy_constant.score(X_test, y_test)  
-0.065105020293257265