1 import pandas as pd 2 from sklearn.model_selection import train_test_split 3 from sklearn.linear_model import LogisticRegression 4 from sklearn.metrics import accuracy_score 5 df = pd.read_csv("./LogisticRegression.csv") 6 df.head() 7 df_x = df.iloc[:,1:] 8 df_y = df.iloc[:,0] 9 df_x_train,df_x_test,df_y_train,df_y_test = train_test_split(df_x,df_y,train_size = 0.8 ,random_state = 2) 10 logistic = LogisticRegression(max_iter = 1000,solver = "newton-cg" ).fit(df_x_train,df_y_train) 11 df_y_predict = logistic.predict(df_x_test) 12 accuracy_score(df_y_test,df_y_predict)
准确率为:0.7125 |
Logistic回归实现分析不同的因素对研究生录取的影响来预测一个人是否会被录取(Python实现)
原文:https://www.cnblogs.com/jory-boke/p/13740278.html