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
import matplotlib.pyplot as plt | |
import itertools | |
import numpy as np | |
import sklearn.metrics as metrics | |
def get_confusion_matrix(target, preds): | |
return metrics.confusion_matrix(target, preds) | |
def plot_confusion_matrix(cm, classes, | |
normalize=True, |
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
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
def get_bins(scores, q=10, adjust_endpoints=False): | |
_, bins = pd.qcut(scores, q=q, retbins=True) | |
if adjust_endpoints: | |
bins[0] = -0.1 | |
bins[len(bins)-1] = 1.1 | |
return bins |
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
import matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.stats import gaussian_kde | |
def plot_prediction_density(target, probs, figsize=(8,5), | |
title='Prediction Density Plot'): | |
class_set = sorted(set(target)) | |
x_grid = np.linspace(0, 1, 1000) |
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
import pandas as pd | |
import numpy as np | |
def test_cutoffs(start_amount, start_price, buy_fee, sell_fee, end_price): | |
bought_fee = start_amount*buy_fee | |
bought_amt = (start_amount-bought_fee) / start_price | |
sold = bought_amt*end_price | |
sold_fee = sold*sell_fee | |
sold = sold-sold_fee |
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
feats = ['post', 'odds'] | |
i_start = 0 | |
i_end = 4 | |
total_size = len(classes) | |
print(classes[i_start:i_end]) | |
while i_start < total_size: | |
print(pclass) |
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
## Multiple plots in one line | |
fig, (ax1, ax2, ax3, ax4) = plt.subplots(ncols=4, sharey=False, figsize=(20,5)) | |
ax1.set_ylim([60,90]) | |
sns.barplot(x="pp", y='sc_avgcr', data=high_five, ax=ax1) | |
ax2.set_ylim([60,90]) | |
sns.barplot(x="pp", y='sc_avgsr', data=high_five, ax=ax2) | |
ax3.set_ylim([60,90]) | |
sns.barplot(x="pp", y='sc_hisr', data=high_five, ax=ax3) | |
ax4.set_ylim([60,90]) |
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
new_data['date'] = new_data['date'].apply(lambda x: str(x).replace('-', '')).astype(np.float) |
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
%matplotlib inline | |
from matplotlib import pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import seaborn as sns | |
import lightgbm as lgb | |
import shap | |
from sklearn.model_selection import train_test_split | |
shap.initjs() |
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 IPython.core.display import display, HTML | |
display(HTML("<style>.container { width:80% !important; }</style>")) | |
pd.set_option('display.max_columns', None) | |
pd.set_option('display.max_rows', None) | |
from IPython.display import display, clear_output | |