Skip to content

Instantly share code, notes, and snippets.

View bbennett36's full-sized avatar

Brennan Bennett bbennett36

View GitHub Profile
@bbennett36
bbennett36 / gist:131c2d7e5193073344d48ae3ed45978d
Last active August 1, 2019 00:23
widen jupyter notebook cells
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
@bbennett36
bbennett36 / model_v1
Last active February 17, 2021 17:28
lgb model quickstart
%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()
new_data['date'] = new_data['date'].apply(lambda x: str(x).replace('-', '')).astype(np.float)
## 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])
@bbennett36
bbennett36 / slice_list
Created August 19, 2018 18:21
iterate through slive of list
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)
@bbennett36
bbennett36 / crpto_profit_calc.py
Last active July 29, 2019 16:29
Take Profit/Stop Loss Profitability Calculator for Trading Crypto
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
@bbennett36
bbennett36 / pred_density.py
Last active May 11, 2020 14:40
pred density
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)
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
@bbennett36
bbennett36 / conf_matrix.py
Created May 11, 2020 15:01
confusion matrix
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,