import pandas as pd
filename = 'C:/Users/ecaoyng/Desktop/work space/DataMining/shizhan_source/chapter5/chapter5/chapter5/demo/data/bankloan.xls'
data = pd.read_excel(filename)
x = data.iloc[:,:8].as_matrix()
y = data.iloc[:,8].as_matrix()
from sklearn.linear_model import LogisticRegression as LR
from sklearn.linear_model import RandomizedLogisticRegression as RLR
rlr = RLR()
rlr.fit(x, y)
rlr.get_support()
print(u'通过随机逻辑回归模型筛选特征结束。')
print(u'有效特征为:%s' % ','.join(data.columns[rlr.get_support()]))
x = data[data.columns[rlr.get_support()]].as_matrix()
lr = LR()
lr.fit(x, y)
print(u'逻辑回归模型训练结束。')
print(u'模型的平均正确率为:%s' % lr.score(x, y))
通过随机逻辑回归模型筛选特征结束。
有效特征为:工龄,地址,负债率,信用卡负债
逻辑回归模型训练结束。
模型的平均正确率为:0.814285714286