Skip to content

Instantly share code, notes, and snippets.

@AvielMak
AvielMak / Plot_clf_calibration.py
Created September 17, 2020 10:07
Plot Classifier Calibration
def plot_calibration(y_true, y_probability,model_name='LGBM'):
# compute calibration
prob_df_clf = pd.DataFrame({'y': y_true, 'y_hat': y_probability})
# binning the dataframe, so we can see success rates for bins of probability
bins = np.arange(0.05, 1.00, 0.05)
prob_df_clf.loc[:,'prob_bin'] = np.digitize(prob_df_clf['y_hat'], bins)
prob_df_clf.loc[:,'prob_bin_val'] = prob_df_clf['prob_bin'].replace(dict(zip(range(len(bins)), bins)))
# opening figure
plt.figure(figsize=(12,7), dpi=150)
@AvielMak
AvielMak / Plot_Distribution.py
Created September 17, 2020 10:05
Plot Distribution of two classes given feature
# Def plot distribution
def plot_distribution(data_select,data,h,limit=()):
"""
Plot_Distribution to see how 2 classes are seperated on different features
data_select = which feature we want to see
data = the DataFrame
h = column of the two classes
limit = non mendatory, tuple to limit the x_axis
"""
figsize =( 15, 8)