欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

a simple example of machine learning: Classification

程序员文章站 2022-04-01 16:11:35
...
# import datasets
from sklearn import datasets
# import svm
from sklearn import svm

# load dataset
digits = datasets.load_digits()

# affiche dataset
print(digits.data)
print(digits.target)


# 8*8 shape of dara arrays
digits.images[0] # 1er image

# support vector classification
clf = svm.SVC(gamma=0.001, C=100.)

# methode fit() : learn from the model [:-1] except the last item
clf.fit(digits.data[:-1], digits.target[:-1])

# use the last image for predicting [-1:] the last item
clf.predict(digits.data[-1:])