-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHF_models.py
41 lines (31 loc) · 1.15 KB
/
HF_models.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
from sklearn.linear_model import LogisticRegression
import numpy as np
import pandas as pd
from sklearn.svm import SVC
import xgboost as xgb
from xgboost import XGBClassifier
from sklearn.preprocessing import StandardScaler
import pickle
import time
# Training three models to predict heart failure
df = pd.read_csv('heart_failure_clinical_records_dataset.csv')
df.drop(['time'], axis=1, inplace=True)
df.drop(df[df['ejection_fraction']==80].index, axis=0, inplace=True)
y = df['DEATH_EVENT']
X = df.drop('DEATH_EVENT', axis=1)
scale_list = ['age','creatinine_phosphokinase','ejection_fraction','platelets','serum_creatinine','serum_sodium']
scaler = StandardScaler()
X[scale_list] = scaler.fit_transform(X[scale_list])
# Logistic Regresion algorithm
Logi = LogisticRegression(C=0.46415, penalty='l2')
Logi.fit(X,y)
pickle.dump(Logi,open('Logistic_HF.pkl', 'wb'))
# SVC algorithm
SVM = SVC(kernel='linear', probability=True)
SVM.fit(X,y)
pickle.dump(SVM, open('SVC_HF.pkl', 'wb'))
#XGBoost algorithm
xgb_params = {'max_depth': 3, 'min_child_weight': 1, 'n_estimators': 300}
XGB = XGBClassifier(**xgb_params)
XGB.fit(X,y)
pickle.dump(XGB,open('XGB_HF.pkl', 'wb'))