■ 로직스틱 회귀 모델을 사용하는 방법을 보여준다.
▶ 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 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 |
import sklearn.datasets as datasets import sklearn.linear_model as linear_model import sklearn.metrics as metrics mnistBunch = datasets.load_digits() imageNDArray = mnistBunch.images imageCount = len(imageNDArray) imageNDArray = imageNDArray.reshape(len(imageNDArray), -1) labelNDArray = mnistBunch.target classifier = linear_model.LogisticRegression(C = 0.01, penalty = 'l2', tol = 0.01) 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))) """ STOP: TOTAL NO. of ITERATIONS REACHED LIMIT. Increase the number of iterations (max_iter) or scale the data as shown in: https://scikit-learn.org/stable/modules/preprocessing.html Please also refer to the documentation for alternative solver options: https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression n_iter_i = _check_optimize_result( 성능 리포트 : precision recall f1-score support 0 1.00 0.98 0.99 131 1 0.97 0.96 0.96 137 2 1.00 1.00 1.00 131 3 0.98 0.92 0.95 136 4 0.99 0.97 0.98 139 5 0.96 0.99 0.98 136 6 0.99 0.99 0.99 138 7 0.97 0.99 0.98 134 8 0.95 0.97 0.96 130 9 0.94 0.98 0.96 136 accuracy 0.97 1348 macro avg 0.98 0.97 0.97 1348 weighted avg 0.98 0.97 0.97 1348 """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
cycler==0.11.0 fonttools==4.34.4 joblib==1.1.0 kiwisolver==1.4.4 matplotlib==3.5.3 numpy==1.23.1 packaging==21.3 Pillow==9.2.0 pip==22.0.4 pyparsing==3.0.9 python-dateutil==2.8.2 scikit-learn==1.1.2 scipy==1.9.0 setuptools==58.1.0 six==1.16.0 sklearn==0.0 threadpoolctl==3.1.0 |