Skip to content

Instantly share code, notes, and snippets.

View dfuller22's full-sized avatar

Darius Fuller dfuller22

View GitHub Profile
def plot_importance(tree, X_train, top_n=10, figsize=(10,10), ax=None):
"""Takes in pre-fit descision tree and the training X data used. Will output
a horizontal bar plot (.plt) of the top 10 (default) features used in said tree."""
## Imports
import pandas as pd
import matplotlib as plt
## Generate feature importances + store into series with correct column names
def regressor_tester(reg_, X_tr, X_te, y_tr, y_te, verbose=False, display_res=False, keep_preds=False):
import pandas as pd
import numpy as np
from sklearn import metrics
## Check if multiple regressors to check
if isinstance(reg_, list):
## Container for multiple regressor results + counter
count = 0
holder = []
def cand_per_yr_viewer(party_dict, yr_start='1920', yr_end=None, bar_width=0.15, figsize_=(10,7), keep=False):
import matplotlib.pyplot as plt
import numpy as np
## This code was heavily influenced by that found at:
# https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/barchart.html
## Setting dictionaries for label positioning
ha = {'center': 'center', 'right': 'left', 'left': 'right'}
offset = {'center': 0, 'right': 1, 'left': -1}
xpos = 'center'