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 numpy as np | |
def standardize(gamma, upper_val = 0.3, lower_val = 0.1): | |
s = (gamma-np.min(gamma))/(np.max(gamma)-np.min(gamma)) | |
out = s * (upper_val - lower_val) + lower_val | |
return out | |
def is_pos_def(x): |
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
""" | |
python3 | |
numpy>=1.12.0 | |
pandas>=0.19.2 | |
matplotlib>=2.0.0 | |
sklearn>=0.18 | |
xgboost>=0.6 | |
sortedcontainers>=1.5.7 | |
""" |
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
def categorical_summarized(dataframe, x=None, y=None, hue=None, palette='Set1', verbose=True): | |
''' | |
Helper function that gives a quick summary of a given column of categorical data | |
Arguments | |
========= | |
dataframe: pandas dataframe | |
x: str. horizontal axis to plot the labels of categorical data, y would be the count | |
y: str. vertical axis to plot the labels of categorical data, x would be the count | |
hue: str. if you want to compare it another variable (usually the target variable) |
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 seaborn as sns | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#adjust seaborn plot size | |
plt.figure(figsize=(20,12)) | |
#pairplot (my favorite) - Draw scatterplots for joint relationships and histograms for univariate distributions | |
#hue optional like on all other seaborn plots |
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
def plot_categorical_variables_pie(data, column_name, plot_defaulter = True, hole = 0): | |
''' | |
Function to plot categorical variables Pie Plots | |
Inputs: | |
data: DataFrame | |
The DataFrame from which to plot | |
column_name: str | |
Column's name whose distribution is to be plotted | |
plot_defaulter: bool |
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 seaborn as sns | |
from sklearn import preprocessing, ensemble | |
from scipy.stats import kendalltau | |
import pandas as pd | |
import random | |
#todo change module name | |
from tqdm import tqdm | |
import numpy as np | |
import pandas as pd |
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
def plot_categorical(df: pd.DataFrame , col:str): | |
""" | |
Function to plot the categorical data on piechart using Plotly | |
@Args: | |
df: pandas data frame | |
col: A string column name within pandas data frame to plot | |
Return: | |
No object return, only visualization | |
""" |
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 altair as alt | |
#Simple Altait plot | |
import altair as alt | |
def plotGenericLineChart(x_values, x_type , y_values, y_type, chart_title, x_axis_title, y_axis_title): | |
""" | |
This function creates a line chart for two values X and Y passed in along with thier types and titles | |
""" | |
df = pd.DataFrame({"x_values" : x_values, 'y_values': y_values}) | |
chart = alt.Chart(df).mark_line( |
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
# Function to print digits on top of Barplot | |
def show_values(axs, orient="v", space=.01): | |
def _single(ax): | |
if orient == "v": | |
for p in ax.patches: | |
_x = p.get_x() + p.get_width() / 2 | |
_y = p.get_y() + p.get_height() + (p.get_height()*0.01) | |
value = '{:.2f}'.format(p.get_height()) | |
ax.text(_x, _y, value, ha="center") | |
elif orient == "h": |
NewerOlder