机器学习之LinearRegression与Logistic Regression逻辑斯蒂回归(三) (2)
# 对数据集进行拆分,得到训练集和测试集
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(data,target,test_size=0.2,random_state=1)
#采用逻辑斯蒂回归模型与KNN
logistic = LogisticRegression()
knn = KNeighborsClassifier(n_neighbors=5)
#对knn与逻辑斯蒂进行训练
logistic.fit(X_train,y_train)
y1_ = logistic.predict(X_test)
knn.fit(X_train,y_train)
y2_ = knn.predict(X_test)
内容版权声明:除非注明,否则皆为本站原创文章。