01.04.2015 Views

1FfUrl0

1FfUrl0

1FfUrl0

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5<br />

This means that we can now fit linear combinations of our features (ok, we have only<br />

one feature and a constant, but that will change soon) to the values. Let's<br />

consider the linear equation in Chapter 1, Getting Started with Python Machine Learning<br />

shown as follows:<br />

This can be replaced with the following equation (by replacing y with p):<br />

We can solve the equation for<br />

as shown in the following formula:<br />

We simply have to find the right coefficients such that the formula will give the<br />

lowest errors for all our pairs (xi, pi) in the dataset, which will be detected by<br />

Scikit-learn.<br />

After fitting the data to the class labels, the formula will give the probability for<br />

every new data point, x, that belongs to class 1. Refer to the following code:<br />

>>> from sklearn.linear_model import LogisticRegression<br />

>>> clf = LogisticRegression()<br />

>>> print(clf)<br />

LogisticRegression(C=1.0, class_weight=None, dual=False, fit_<br />

intercept=True, intercept_scaling=1, penalty=l2, tol=0.0001)<br />

[ 107 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!