# -*- coding: utf-8 -*-
"""
Created on Tue Feb 6 09:00:31 2018
@author: wangqingxin
"""
import pandas as pd
from pandas.core import datetools
import statsmodels.api as sm
import pylab as pl
import numpy as np
data=pd.read_csv('d:/wqx_logit.csv')
print(data.describe())
print(data.std())
data.hist()
pl.show()
train_cols=data.columns[2:]
data['intercept']=1.0
logit=sm.Logit(data["lius"],data[train_cols])
result=logit.fit()
combos = pd.read_csv('d:/wqx_logit.csv')
predict_cols = combos.columns[2:]
combos['intercept']=1.0
combos['predict']=result.predict(combos[predict_cols])
tot = 0
hit = 0
tot1 = 0
hit1 = 0
for value in combos.values:
predict = value[-1]
admit = int(value[1])
if predict >=0.5:
tot+=1
if admit == 1:
hit+=1
if predict <0.5:
tot1+=1
if admit == 0:
hit1+=1
print(tot,hit,hit/tot)
print(tot1,hit1,hit1/tot1)
print((hit+hit1)/(tot+tot1))
print(result.summary())
python逻辑回归代码实例
最新推荐文章于 2024-05-16 05:30:00 发布