Skip to content

Instantly share code, notes, and snippets.

s1 = data['score']
s_s1 = sum(s1.tolist())
s_s1
plt.style.use('fivethirtyeight')
ax=data.head(20).plot(kind = 'barh' , color = 'red')
for p in ax.patches:
percentage = '{:.1f}%'.format(100 * p.get_width()/s_s1)
x = p.get_x() + p.get_width() - 0.5
y = p.get_y() + p.get_height()
+---------+-----------------+----------------+----------------+---------------+
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score |
+---------+-----------------+----------------+----------------+---------------+
| XgBoost | 0.99938 | 0.99855 | 0.9998 | 0.990791 |
+---------+-----------------+----------------+----------------+---------------+
x_cfl=XGBClassifier(n_estimators=1000,nthread=-1)
x_1=XGBClassifier(n_estimators=500,nthread=-1)
x_2=XGBClassifier(n_estimators=500,nthread=-1)
x_3 = DecisionTreeClassifier(max_depth=best_depth,min_samples_split=best_samples,class_weight='balanced')
x_4 = LogisticRegression(class_weight='balanced')
s_clf = StackingClassifier(classifiers=[x_1,x_2,x_3,x_4],meta_classifier=x_cfl)
s_clf.fit(X_train,y_train)
#sig_clf = CalibratedClassifierCV(x_cfl, method="sigmoid")
#sig_clf.fit(X_train_f, y_train_f)
+---------------------+-----------------+----------------+----------------+---------------+
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score |
+---------------------+-----------------+----------------+----------------+---------------+
| Stacking_Classifier | 0.99537 | 0.9902 | 0.99429 | 0.98759 |
+---------------------+-----------------+----------------+----------------+---------------+
#In the 80% train set, split the train set into d1 and d2.(50-50).
d1,d2,y1,y2 = train_test_split(X_train,y_train,stratify=y_train,test_size=0.5,random_state=15)
d1 = d1.reset_index(drop=True)
d2 = d2.reset_index(drop=True)
y1 = y1.reset_index(drop=True)
y2 = y2.reset_index(drop=True)
def generating_samples(d1, y1):
"""From this d1,sampling with replacement is done
"""
+--------------------------------+-------------+---------------+
| Custom_Stacking_Implementation | Base Models | Test F1 Score |
+--------------------------------+-------------+---------------+
| | 50 | 0.980001 |
| | 100 | 0.981479 |
| | 150 | 0.982725 |
+--------------------------------+-------------+---------------+
#In the 80% train set, split the train set into d1 and d2.(50-50).
d1,d2,y1,y2 = train_test_split(X_train,y_train,stratify=y_train,test_size=0.5,random_state=15)
d1 = d1.reset_index(drop=True)
d2 = d2.reset_index(drop=True)
y1 = y1.reset_index(drop=True)
y2 = y2.reset_index(drop=True)
def generating_samples(d1, y1):
"""From this d1,sampling with replacement is done
"""
+---------+-----------------+----------------+----------------+---------------+
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score |
+---------+-----------------+----------------+----------------+---------------+
| XgBoost | 0.99938 | 0.99855 | 0.9998 | 0.990791 |
+---------+-----------------+----------------+----------------+---------------+ +---------------+-----------------+----------------+----------------+---------------+
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score |
+---------------+-----------------+----------------+----------------+---------------+
| Decision_Tree | 0.9967 | 0.9909 | 0.99314 | 0.9771 |
+---------------+-----------------+----------------+----------------+---------------+ +---------------------+-----------------+----------------+----------------+---------------+
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score |
def find_best_threshold(threshold, fpr, tpr):
t = threshold[np.argmax(tpr*(1-fpr))]
print("the maximum value of tpr*(1-fpr)", max(tpr*(1-fpr)), "for threshold", np.round(t,3))
return t
def predict_with_best_t(proba, threshold):
predictions = []
for i in proba:
if i>=threshold:
predictions.append(1)
def final_fun_1(X):
""" function takes raw data as input,preprocessing is done,
feature engineering is performed and predictions made on the
best model already trained"""
d_beneficiary = pd.read_csv('health_cs_data/' + X[0])
d_inpatient = pd.read_csv('health_cs_data/' + X[1])
d_outpatient = pd.read_csv('health_cs_data/' + X[2])
d_labels = pd.read_csv('health_cs_data/' + X[3])