This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+---------+-----------------+----------------+----------------+---------------+ | |
| 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+--------------------------------+-------------+---------------+ | |
| Custom_Stacking_Implementation | Base Models | Test F1 Score | | |
+--------------------------------+-------------+---------------+ | |
| | 50 | 0.980001 | | |
| | 100 | 0.981479 | | |
| | 150 | 0.982725 | | |
+--------------------------------+-------------+---------------+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ar win = Ti.UI.createWindow({ backgroundColor: '#fff' }); | |
var scrollView = Titanium.UI.createScrollableView({ | |
views:[ | |
Titanium.UI.createView({backgroundColor:'#f00'}), | |
Titanium.UI.createView({backgroundColor:'#0f0'}), | |
Titanium.UI.createView({backgroundColor:'#00f'})], | |
showPagingControl:true, | |
width: 480, | |
height: 320, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+---------------------+-----------------+----------------+----------------+---------------+ | |
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score | | |
+---------------------+-----------------+----------------+----------------+---------------+ | |
| Stacking_Classifier | 0.99537 | 0.9902 | 0.99429 | 0.98759 | | |
+---------------------+-----------------+----------------+----------------+---------------+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.linear_model import LogisticRegression | |
from sklearn.metrics import roc_auc_score | |
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+---------+-----------------+----------------+----------------+---------------+ | |
| Model | Train AUC Score | Test AUC Score | Train F1 Score | Test F1 Score | | |
+---------+-----------------+----------------+----------------+---------------+ | |
| XgBoost | 0.99938 | 0.99855 | 0.9998 | 0.990791 | | |
+---------+-----------------+----------------+----------------+---------------+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider_count 14960 | |
State 5550 | |
attend_physician_count 4258 | |
County 3218 | |
OPAnnualReimbursementAmt 816 | |
total_diff_amount 800 | |
ClmDiagnosisCode_1_count 713 | |
OPAnnualDeductibleAmt 668 | |
InscClaimAmtReimbursed 634 |