Machine learning Path: The python support vector machine regression SVR predicts rates in Boston area

Source: Internet
Author: User

Python3 Learning using the API

Prediction of two kernel function models for support vector machines

Git:https://github.com/linyi0604/machinelearning

 fromSklearn.datasetsImportLoad_boston fromSklearn.cross_validationImportTrain_test_split fromSklearn.preprocessingImportStandardscaler fromSklearn.svmImportSVR fromSklearn.metricsImportR2_score, Mean_squared_error, Mean_absolute_errorImportNumPy as NP#1 Preparing Data#Read the Boston area rate informationBoston =Load_boston ()#View Data Description#Print (Boston. DESCR) # A total of 506 Boston area rate information, each 13 numerical description and target rate#view differences in Data#print ("max rate:", Np.max (Boston.target)) ##print ("Minimum rate:", Np.min (Boston.target)) # 5#print ("Average price:", Np.mean (Boston.target)) # 22.532806324110677x=Boston.datay=Boston.target#2 split training data and test data#random sample 25% as test 75% as trainingX_train, X_test, y_train, y_test = Train_test_split (x, Y, test_size=0.25, random_state=33)#3 Standardized processing of training data and test dataSs_x =Standardscaler () X_train=ss_x.fit_transform (x_train) x_test=ss_x.transform (x_test) ss_y=Standardscaler () Y_train= Ss_y.fit_transform (Y_train.reshape (-1, 1)) Y_test= Ss_y.transform (Y_test.reshape (-1, 1))#4.1 Support vector machine model for learning and prediction#linear kernel function configuration support vector machineLinear_svr = SVR (kernel="Linear")#TrainingLinear_svr.fit (X_train, Y_train)#forecast Save Forecast resultsLinear_svr_y_predict =linear_svr.predict (x_test)#polynomial kernel function configuration support vector machinePoly_svr = SVR (kernel="Poly")#TrainingPoly_svr.fit (X_train, Y_train)#forecast Save Forecast resultsPoly_svr_y_predict =linear_svr.predict (x_test)#5 Model Evaluation#Evaluation of linear kernel function modelPrint("The default evaluation values for linear kernel function support vector machines are:", Linear_svr.score (X_test, y_test))Print("the r_squared value of the linear kernel function support vector machine is:", R2_score (Y_test, linear_svr_y_predict))Print("the mean square error of the linear kernel function support vector machine is:", Mean_squared_error (Ss_y.inverse_transform (y_test), SS_Y.INVERSE_TRANSFO RM (Linear_svr_y_predict )))Print("the mean absolute error of the linear kernel function support vector machine is:", Mean_absolute_error (Ss_y.inverse_transform (y_test), Ss_y.inverse_tra Nsform (linear_svr_y_predict)))#evaluation of a polynomial kernel function modelPrint("The default evaluation value for a polynomial kernel function is:", Poly_svr.score (X_test, y_test))Print("The r_squared value for the polynomial kernel function is:", R2_score (Y_test, poly_svr_y_predict))Print("The mean square error of the polynomial kernel function is:", Mean_squared_error (Ss_y.inverse_transform (y_test), Ss_y.inverse_transform (poly_svr_y_predict)))Print("The average absolute error for a polynomial kernel function is:", Mean_absolute_error (Ss_y.inverse_transform (y_test), ss_y.inverse_transf ORM (Poly_svr_y_predict )))" "the default evaluation value for the linear kernel function support vector machine is: 0.651717097429608 the r_squared value of the linear kernel function support vector machine is: 0.651717097429608 the mean square error of the linear kernel function support vector machine is: 27.0063071393243 the mean absolute error of the linear kernel function support vector machine is: 3.426672916872753 The default evaluation value for the polynomial kernel function is: 0.40445405800289286 The r_squared value of the polynomial kernel function is: 0.651717097429608 the mean square error of the polynomial kernel function is: 27.0063071393243 the mean absolute error of the polynomial kernel function is: 3.426672916872753" "

Machine learning Path: The python support vector machine regression SVR predicts rates in Boston area

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.