import numpy as np
= np.array([[0.5, 1.5], [1,1], [1.5, 0.5], [3, 0.5], [2, 2], [1, 2.5]])
X = np.array([0, 0, 0, 1, 1, 1]) y
Scikit-Learn
Let’s work with logistic models using scikit-learn
.
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
= LogisticRegression()
lr_model 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.
LogisticRegression()
Make Predictions
= lr_model.predict(X)
y_pred
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