Digits Prediction in Logistic Regression in ML

Machine Learning courses with 100+ Real-time projects Start Now!!

Program 1

import matplotlib.pyplot as plt
from sklearn.datasets import load_digits

digits=load_digits()

digits

dir(digits)

digits.images[0]

plt.gray()
plt.matshow(digits.images[9])
plt.show()

for i in range(9):
    plt.matshow(digits.images[i])

digits.target[:10]

from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(digits.data,digits.target,test_size=0.2)

x_train

x_test

from sklearn.linear_model import LogisticRegression
model=LogisticRegression()

model.fit(x_train,y_train)

y_pred=model.predict(x_test)
y_pred

y_test

model.score(x_test,y_test)

from sklearn.metrics import confusion_matrix
cm=confusion_matrix(y_test,y_pred)
cm

import seaborn as se
plt.figure(figsize=(10,7))
se.heatmap(cm,annot=True)
plt.xlabel('Predication')
plt.ylabel('Truth')

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *