text_plain_output_1.png
from eli5.sklearn import PermutationImportance

from matplotlib import pyplot

from numpy import argmax

from numpy import sqrt

from sklearn.ensemble import RandomForestClassifier

from sklearn.ensemble import RandomForestClassifier

from sklearn.ensemble import RandomForestClassifier

from sklearn.linear_model import LogisticRegression

from sklearn.metrics import accuracy_score

from sklearn.metrics import roc_curve

import eli5

from sklearn.ensemble import RandomForestClassifier
rf_model = RandomForestClassifier()
rf_model.fit(X_train, y_train)
pred_s = rf_model.predict_proba(X_test)

y_pred = rf_model.predict(X_test)

from sklearn.ensemble import RandomForestClassifier
rf_model = RandomForestClassifier()
rf_model.fit(X_train, y_train)
pred_s = rf_model.predict_proba(X_test)

y_pred = rf_model.predict(X_test)

accuracy = accuracy_score(y_test, y_pred)
accuracy

threshold = 0.5
predicted = (pred_s[:, 1] >= threshold).astype('int')

y_predict = rf_model.predict(X_test)

threshold = 0.25
predicted = (pred_s[:, 1] >= threshold).astype('int')
accuracy = accuracy_score(y_test, predicted)
accuracy

from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train, y_train)
y_pred_lg = classifier.predict(X_test)

lr_probs = classifier.predict_proba(X_test)
lr_probs = lr_probs[:, 1]

from numpy import sqrt
from sklearn.metrics import roc_curve
from numpy import argmax
from matplotlib import pyplot
yhat_prob = classifier.predict_proba(X_test)
yhat = yhat_prob[:, 1]
fpr, tpr, thresholds = roc_curve(y_test, yhat)
gmeans = sqrt(tpr * (1 - fpr))
ix = argmax(gmeans)

threshold = 0.3
predicted = (yhat_prob[:, 1] >= threshold).astype('int')
accuracy = accuracy_score(y_test, predicted)
accuracy

from sklearn.ensemble import RandomForestClassifier
rf_model = RandomForestClassifier()
rf_model.fit(X_train, y_train)
pred_s = rf_model.predict_proba(X_test)

y_pred = rf_model.predict(X_test)

threshold = 0.25
predicted = (pred_s[:, 1] >= threshold).astype('int')
accuracy = accuracy_score(y_test, predicted)
accuracy

threshold = 0.25
pred_s = rf_model.predict_proba(X_valid)
predicted = (pred_s[:, 1] >= threshold).astype('int')
accuracy = accuracy_score(y_valid, predicted)
accuracy

import eli5
from eli5.sklearn import PermutationImportance
perm = PermutationImportance(rf_model, random_state=1).fit(X_valid, y_valid)
eli5.show_weights(perm, feature_names=X_valid.columns.tolist())