In [ ]:
# Standard scientific Python imports
import matplotlib.pyplot as plt

# Import datasets, classifiers and performance metrics
from sklearn import datasets, svm, metrics
from sklearn.model_selection import train_test_split
from sklearn.neighbors import NearestCentroid
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
In [ ]:
digits = datasets.load_digits()
print(digits.images[0,:,:])
[[ 0.  0.  5. 13.  9.  1.  0.  0.]
 [ 0.  0. 13. 15. 10. 15.  5.  0.]
 [ 0.  3. 15.  2.  0. 11.  8.  0.]
 [ 0.  4. 12.  0.  0.  8.  8.  0.]
 [ 0.  5.  8.  0.  0.  9.  8.  0.]
 [ 0.  4. 11.  0.  1. 12.  7.  0.]
 [ 0.  2. 14.  5. 10. 12.  0.  0.]
 [ 0.  0.  6. 13. 10.  0.  0.  0.]]
In [ ]:
_, axes = plt.subplots(nrows=1, ncols=20, figsize=(20, 6))
for ax, image, label in zip(axes, digits.images, digits.target):
    ax.set_axis_off()
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")
    ax.set_title("Label: %i" % label)
In [ ]:
# flatten the images
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))
data.shape
#print(n_samples)
Out[ ]:
(1797, 64)
In [ ]:
# Split data into 50% train and 50% test subsets
X_train, X_test, y_train, y_test = train_test_split(
    data, digits.target, test_size=0.5, shuffle=False
)
print(X_train[0,:])
[ 0.  0.  5. 13.  9.  1.  0.  0.  0.  0. 13. 15. 10. 15.  5.  0.  0.  3.
 15.  2.  0. 11.  8.  0.  0.  4. 12.  0.  0.  8.  8.  0.  0.  5.  8.  0.
  0.  9.  8.  0.  0.  4. 11.  0.  1. 12.  7.  0.  0.  2. 14.  5. 10. 12.
  0.  0.  0.  0.  6. 13. 10.  0.  0.  0.]
In [ ]:

In [ ]:
# Learn the digits on the train subset
#model=NearestCentroid()
#model= svm.SVC()
#model = LogisticRegression()
#model = DecisionTreeClassifier()
#model = GaussianNB()
model = RandomForestClassifier(n_estimators=10,criterion='gini')

# fit the model
model.fit(X_train, y_train)

