generated from lasseufpa/python_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exhaustive.py
52 lines (40 loc) · 1.6 KB
/
exhaustive.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
from imblearn.pipeline import Pipeline
from imblearn.over_sampling import SMOTE
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from mlxtend.feature_selection import ExhaustiveFeatureSelector as EFS
import pandas as pd
def exhaustive(X, Y):
model = LogisticRegression(max_iter=1000,random_state=42)
smote = SMOTE(random_state=42)
pipeline = Pipeline([('SMOTE', smote), ('Logistic Regression', model)])
efs = EFS(pipeline, min_features=1,
max_features=12,
scoring='roc_auc',
cv=5,
n_jobs=1)
efs = efs.fit(X, Y)
return efs
def main():
data = pd.read_csv('src/features.csv')
X = data.drop(columns=['label','commit'])
Y = data['label']
# X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=42)
# Defina o modelo
model = LogisticRegression(max_iter=1000,random_state=42)
# Defina o método de oversampling
smote = SMOTE(random_state=42)
# Crie uma pipeline com o método de oversampling e o modelo
pipeline = Pipeline([('SMOTE', smote), ('Logistic Regression', model)])
# Defina o seletor de recursos
efs = EFS(pipeline, min_features=1,
max_features=12,
scoring='roc_auc',
cv=5,
n_jobs=-1)
efs = efs.fit(X, Y)
efs_df = pd.DataFrame.from_dict(efs.get_metric_dict()).T
efs_df = efs_df.sort_values('avg_score', ascending=False,ignore_index=True)
efs_df.to_csv('src/Results/LogisticRegression/efs_roc_auc.csv')
if __name__ == '__main__':
main()