Using Python3 to learn the use of the support vector machine API in Sklearn
can come to my git download source code:https://github.com/linyi0604/kaggle
1 #Import the Handwriting font loader2 fromSklearn.datasetsImportload_digits3 fromSklearn.cross_validationImportTrain_test_split4 fromSklearn.preprocessingImportStandardscaler5 fromSklearn.svmImportlinearsvc6 fromSklearn.metricsImportClassification_report7 8 " "9 Support Vector MachineTen based on the distribution of the training samples, the best one for all possible linear classifiers is searched. One Select the most effective number of training samples from high latitude data. A save data memory and improve predictive performance - but paying more CPU and computing time - " " the - " " - 1 Getting Data - " " + #Digital image data of handwritten font numbers and stored in digits variable via data Loader -digits =load_digits () + #View the feature dimensions and scale of the data A #print (Digits.data.shape) # (1797, +) at - " " - 2 split training sets and test sets - " " -X_train, X_test, y_train, y_test =train_test_split (Digits.data, - Digits.target, intest_size=0.25, -Random_state=33) to + " " - 3 recognition of digital images using support vector machine classification model the " " * #standardize training data and test data $SS =Standardscaler ()Panax NotoginsengX_train =ss.fit_transform (X_train) -X_test =ss.fit_transform (x_test) the + #Support Vector machine classifier for initializing linear hypothesis ALsvc =linearsvc () the #to train + Lsvc.fit (X_train, Y_train) - #Predictive test results for test sets are stored in y_predict using a well-trained model $Y_predict =lsvc.predict (x_test) $ - " " - 4 Support Vector machine classifier model capability Evaluation the " " - Print("Accuracy rate:", Lsvc.score (X_test, y_test))Wuyi Print("additional evaluation data: \ n", Classification_report (Y_test, Y_predict, target_names=digits.target_names.astype (str ))) the " " - accuracy rate: 0.9488888888888889 Wu Other evaluation data: Accuracy recall rate F1 indicator data Count - Precision recall F1-score support About $ 0 0.92 0.97 0.94 - 1 0.95 0.98 0.96 - 2 0.98 1.00 0.99 - 3 0.93 0.93 0.93 A 4 0.97 1.00 0.99 + 5 0.94 0.94 0.94 the 6 0.96 0.98 0.97 Wuyi - 7 0.90 1.00 0.95 $ 8 0.98 0.83 0.90 the 9 0.95 0.91 0.93 the the avg/total 0.95 0.95 0.95 the " "
Machine learning path: Python support vector machine handwriting font recognition