Scikit-Learn

Let’s work with logistic models using scikit-learn

import numpy as np

X = np.array([[0.5, 1.5], [1,1], [1.5, 0.5], [3, 0.5], [2, 2], [1, 2.5]])
y = np.array([0, 0, 0, 1, 1, 1])

.

Fit the Model

  • We will first import the model
  • Then we’ll fit the model to the training data by calling fit()
from sklearn.linear_model import LogisticRegression

lr_model = LogisticRegression()
lr_model.fit(X, y)
LogisticRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

Make Predictions

y_pred = lr_model.predict(X)

print("Prediction on training set:", y_pred)
Prediction on training set: [0 0 0 1 1 1]

Calculate Accuracy

print("Accuracy on training set:", lr_model.score(X, y))
Accuracy on training set: 1.0