-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
23 lines (16 loc) · 798 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from sklearn import datasets, metrics, svm
from sklearn.model_selection import train_test_split
if __name__ == "__main__":
digits = datasets.load_digits()
# flatten the images
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))
# Create a classifier: a support vector classifier
clf = svm.SVC(gamma=0.001)
# 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)
# Learn the digits on the train subset
clf.fit(X_train, y_train)
# Predict the value of the digit on the test subset
predicted = clf.predict(X_test)
print(f"Classification report for classifier {clf}:\n{metrics.classification_report(y_test, predicted)}\n")