# Predict the value of the digit on the test subset
predicted = model.predict(X_test)
In [ ]:
from sklearn import tree
# Extract the first tree from the forest
estimator = model.estimators_[0]
tree.plot_tree(estimator, filled=True)
Out[ ]:
[Text(0.45829028925619836, 0.9615384615384616, 'x[42] <= 6.5\ngini = 0.899\nsamples = 576\nvalue = [93, 87, 84, 104, 93, 95, 86, 84, 91, 81]'),
 Text(0.2024793388429752, 0.8846153846153846, 'x[26] <= 5.5\ngini = 0.838\nsamples = 286\nvalue = [0, 46, 37, 99, 9, 85, 0, 66, 21, 80]'),
 Text(0.33038481404958675, 0.9230769230769231, 'True  '),
 Text(0.045454545454545456, 0.8076923076923077, 'x[10] <= 3.5\ngini = 0.683\nsamples = 117\nvalue = [0.0, 15.0, 26.0, 92.0, 0.0, 0.0, 0.0, 38.0, 2.0\n13.0]'),
 Text(0.01652892561983471, 0.7307692307692307, 'x[29] <= 13.0\ngini = 0.375\nsamples = 8\nvalue = [0, 12, 0, 0, 0, 0, 0, 4, 0, 0]'),
 Text(0.008264462809917356, 0.6538461538461539, 'gini = 0.0\nsamples = 5\nvalue = [0, 12, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.024793388429752067, 0.6538461538461539, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 0, 0, 4, 0, 0]'),
 Text(0.0743801652892562, 0.7307692307692307, 'x[43] <= 4.5\ngini = 0.637\nsamples = 109\nvalue = [0.0, 3.0, 26.0, 92.0, 0.0, 0.0, 0.0, 34.0, 2.0, 13.0]'),
 Text(0.04132231404958678, 0.6538461538461539, 'x[9] <= 0.5\ngini = 0.252\nsamples = 67\nvalue = [0, 0, 0, 89, 0, 0, 0, 2, 0, 13]'),
 Text(0.024793388429752067, 0.5769230769230769, 'x[29] <= 13.5\ngini = 0.485\nsamples = 25\nvalue = [0, 0, 0, 26, 0, 0, 0, 2, 0, 12]'),
 Text(0.01652892561983471, 0.5, 'gini = 0.0\nsamples = 13\nvalue = [0, 0, 0, 26, 0, 0, 0, 0, 0, 0]'),
 Text(0.03305785123966942, 0.5, 'x[27] <= 9.5\ngini = 0.245\nsamples = 12\nvalue = [0, 0, 0, 0, 0, 0, 0, 2, 0, 12]'),
 Text(0.024793388429752067, 0.4230769230769231, 'x[20] <= 8.5\ngini = 0.444\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 0, 0, 2, 0, 1]'),
 Text(0.01652892561983471, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 0, 0, 2, 0, 0]'),
 Text(0.03305785123966942, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.04132231404958678, 0.4230769230769231, 'gini = 0.0\nsamples = 9\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 11]'),
 Text(0.05785123966942149, 0.5769230769230769, 'x[60] <= 15.5\ngini = 0.031\nsamples = 42\nvalue = [0, 0, 0, 63, 0, 0, 0, 0, 0, 1]'),
 Text(0.049586776859504134, 0.5, 'gini = 0.0\nsamples = 31\nvalue = [0, 0, 0, 48, 0, 0, 0, 0, 0, 0]'),
 Text(0.06611570247933884, 0.5, 'x[36] <= 5.5\ngini = 0.117\nsamples = 11\nvalue = [0, 0, 0, 15, 0, 0, 0, 0, 0, 1]'),
 Text(0.05785123966942149, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.0743801652892562, 0.4230769230769231, 'gini = 0.0\nsamples = 10\nvalue = [0, 0, 0, 15, 0, 0, 0, 0, 0, 0]'),
 Text(0.10743801652892562, 0.6538461538461539, 'x[53] <= 1.5\ngini = 0.605\nsamples = 42\nvalue = [0, 3, 26, 3, 0, 0, 0, 32, 2, 0]'),
 Text(0.09917355371900827, 0.5769230769230769, 'gini = 0.0\nsamples = 22\nvalue = [0, 0, 0, 0, 0, 0, 0, 31, 0, 0]'),
 Text(0.11570247933884298, 0.5769230769230769, 'x[18] <= 4.0\ngini = 0.429\nsamples = 20\nvalue = [0, 3, 26, 3, 0, 0, 0, 1, 2, 0]'),
 Text(0.09917355371900827, 0.5, 'x[9] <= 5.0\ngini = 0.716\nsamples = 4\nvalue = [0, 3, 2, 3, 0, 0, 0, 1, 0, 0]'),
 Text(0.09090909090909091, 0.4230769230769231, 'x[29] <= 9.5\ngini = 0.611\nsamples = 3\nvalue = [0, 3, 2, 0, 0, 0, 0, 1, 0, 0]'),
 Text(0.08264462809917356, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 3, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.09917355371900827, 0.34615384615384615, 'x[41] <= 1.0\ngini = 0.444\nsamples = 2\nvalue = [0, 0, 2, 0, 0, 0, 0, 1, 0, 0]'),
 Text(0.09090909090909091, 0.2692307692307692, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 2, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.10743801652892562, 0.2692307692307692, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0]'),
 Text(0.10743801652892562, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 3, 0, 0, 0, 0, 0, 0]'),
 Text(0.1322314049586777, 0.5, 'x[29] <= 13.0\ngini = 0.142\nsamples = 16\nvalue = [0, 0, 24, 0, 0, 0, 0, 0, 2, 0]'),
 Text(0.12396694214876033, 0.4230769230769231, 'gini = 0.0\nsamples = 15\nvalue = [0, 0, 24, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.14049586776859505, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 2, 0]'),
 Text(0.359504132231405, 0.8076923076923077, 'x[2] <= 5.5\ngini = 0.787\nsamples = 169\nvalue = [0, 31, 11, 7, 9, 85, 0, 28, 19, 67]'),
 Text(0.29132231404958675, 0.7307692307692307, 'x[7] <= 1.5\ngini = 0.807\nsamples = 98\nvalue = [0, 29, 7, 7, 9, 7, 0, 24, 19, 49]'),
 Text(0.2830578512396694, 0.6538461538461539, 'x[19] <= 11.0\ngini = 0.792\nsamples = 90\nvalue = [0.0, 29.0, 7.0, 7.0, 9.0, 7.0, 0.0, 11.0, 19.0, 49.0]'),
 Text(0.21487603305785125, 0.5769230769230769, 'x[43] <= 4.5\ngini = 0.737\nsamples = 61\nvalue = [0.0, 3.0, 7.0, 7.0, 2.0, 7.0, 0.0, 11.0, 18.0, 45.0]'),
 Text(0.17355371900826447, 0.5, 'x[14] <= 0.5\ngini = 0.491\nsamples = 41\nvalue = [0, 2, 0, 7, 0, 7, 0, 2, 1, 43]'),
 Text(0.15702479338842976, 0.4230769230769231, 'x[25] <= 8.5\ngini = 0.719\nsamples = 19\nvalue = [0, 0, 0, 7, 0, 6, 0, 2, 1, 10]'),
 Text(0.1487603305785124, 0.34615384615384615, 'x[44] <= 10.5\ngini = 0.649\nsamples = 17\nvalue = [0, 0, 0, 7, 0, 1, 0, 2, 1, 10]'),
 Text(0.128099173553719, 0.2692307692307692, 'x[12] <= 12.0\ngini = 0.537\nsamples = 15\nvalue = [0, 0, 0, 7, 0, 1, 0, 0, 0, 10]'),
 Text(0.1115702479338843, 0.19230769230769232, 'x[52] <= 9.5\ngini = 0.278\nsamples = 5\nvalue = [0, 0, 0, 5, 0, 1, 0, 0, 0, 0]'),
 Text(0.10330578512396695, 0.11538461538461539, 'gini = 0.0\nsamples = 4\nvalue = [0, 0, 0, 5, 0, 0, 0, 0, 0, 0]'),
 Text(0.11983471074380166, 0.11538461538461539, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]'),
 Text(0.1446280991735537, 0.19230769230769232, 'x[37] <= 15.5\ngini = 0.278\nsamples = 10\nvalue = [0, 0, 0, 2, 0, 0, 0, 0, 0, 10]'),
 Text(0.13636363636363635, 0.11538461538461539, 'gini = 0.0\nsamples = 8\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 9]'),
 Text(0.15289256198347106, 0.11538461538461539, 'x[52] <= 7.5\ngini = 0.444\nsamples = 2\nvalue = [0, 0, 0, 2, 0, 0, 0, 0, 0, 1]'),
 Text(0.1446280991735537, 0.038461538461538464, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 2, 0, 0, 0, 0, 0, 0]'),
 Text(0.16115702479338842, 0.038461538461538464, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.16942148760330578, 0.2692307692307692, 'x[11] <= 9.0\ngini = 0.444\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 0, 0, 2, 1, 0]'),
 Text(0.16115702479338842, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 2, 0, 0]'),
 Text(0.17768595041322313, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.1652892561983471, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 5, 0, 0, 0, 0]'),
 Text(0.19008264462809918, 0.4230769230769231, 'x[29] <= 7.0\ngini = 0.156\nsamples = 22\nvalue = [0, 2, 0, 0, 0, 1, 0, 0, 0, 33]'),
 Text(0.18181818181818182, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]'),
 Text(0.19834710743801653, 0.34615384615384615, 'x[33] <= 3.0\ngini = 0.108\nsamples = 21\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 33]'),
 Text(0.19008264462809918, 0.2692307692307692, 'gini = 0.0\nsamples = 18\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 32]'),
 Text(0.2066115702479339, 0.2692307692307692, 'x[19] <= 8.5\ngini = 0.444\nsamples = 3\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.19834710743801653, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.21487603305785125, 0.19230769230769232, 'gini = 0.0\nsamples = 2\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.256198347107438, 0.5, 'x[54] <= 0.5\ngini = 0.704\nsamples = 20\nvalue = [0, 1, 7, 0, 2, 0, 0, 9, 17, 2]'),
 Text(0.2396694214876033, 0.4230769230769231, 'x[58] <= 3.5\ngini = 0.596\nsamples = 10\nvalue = [0, 1, 0, 0, 2, 0, 0, 9, 1, 2]'),
 Text(0.23140495867768596, 0.34615384615384615, 'x[42] <= 1.0\ngini = 0.722\nsamples = 6\nvalue = [0, 1, 0, 0, 2, 0, 0, 0, 1, 2]'),
 Text(0.2231404958677686, 0.2692307692307692, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 2]'),
 Text(0.2396694214876033, 0.2692307692307692, 'x[27] <= 8.5\ngini = 0.625\nsamples = 4\nvalue = [0, 1, 0, 0, 2, 0, 0, 0, 1, 0]'),
 Text(0.23140495867768596, 0.19230769230769232, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 2, 0, 0, 0, 0, 0]'),
 Text(0.24793388429752067, 0.19230769230769232, 'x[43] <= 8.5\ngini = 0.5\nsamples = 2\nvalue = [0, 1, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.2396694214876033, 0.11538461538461539, 'gini = 0.0\nsamples = 1\nvalue = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.256198347107438, 0.11538461538461539, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.24793388429752067, 0.34615384615384615, 'gini = 0.0\nsamples = 4\nvalue = [0, 0, 0, 0, 0, 0, 0, 9, 0, 0]'),
 Text(0.2727272727272727, 0.4230769230769231, 'x[63] <= 2.0\ngini = 0.423\nsamples = 10\nvalue = [0, 0, 7, 0, 0, 0, 0, 0, 16, 0]'),
 Text(0.2644628099173554, 0.34615384615384615, 'x[51] <= 15.5\ngini = 0.198\nsamples = 7\nvalue = [0, 0, 2, 0, 0, 0, 0, 0, 16, 0]'),
 Text(0.256198347107438, 0.2692307692307692, 'gini = 0.0\nsamples = 6\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 16, 0]'),
 Text(0.2727272727272727, 0.2692307692307692, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 2, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.2809917355371901, 0.34615384615384615, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 5, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.3512396694214876, 0.5769230769230769, 'x[61] <= 9.0\ngini = 0.486\nsamples = 29\nvalue = [0, 26, 0, 0, 7, 0, 0, 0, 1, 4]'),
 Text(0.32231404958677684, 0.5, 'x[27] <= 13.0\ngini = 0.622\nsamples = 11\nvalue = [0, 3, 0, 0, 7, 0, 0, 0, 0, 4]'),
 Text(0.30578512396694213, 0.4230769230769231, 'x[33] <= 2.0\ngini = 0.219\nsamples = 7\nvalue = [0, 1, 0, 0, 7, 0, 0, 0, 0, 0]'),
 Text(0.2975206611570248, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.3140495867768595, 0.34615384615384615, 'gini = 0.0\nsamples = 6\nvalue = [0, 0, 0, 0, 7, 0, 0, 0, 0, 0]'),
 Text(0.33884297520661155, 0.4230769230769231, 'x[4] <= 14.0\ngini = 0.444\nsamples = 4\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 4]'),
 Text(0.3305785123966942, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 4]'),
 Text(0.34710743801652894, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.38016528925619836, 0.5, 'x[37] <= 1.5\ngini = 0.08\nsamples = 18\nvalue = [0, 23, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.371900826446281, 0.4230769230769231, 'x[28] <= 10.0\ngini = 0.444\nsamples = 3\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.36363636363636365, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.38016528925619836, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.3884297520661157, 0.4230769230769231, 'gini = 0.0\nsamples = 15\nvalue = [0, 21, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.29958677685950413, 0.6538461538461539, 'gini = 0.0\nsamples = 8\nvalue = [0, 0, 0, 0, 0, 0, 0, 13, 0, 0]'),
 Text(0.42768595041322316, 0.7307692307692307, 'x[10] <= 13.5\ngini = 0.426\nsamples = 71\nvalue = [0, 2, 4, 0, 0, 78, 0, 4, 0, 18]'),
 Text(0.39669421487603307, 0.6538461538461539, 'x[53] <= 6.0\ngini = 0.642\nsamples = 8\nvalue = [0, 2, 0, 0, 0, 0, 0, 4, 0, 3]'),
 Text(0.3884297520661157, 0.5769230769230769, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 0, 0, 4, 0, 0]'),
 Text(0.4049586776859504, 0.5769230769230769, 'x[19] <= 14.5\ngini = 0.48\nsamples = 5\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 3]'),
 Text(0.39669421487603307, 0.5, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 3]'),
 Text(0.4132231404958678, 0.5, 'gini = 0.0\nsamples = 2\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.45867768595041325, 0.6538461538461539, 'x[29] <= 15.5\ngini = 0.328\nsamples = 63\nvalue = [0, 0, 4, 0, 0, 78, 0, 0, 0, 15]'),
 Text(0.45041322314049587, 0.5769230769230769, 'x[21] <= 10.5\ngini = 0.191\nsamples = 55\nvalue = [0, 0, 4, 0, 0, 78, 0, 0, 0, 5]'),
 Text(0.4297520661157025, 0.5, 'x[4] <= 5.5\ngini = 0.116\nsamples = 51\nvalue = [0, 0, 4, 0, 0, 77, 0, 0, 0, 1]'),
 Text(0.4132231404958678, 0.4230769230769231, 'x[27] <= 13.5\ngini = 0.444\nsamples = 5\nvalue = [0, 0, 3, 0, 0, 6, 0, 0, 0, 0]'),
 Text(0.4049586776859504, 0.34615384615384615, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 3, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.4214876033057851, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 6, 0, 0, 0, 0]'),
 Text(0.4462809917355372, 0.4230769230769231, 'x[21] <= 8.0\ngini = 0.054\nsamples = 46\nvalue = [0, 0, 1, 0, 0, 71, 0, 0, 0, 1]'),
 Text(0.4380165289256198, 0.34615384615384615, 'x[17] <= 11.5\ngini = 0.027\nsamples = 45\nvalue = [0, 0, 1, 0, 0, 71, 0, 0, 0, 0]'),
 Text(0.4297520661157025, 0.2692307692307692, 'gini = 0.0\nsamples = 41\nvalue = [0, 0, 0, 0, 0, 66, 0, 0, 0, 0]'),
 Text(0.4462809917355372, 0.2692307692307692, 'x[61] <= 8.0\ngini = 0.278\nsamples = 4\nvalue = [0, 0, 1, 0, 0, 5, 0, 0, 0, 0]'),
 Text(0.4380165289256198, 0.19230769230769232, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 5, 0, 0, 0, 0]'),
 Text(0.45454545454545453, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.45454545454545453, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.47107438016528924, 0.5, 'x[17] <= 1.5\ngini = 0.32\nsamples = 4\nvalue = [0, 0, 0, 0, 0, 1, 0, 0, 0, 4]'),
 Text(0.4628099173553719, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]'),
 Text(0.4793388429752066, 0.4230769230769231, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 4]'),
 Text(0.4669421487603306, 0.5769230769230769, 'gini = 0.0\nsamples = 8\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 10]'),
 Text(0.7141012396694215, 0.8846153846153846, 'x[53] <= 4.5\ngini = 0.844\nsamples = 290\nvalue = [93, 41, 47, 5, 84, 10, 86, 18, 70, 1]'),
 Text(0.58619576446281, 0.9230769230769231, '  False'),
 Text(0.6275826446280992, 0.8076923076923077, 'x[25] <= 2.5\ngini = 0.696\nsamples = 84\nvalue = [0, 22, 7, 0, 66, 2, 4, 18, 15, 0]'),
 Text(0.59400826446281, 0.7307692307692307, 'x[19] <= 15.5\ngini = 0.798\nsamples = 45\nvalue = [0, 17, 6, 0, 10, 0, 4, 18, 14, 0]'),
 Text(0.5681818181818182, 0.6538461538461539, 'x[36] <= 15.5\ngini = 0.73\nsamples = 30\nvalue = [0.0, 0.0, 6.0, 0.0, 8.0, 0.0, 2.0, 18.0, 13.0, 0.0]'),
 Text(0.5413223140495868, 0.5769230769230769, 'x[18] <= 9.5\ngini = 0.671\nsamples = 17\nvalue = [0, 0, 6, 0, 7, 0, 2, 0, 13, 0]'),
 Text(0.512396694214876, 0.5, 'x[13] <= 5.5\ngini = 0.613\nsamples = 10\nvalue = [0, 0, 6, 0, 7, 0, 1, 0, 1, 0]'),
 Text(0.49586776859504134, 0.4230769230769231, 'x[12] <= 9.0\ngini = 0.219\nsamples = 5\nvalue = [0, 0, 0, 0, 7, 0, 1, 0, 0, 0]'),
 Text(0.48760330578512395, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]'),
 Text(0.5041322314049587, 0.34615384615384615, 'gini = 0.0\nsamples = 4\nvalue = [0, 0, 0, 0, 7, 0, 0, 0, 0, 0]'),
 Text(0.5289256198347108, 0.4230769230769231, 'x[53] <= 0.5\ngini = 0.245\nsamples = 5\nvalue = [0, 0, 6, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.5206611570247934, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.5371900826446281, 0.34615384615384615, 'gini = 0.0\nsamples = 4\nvalue = [0, 0, 6, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.5702479338842975, 0.5, 'x[20] <= 1.5\ngini = 0.142\nsamples = 7\nvalue = [0, 0, 0, 0, 0, 0, 1, 0, 12, 0]'),
 Text(0.5619834710743802, 0.4230769230769231, 'x[3] <= 11.5\ngini = 0.444\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 0, 1, 0, 2, 0]'),
 Text(0.5537190082644629, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 2, 0]'),
 Text(0.5702479338842975, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]'),
 Text(0.5785123966942148, 0.4230769230769231, 'gini = 0.0\nsamples = 5\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 10, 0]'),
 Text(0.5950413223140496, 0.5769230769230769, 'x[3] <= 5.5\ngini = 0.1\nsamples = 13\nvalue = [0, 0, 0, 0, 1, 0, 0, 18, 0, 0]'),
 Text(0.5867768595041323, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 1, 0, 0, 0, 0, 0]'),
 Text(0.6033057851239669, 0.5, 'gini = 0.0\nsamples = 12\nvalue = [0, 0, 0, 0, 0, 0, 0, 18, 0, 0]'),
 Text(0.6198347107438017, 0.6538461538461539, 'x[27] <= 12.0\ngini = 0.384\nsamples = 15\nvalue = [0, 17, 0, 0, 2, 0, 2, 0, 1, 0]'),
 Text(0.6115702479338843, 0.5769230769230769, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 2, 0, 0, 0, 0, 0]'),
 Text(0.628099173553719, 0.5769230769230769, 'x[61] <= 13.5\ngini = 0.265\nsamples = 14\nvalue = [0, 17, 0, 0, 0, 0, 2, 0, 1, 0]'),
 Text(0.6198347107438017, 0.5, 'x[20] <= 15.5\ngini = 0.105\nsamples = 13\nvalue = [0, 17, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.6115702479338843, 0.4230769230769231, 'x[60] <= 12.0\ngini = 0.375\nsamples = 3\nvalue = [0, 3, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.6033057851239669, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.6198347107438017, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 3, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.628099173553719, 0.4230769230769231, 'gini = 0.0\nsamples = 10\nvalue = [0, 14, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.6363636363636364, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 2, 0, 0, 0]'),
 Text(0.6611570247933884, 0.7307692307692307, 'x[37] <= 4.5\ngini = 0.25\nsamples = 39\nvalue = [0, 5, 1, 0, 56, 2, 0, 0, 1, 0]'),
 Text(0.6528925619834711, 0.6538461538461539, 'x[17] <= 3.5\ngini = 0.617\nsamples = 6\nvalue = [0, 5, 1, 0, 0, 2, 0, 0, 1, 0]'),
 Text(0.6446280991735537, 0.5769230769230769, 'gini = 0.0\nsamples = 2\nvalue = [0, 5, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.6611570247933884, 0.5769230769230769, 'x[60] <= 9.0\ngini = 0.625\nsamples = 4\nvalue = [0, 0, 1, 0, 0, 2, 0, 0, 1, 0]'),
 Text(0.6528925619834711, 0.5, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]'),
 Text(0.6694214876033058, 0.5, 'x[26] <= 4.0\ngini = 0.5\nsamples = 2\nvalue = [0, 0, 1, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.6611570247933884, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.6776859504132231, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.6694214876033058, 0.6538461538461539, 'gini = 0.0\nsamples = 33\nvalue = [0, 0, 0, 0, 56, 0, 0, 0, 0, 0]'),
 Text(0.8006198347107438, 0.8076923076923077, 'x[36] <= 1.5\ngini = 0.798\nsamples = 206\nvalue = [93.0, 19.0, 40.0, 5.0, 18.0, 8.0, 82.0, 0.0, 55.0\n1.0]'),
 Text(0.7148760330578512, 0.7307692307692307, 'x[35] <= 6.5\ngini = 0.214\nsamples = 64\nvalue = [92, 0, 4, 0, 2, 1, 4, 0, 0, 1]'),
 Text(0.6859504132231405, 0.6538461538461539, 'x[13] <= 1.5\ngini = 0.062\nsamples = 58\nvalue = [92, 0, 0, 0, 0, 1, 2, 0, 0, 0]'),
 Text(0.6776859504132231, 0.5769230769230769, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 2, 0, 0, 0]'),
 Text(0.6942148760330579, 0.5769230769230769, 'x[27] <= 12.5\ngini = 0.021\nsamples = 57\nvalue = [92, 0, 0, 0, 0, 1, 0, 0, 0, 0]'),
 Text(0.6859504132231405, 0.5, 'gini = 0.0\nsamples = 56\nvalue = [92, 0, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.7024793388429752, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0]'),
 Text(0.743801652892562, 0.6538461538461539, 'x[50] <= 11.0\ngini = 0.691\nsamples = 6\nvalue = [0, 0, 4, 0, 2, 0, 2, 0, 0, 1]'),
 Text(0.7272727272727273, 0.5769230769230769, 'x[11] <= 10.5\ngini = 0.5\nsamples = 2\nvalue = [0, 0, 0, 0, 2, 0, 2, 0, 0, 0]'),
 Text(0.71900826446281, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 2, 0, 0, 0, 0, 0]'),
 Text(0.7355371900826446, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 2, 0, 0, 0]'),
 Text(0.7603305785123967, 0.5769230769230769, 'x[37] <= 5.5\ngini = 0.32\nsamples = 4\nvalue = [0, 0, 4, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.7520661157024794, 0.5, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 4, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.768595041322314, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]'),
 Text(0.8863636363636364, 0.7307692307692307, 'x[13] <= 8.5\ngini = 0.764\nsamples = 142\nvalue = [1, 19, 36, 5, 16, 7, 78, 0, 55, 0]'),
 Text(0.8285123966942148, 0.6538461538461539, 'x[1] <= 0.5\ngini = 0.607\nsamples = 90\nvalue = [0, 4, 28, 3, 16, 2, 76, 0, 3, 0]'),
 Text(0.8057851239669421, 0.5769230769230769, 'x[21] <= 0.5\ngini = 0.517\nsamples = 77\nvalue = [0, 3, 10, 3, 16, 2, 76, 0, 3, 0]'),
 Text(0.7851239669421488, 0.5, 'x[9] <= 2.5\ngini = 0.215\nsamples = 58\nvalue = [0, 1, 3, 0, 4, 2, 76, 0, 0, 0]'),
 Text(0.7768595041322314, 0.4230769230769231, 'x[61] <= 7.0\ngini = 0.159\nsamples = 56\nvalue = [0, 1, 0, 0, 4, 2, 76, 0, 0, 0]'),
 Text(0.7603305785123967, 0.34615384615384615, 'x[44] <= 11.5\ngini = 0.571\nsamples = 5\nvalue = [0, 0, 0, 0, 4, 2, 1, 0, 0, 0]'),
 Text(0.7520661157024794, 0.2692307692307692, 'x[28] <= 4.5\ngini = 0.444\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 2, 1, 0, 0, 0]'),
 Text(0.743801652892562, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 1, 0, 0, 0]'),
 Text(0.7603305785123967, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]'),
 Text(0.768595041322314, 0.2692307692307692, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 0, 4, 0, 0, 0, 0, 0]'),
 Text(0.7933884297520661, 0.34615384615384615, 'x[63] <= 1.5\ngini = 0.026\nsamples = 51\nvalue = [0, 1, 0, 0, 0, 0, 75, 0, 0, 0]'),
 Text(0.7851239669421488, 0.2692307692307692, 'gini = 0.0\nsamples = 50\nvalue = [0, 0, 0, 0, 0, 0, 75, 0, 0, 0]'),
 Text(0.8016528925619835, 0.2692307692307692, 'gini = 0.0\nsamples = 1\nvalue = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.7933884297520661, 0.4230769230769231, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 3, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8264462809917356, 0.5, 'x[59] <= 10.5\ngini = 0.705\nsamples = 19\nvalue = [0, 2, 7, 3, 12, 0, 0, 0, 3, 0]'),
 Text(0.8181818181818182, 0.4230769230769231, 'gini = 0.0\nsamples = 7\nvalue = [0, 0, 0, 0, 12, 0, 0, 0, 0, 0]'),
 Text(0.8347107438016529, 0.4230769230769231, 'x[52] <= 14.5\ngini = 0.684\nsamples = 12\nvalue = [0, 2, 7, 3, 0, 0, 0, 0, 3, 0]'),
 Text(0.8264462809917356, 0.34615384615384615, 'x[44] <= 10.0\ngini = 0.604\nsamples = 10\nvalue = [0, 0, 7, 3, 0, 0, 0, 0, 3, 0]'),
 Text(0.8181818181818182, 0.2692307692307692, 'x[46] <= 0.5\ngini = 0.42\nsamples = 9\nvalue = [0, 0, 7, 3, 0, 0, 0, 0, 0, 0]'),
 Text(0.8099173553719008, 0.19230769230769232, 'gini = 0.0\nsamples = 5\nvalue = [0, 0, 6, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8264462809917356, 0.19230769230769232, 'x[4] <= 7.5\ngini = 0.375\nsamples = 4\nvalue = [0, 0, 1, 3, 0, 0, 0, 0, 0, 0]'),
 Text(0.8181818181818182, 0.11538461538461539, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 1, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8347107438016529, 0.11538461538461539, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 0, 3, 0, 0, 0, 0, 0, 0]'),
 Text(0.8347107438016529, 0.2692307692307692, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 3, 0]'),
 Text(0.8429752066115702, 0.34615384615384615, 'gini = 0.0\nsamples = 2\nvalue = [0, 2, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8512396694214877, 0.5769230769230769, 'x[54] <= 0.5\ngini = 0.1\nsamples = 13\nvalue = [0, 1, 18, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8429752066115702, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.859504132231405, 0.5, 'gini = 0.0\nsamples = 12\nvalue = [0, 0, 18, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.9442148760330579, 0.6538461538461539, 'x[6] <= 5.0\ngini = 0.581\nsamples = 52\nvalue = [1.0, 15.0, 8.0, 2.0, 0.0, 5.0, 2.0, 0.0, 52.0, 0.0]'),
 Text(0.9049586776859504, 0.5769230769230769, 'x[3] <= 5.0\ngini = 0.524\nsamples = 48\nvalue = [1, 14, 8, 2, 0, 0, 2, 0, 52, 0]'),
 Text(0.8760330578512396, 0.5, 'x[11] <= 10.5\ngini = 0.445\nsamples = 11\nvalue = [0, 14, 5, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.8677685950413223, 0.4230769230769231, 'gini = 0.0\nsamples = 6\nvalue = [0, 14, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8842975206611571, 0.4230769230769231, 'x[27] <= 11.0\ngini = 0.278\nsamples = 5\nvalue = [0, 0, 5, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.8760330578512396, 0.34615384615384615, 'gini = 0.0\nsamples = 4\nvalue = [0, 0, 5, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.8925619834710744, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.9338842975206612, 0.5, 'x[46] <= 5.5\ngini = 0.248\nsamples = 37\nvalue = [1, 0, 3, 2, 0, 0, 2, 0, 51, 0]'),
 Text(0.9173553719008265, 0.4230769230769231, 'x[36] <= 8.0\ngini = 0.142\nsamples = 33\nvalue = [1, 0, 3, 0, 0, 0, 0, 0, 49, 0]'),
 Text(0.9090909090909091, 0.34615384615384615, 'x[26] <= 7.0\ngini = 0.56\nsamples = 5\nvalue = [1, 0, 3, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.9008264462809917, 0.2692307692307692, 'gini = 0.0\nsamples = 3\nvalue = [0, 0, 3, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.9173553719008265, 0.2692307692307692, 'x[42] <= 15.5\ngini = 0.5\nsamples = 2\nvalue = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.9090909090909091, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 1, 0]'),
 Text(0.9256198347107438, 0.19230769230769232, 'gini = 0.0\nsamples = 1\nvalue = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.9256198347107438, 0.34615384615384615, 'gini = 0.0\nsamples = 28\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 48, 0]'),
 Text(0.9504132231404959, 0.4230769230769231, 'x[5] <= 2.5\ngini = 0.667\nsamples = 4\nvalue = [0, 0, 0, 2, 0, 0, 2, 0, 2, 0]'),
 Text(0.9421487603305785, 0.34615384615384615, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 2, 0, 0, 0, 0, 0, 0]'),
 Text(0.9586776859504132, 0.34615384615384615, 'x[37] <= 15.5\ngini = 0.5\nsamples = 3\nvalue = [0, 0, 0, 0, 0, 0, 2, 0, 2, 0]'),
 Text(0.9504132231404959, 0.2692307692307692, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 0, 0, 0, 2, 0]'),
 Text(0.9669421487603306, 0.2692307692307692, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 0, 2, 0, 0, 0]'),
 Text(0.9834710743801653, 0.5769230769230769, 'x[49] <= 3.0\ngini = 0.278\nsamples = 4\nvalue = [0, 1, 0, 0, 0, 5, 0, 0, 0, 0]'),
 Text(0.9752066115702479, 0.5, 'x[5] <= 12.0\ngini = 0.444\nsamples = 3\nvalue = [0, 1, 0, 0, 0, 2, 0, 0, 0, 0]'),
 Text(0.9669421487603306, 0.4230769230769231, 'gini = 0.0\nsamples = 1\nvalue = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0]'),
 Text(0.9834710743801653, 0.4230769230769231, 'gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]'),
 Text(0.9917355371900827, 0.5, 'gini = 0.0\nsamples = 1\nvalue = [0, 0, 0, 0, 0, 3, 0, 0, 0, 0]')]
In [ ]:
disp = metrics.ConfusionMatrixDisplay.from_predictions(y_test, predicted)
accu = metrics.accuracy_score(y_test, predicted)
disp.figure_.suptitle("Confusion Matrix")
print(f"Confusion matrix:\n{disp.confusion_matrix}")
print('Overall Acuracy:{:.3}'.format(accu))
#disp.figure_.set_size_inches(10,8)
#disp.figure_.set_tight_layout('tight')
Confusion matrix:
[[87  0  0  0  1  0  0  0  0  0]
 [ 0 80  1  6  0  0  1  0  0  3]
 [ 2  3 72  6  0  1  0  0  0  2]
 [ 0  4  0 78  0  4  0  2  3  0]
 [ 3  5  0  0 74  0  7  1  0  2]
 [ 0  0  0  0  0 89  0  0  0  2]
 [ 0  0  1  0  0  0 89  0  1  0]
 [ 0  0  0  0  2  1  0 85  1  0]
 [ 0  4  6  3  1  6  0  4 63  1]
 [ 0  0  0  8  0  4  0  1  4 75]]
Overall Acuracy:0.881
In [ ]:
_, axes = plt.subplots(nrows=1, ncols=20, figsize=(20, 3))
for ax, image, prediction in zip(axes, X_test, predicted):
    ax.set_axis_off()
    image = image.reshape(8, 8)
    ax.imshow(image, cmap=plt.cm.gray_r, interpolation="nearest")
    ax.set_title(f"Pred.: {prediction}")
In [ ]:
import xgboost as xgb
In [ ]:
train = xgb.DMatrix(X_train, label=y_train)
test = xgb.DMatrix(X_test,label=y_test)
In [ ]:
para = {'max_depth':100,'eta':0.1, 'objective':'multi:softmax','num_class':10}
epochs = 100
model = xgb.train(para,train,epochs)
In [ ]:
fig, ax = plt.subplots(1,1,figsize=(20,20))
xgb.plot_tree(model,ax=ax)
Out[ ]:
<Axes: >
In [ ]:
predictions = model.predict(test)
In [ ]:
disp = metrics.ConfusionMatrixDisplay.from_predictions(y_test, predictions)
accu = metrics.accuracy_score(y_test, predictions)
disp.figure_.suptitle("Confusion Matrix")
print(f"Confusion matrix:\n{disp.confusion_matrix}")
print('Overall Acuracy:{:.3}'.format(accu))
#disp.figure_.set_size_inches(10,8)
#disp.figure_.set_tight_layout('tight')
Confusion matrix:
[[87  0  0  0  0  0  0  0  1  0]
 [ 0 75  0  2  1  0  0  1  1 11]
 [ 2  0 77  4  0  0  0  0  0  3]
 [ 0  3  0 75  0  2  0  3  7  1]
 [ 4  0  0  0 76  0  6  1  0  5]
 [ 0  1  0  0  0 83  1  0  0  6]
 [ 0  3  4  0  0  0 84  0  0  0]
 [ 0  0  0  0  1  4  0 83  1  0]
 [ 0  5  0  1  0  3  0  1 77  1]
 [ 2  1  0  0  0  2  0  0  2 85]]
Overall Acuracy:0.892
In [ ]:
import lightgbm as lgb
from sklearn import datasets, svm, metrics
import numpy as np
/usr/local/lib/python3.10/dist-packages/dask/dataframe/__init__.py:42: FutureWarning: 
Dask dataframe query planning is disabled because dask-expr is not installed.

You can install it with `pip install dask[dataframe]` or `conda install dask`.
This will raise in a future version.

  warnings.warn(msg, FutureWarning)
In [ ]:
d_train = lgb.Dataset(X_train, label=y_train)
In [ ]:
para = {'max_depth':10,
        'learning_rate':0.08,
        'objective':'multiclass',
        'num_class':10,
        'boosting_type':'gbdt',  # try dart also
        #'metric':['auc','binary_logloss'],
        'num_leaves':50}
epochs = 30
model = lgb.train(para,d_train,epochs)
[LightGBM] [Info] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000744 seconds.
You can set `force_row_wise=true` to remove the overhead.
And if memory is not enough, you can set `force_col_wise=true`.
[LightGBM] [Info] Total Bins 810
[LightGBM] [Info] Number of data points in the train set: 898, number of used features: 52
[LightGBM] [Info] Start training from score -2.300360
[LightGBM] [Info] Start training from score -2.289311
[LightGBM] [Info] Start training from score -2.289311
[LightGBM] [Info] Start training from score -2.278381
[LightGBM] [Info] Start training from score -2.311534
[LightGBM] [Info] Start training from score -2.289311
[LightGBM] [Info] Start training from score -2.300360
[LightGBM] [Info] Start training from score -2.300360
[LightGBM] [Info] Start training from score -2.345823
[LightGBM] [Info] Start training from score -2.322833
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
[LightGBM] [Warning] No further splits with positive gain, best gain: -inf
In [ ]:
predictions = model.predict(X_test)
print(predictions.shape)
(899, 10)
In [ ]:
best_preds = [np.argmax(line) for line in predictions]
In [ ]:
disp = metrics.ConfusionMatrixDisplay.from_predictions(y_test, best_preds)
accu = metrics.accuracy_score(y_test, best_preds)
disp.figure_.suptitle("Confusion Matrix")
print(f"Confusion matrix:\n{disp.confusion_matrix}")
print('Overall Acuracy:{:.3}'.format(accu))
Confusion matrix:
[[87  0  0  0  0  0  0  0  1  0]
 [ 0 73  0  6  1  0  0  1  0 10]
 [ 1  0 75  6  0  0  0  0  0  4]
 [ 0  1  1 75  0  4  0  5  5  0]
 [ 3  0  0  0 79  1  5  0  1  3]
 [ 1  1  0  0  0 81  2  1  0  5]
 [ 0  1  1  0  0  0 89  0  0  0]
 [ 0  0  0  0  1  5  0 82  1  0]
 [ 0  6  0  1  0  2  0  1 74  4]
 [ 2  0  0  4  0  3  0  0  3 80]]
Overall Acuracy:0.884
In [ ]: