Title: Fast C Hyperparameter Tuning
Slug: fast_c_hyperparameter_tuning
Summary: How to fast C hyperparameter tuning for logistic regression in scikit-learn for machine learning in Python.
Date: 2017-09-18 12:00
Category: Machine Learning
Tags: Logistic Regression
Authors: Chris Albon
Sometimes the characteristics of a learning algorithm allows us to search for the best hyperparameters significantly faster than either brute force or randomized model search methods.
scikit-learn's LogisticRegressionCV method includes a parameter Cs. If supplied a list, Cs is the candidate hyperparameter values to select from. If supplied a integer, Cs a list of that many candidate values will is drawn from a logarithmic scale between 0.0001 and and 10000 (a range of reasonable values for C).
In [4]:
# Load libraries
from sklearn import linear_model, datasets
In [5]:
# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target
In [6]:
# Create cross-validated logistic regression
clf = linear_model.LogisticRegressionCV(Cs=100)
# Train model
clf.fit(X, y)
Out[6]: