-** Logistic regression that enables multi-class classification **
--A model that attempts to transform the linear predictor so that the range is [0,1] and the sum is 1.
--Largely divided into ** "nominal logistic regression" ** and ** "order logistic regression" **
(1) Name logistic: Multi-class classification when there is no special order between classes ** ex) Men = 0, Women = 1 **
(2) Order logistic: Multi-class classification when there is a special order between classes. ** ex) Like = 0, I don't like it so much = 1, I hate = 2 **
** This time I would like to analyze using the dataset of the sklearn library. ** **
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_digits
digits = load_digits()
X=digits.data
y=digits.target
images_with_labels = list(zip(digits.images,digits.target))
plt.figure(figsize=(15,6))
for idx,(image,label) in enumerate(images_with_labels[:10]):
plt.subplot(2,5,idx+1)
plt.imshow(image,cmap=plt.cm.gray_r,interpolation="nearest")
plt.title("{}".format(label),fontsize=25)
plt.show()
from sklearn.metrics import confusion_matrix
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
scaler=StandardScaler()
X_scaled=scaler.fit_transform(X)
X_train,X_test,y_train,y_test=train_test_split(X_scaled,y,random_state=0)
print(log_reg.score(X_train,y_train))
print(log_reg.score(X_test,y_test))
prediction=log_reg.predict(X_test)
confusion = confusion_matrix(prediction,y_test) #Mixed matrix generation
print(confusinon)
Recommended Posts