【邏輯回歸的特征篩選方法】


 

數據特征如下

使用邏輯回歸的穩定性選擇

import pandas as pd
import numpy as np
import pyecharts
import xlrd

# with open(r'F:\數據分析專用\數據分析與機器學習\bankloan.xls', 'rb') as f:
file = r'F:\數據分析專用\數據分析與機器學習\bankloan.xls'
data = pd.read_excel(file)
    # print(data.head())
x = data.iloc[:, :8].values
# print(x)
y = data.iloc[:, 8].values
# print(y)


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()
validate_feature = data.iloc[:, :8]
print(u'有效特征為:%s' % ','.join(validate_feature.columns[rlr.get_support()]))
x = data[validate_feature.columns[rlr.get_support()]].values

lr = LR()
lr.fit(x, y)
print(u'模型的平均正確率:%s' % lr.score(x, y))
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM