Skip to content

Instantly share code, notes, and snippets.

View maria-aguilera's full-sized avatar

Maria Aguilera García maria-aguilera

View GitHub Profile
@maria-aguilera
maria-aguilera / helpers.py
Created November 16, 2022 16:01 — forked from Tobias-K93/helpers.py
APA interactive plots
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):
@maria-aguilera
maria-aguilera / automobile.py
Created November 16, 2022 15:59 — forked from ethen8181/automobile.py
What appears to be the three or four most important car attributes for predicting a car’s price? (http://archive.ics.uci.edu/ml/datasets/Automobile)
"""
python3
numpy>=1.12.0
pandas>=0.19.2
matplotlib>=2.0.0
sklearn>=0.18
xgboost>=0.6
sortedcontainers>=1.5.7
"""
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)
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
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
@maria-aguilera
maria-aguilera / kaggle.py
Created November 16, 2022 15:14 — forked from AdityaSoni19031997/kaggle.py
Kaggle Helper Scripts
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
@maria-aguilera
maria-aguilera / plot_categorical.py
Created November 16, 2022 15:12 — forked from netsatsawat/plot_categorical.py
Function to plot categorical data
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
"""
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(
# 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":