-
Notifications
You must be signed in to change notification settings - Fork 0
/
Classification_RFE.py
53 lines (41 loc) · 1.25 KB
/
Classification_RFE.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import os
import pandas as pd
os.chdir("//ahmct-065/teams/PMRF/Amir/bin")
df=pd.read_csv("training1.csv")
test=pd.read_csv("testing1.csv")
x=pd.DataFrame(data=df)
x=x.drop(columns=['CASE_ID'])
y=pd.DataFrame(data=df, columns=['CASE_ID'])
test_col=[col for col in test.columns if col in df.columns]
x_test=pd.DataFrame(data=test, columns=test_col)
x_test=x_test.drop(columns=['CASE_ID'])
y_test=pd.DataFrame(data=test, columns=['CASE_ID'])
from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
logreg = LogisticRegression(solver='lbfgs', max_iter=1000, n_jobs=7)
rfe = RFE(logreg, 10)
rfe = rfe.fit(x, y.values.ravel())
print(rfe.support_)
print(rfe.ranking_)
rfe.get_support(indices=True)
high_score=0
score_list =[]
nof=0
for n in range(2, 38):
model = LogisticRegression(solver='lbfgs', max_iter=1000, n_jobs=7)
rfe = RFE(model, n)
train = rfe.fit_transform(x, y.values.ravel())
x_test_rfe = rfe.transform(x_test)
model.fit(train,y)
score = model.score(x_test_rfe,y_test)
score_list.append(score)
if(score>high_score):
high_score = score
nof = n
import matplotlib.pyplot as plt
plt.plot(score_list)