# -*- coding: utf-8 -*-
"""
Created on Mon Oct 8 15:47:18 2018
@author: Administrator
"""
import os
dir(os)
os.chdir(r'C:\Users\Administrator\Desktop\10-8\04-回归分析\data')
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
data=pd.read_csv('LogisticRegression.csv',sep=',',encoding='utf-8')
print(data)
from sklearn.model_selection import train_test_split
data_tr,data_te,class_tr,class_te = train_test_split(data.iloc[:,1:],data['admit'],test_size=0.2,random_state=1234)
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(max_iter=500,solver='newton-cg').fit(data_tr,class_tr)
pre =lr.predict(data_te)
lr.score(data_te,class_te)
p=sum(class_te == pre)/len(class_te)
print(p)
print('准确率为%.2f'%(lr.score(data_te,class_te)))
print('准确率为{0:.2f}%'.format(lr.score(data_te,class_te)))
data.admit
数据集划分
最新推荐文章于 2024-02-22 12:25:21 发布