Title: Create Baseline Classification Model
Slug: create_baseline_classification_model
Summary: How to create a baseline classification model in scikit-learn for machine learning in Python.
Date: 2017-09-14 12:00
Category: Machine Learning
Tags: Model Evaluation
Authors: Chris Albon

Preliminaries


In [3]:
# Load libraries
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.model_selection import train_test_split

Load Iris Flower Dataset


In [4]:
# Load data
iris = load_iris()

# Create target vector and feature matrix
X, y = iris.data, iris.target

Split Data Into Training And Test Set


In [5]:
# Split into training and test set
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


In [6]:
# Create dummy classifer
dummy = DummyClassifier(strategy='uniform', random_state=1)

# "Train" model
dummy.fit(X_train, y_train)


Out[6]:
DummyClassifier(constant=None, random_state=1, strategy='uniform')

Evaluate Performance Metric


In [7]:
# Get accuracy score
dummy.score(X_test, y_test)


Out[7]:
0.42105263157894735