■ SVM(Support Vector Machine)을 사용하는 방법을 보여준다.
▶ 예제 코드 (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 |
import sklearn.datasets as datasets import sklearn.linear_model as linear_model import sklearn.metrics as metrics import sklearn.svm as svm mnistBunch = datasets.load_digits() imageNDArray = mnistBunch.images imageCount = len(imageNDArray) imageNDArray = imageNDArray.reshape(len(imageNDArray), -1) labelNDArray = mnistBunch.target classifier = svm.SVC(gamma = 0.001) trainCount = int((imageCount / 4) * 3) trainImageNDArray = imageNDArray[:trainCount] trainLabelNDArray = labelNDArray[:trainCount] classifier.fit(trainImageNDArray, trainLabelNDArray) testCount = int((imageCount / 4)) testImageNDArray = imageNDArray[testCount:] testLabelList = labelNDArray[testCount:] predictionLabelList = classifier.predict(testImageNDArray) print("성능 리포트 :\n%s\n" %(metrics.classification_report(testLabelList, predictionLabelList))) """ 성능 리포트 : precision recall f1-score support 0 1.00 0.99 1.00 131 1 0.99 1.00 1.00 137 2 1.00 1.00 1.00 131 3 0.99 0.95 0.97 136 4 0.99 0.98 0.99 139 5 0.98 0.99 0.99 136 6 0.99 1.00 1.00 138 7 0.99 1.00 1.00 134 8 0.96 0.99 0.98 130 9 0.99 0.99 0.99 136 accuracy 0.99 1348 macro avg 0.99 0.99 0.99 1348 weighted avg 0.99 0.99 0.99 1348 """ |