-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload digits.py
146 lines (57 loc) · 1.32 KB
/
load digits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
# coding: utf-8
# In[23]:
from sklearn.datasets import load_digits
get_ipython().run_line_magic('matplotlib', 'inline')
import matplotlib.pyplot as plt
digits = load_digits()
# In[24]:
plt.gray()
for i in range(2):
plt.matshow(digits.images[i])
# In[25]:
dir(digits)
# In[26]:
digits.data[0]
# In[27]:
digits.images[4]
# In[28]:
plt.matshow(digits.images[9])
# In[29]:
digits.target[0:7]
# In[30]:
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
# In[31]:
from sklearn.model_selection import train_test_split
# In[32]:
X_train, X_test, y_train, y_test = train_test_split(digits.data,digits.target, test_size=0.2)
# In[33]:
model.fit(X_train, y_train)
# In[34]:
model.score(X_test, y_test)
# In[35]:
model.predict(digits.data[0:5])
# In[36]:
y_predicted = model.predict(X_test)
# In[37]:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_predicted)
cm
# In[38]:
import seaborn as sn
plt.figure(figsize = (10,7))
sn.heatmap(cm, annot=True)
plt.xlabel('Predicted')
plt.ylabel('Truth')
# In[44]:
model.predict([digits.data[6]])
# In[45]:
digits.target[5]
# In[46]:
model.predict([digits.data[5]])
# In[47]:
digits.target[6]
# In[48]:
model.predict([digits.data[6]])
# In[ ]: