Sklearn Profile
Scikit-learn (sklearn) is commonly used in machine learning third party modules, machine learning methods commonly used the package, including regression (Regression), dimensionality reduction (Dimensionality Reduction), classification (Classfication), clustering (Clustering), etc. method. When we are faced with the problem of machine learning, you can select the appropriate method below.
Sklearn has the following characteristics:
- Simple and efficient data mining and data analysis tools
- So that everyone can be reused in a complex environment
- On the establishment of NumPy, Scipy, MatPlotLib
Code as follows:
import xlrd import matplotlib.pyplot as plt import numpy as np from sklearn import model_selection from sklearn.linear_model import LogisticRegression from sklearn import metrics data = xlrd.open_workbook('gua.xlsx') sheet = data.sheet_by_index(0) Density = sheet.col_values(6) Sugar = sheet.col_values(7) Res = sheet.col_values(8) # 读取原始数据 X =np.array ([Density, Sugar]) # size of Y ( . 17 ,) Y = np.array (Res) X- = X.reshape ( . 17 , 2 ) # drawing classification data F1 = plt.figure ( . 1 ) PLT .title ( ' watermelon_3a ' ) plt.xlabel ( ' density ' ) plt.ylabel ( ' ratio_sugar ' ) # plotted scattergram (x-axis is the density, y-axis is the sugar content) plt.scatter (X-[Y == 0 , 0 ], X-[Y == 0 , . 1 ], marker = ' O' , Color = ' K ' , S = 100 , label = ' Bad ' ) plt.scatter (X-[Y == . 1 , 0 ], X-[Y == . 1 , . 1 ], marker = ' O ' , Color = ' G ' , S = 100 , label = ' Good ' ) plt.legend (LOC = ' Upper right ' ) plt.show () # half data selected from the original training data, test data and the other half X_train, X_test, y_train, y_testModel_selection.train_test_split = (X-, y, test_size = 0.5 , random_state = 0 ) # logistic regression model log_model = LogisticRegression () # logistic regression model training log_model.fit (X_train, y_train) # y is the predicted value of y_pred = log_model.predict ( X_test) # View test results Print (metrics.confusion_matrix (android.permission.FACTOR., y_pred)) Print (metrics.classification_report (android.permission.FACTOR., y_pred))