<jupyter_start><jupyter_text>Seaborn - Distribution Plots* Tópicos:    * distplot  (pdf of a variable)    * jointplot (combines two displots, and a graph in the middle)    * pairplot  (pair pdfs, combining each variable)    * rugplot   (dash mark for each point in a univariate distribution)    * kdeplot   (Kernel Density Estimator)<jupyter_code># Import Libraries

import numpy as np
from numpy.random import randn
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
from scipy import stats

# Import Data

tips = sns.load_dataset('tips')
tips.head()
# Distplot

# kde = shows density estimation of data (True or False)
# bins = number of 'spaces' for data division

sns.distplot(tips['total_bill'], bins=20, kde=True)
# Joint Plot

# data = which dataframe / x,y = which collumn will be plot
# kind = type of plot (“scatter”  / “reg” / “resid” / “kde” / “hex”)

sns.jointplot(data = tips, x = 'total_bill', y = 'tip', kind = 'reg')
# Pair plot

# data = which dataframe
# hue = for each value of this variable, a different color 
# (good for classification datasets)
# pallete = color pallete

sns.pairplot(data=tips,hue='sex',palette='coolwarm')
# Rug Plot

sns.rugplot(tips['total_bill'])
# Kernel Density Estimation 1: Basis Functions

# https://en.wikipedia.org/wiki/Kernel_density_estimation#Pratical_estimation_of_the_bandwidth

# Create normal random dataset
dataset = np.random.randn(25)

# Create rugplot
sns.rugplot(dataset);

# Config Axis
x_min = dataset.min() - 2
x_max = dataset.max() + 2

# 100 equally spaced points between x_min and x_max
x_axis = np.linspace(x_min,x_max,100)

# Config bandwidth
bandwidth = ((4*dataset.std()**5)/(3*len(dataset)))**.2

# Create a kernel list
kernel_list = []

# Basis functions
for data_point in dataset:
    
    # Create kernel for each point
    kernel = stats.norm(data_point,bandwidth).pdf(x_axis)
    kernel_list.append(kernel)
    
    # Adjust scale
    kernel = kernel / kernel.max()
    kernel = kernel * .4
    plt.plot(x_axis,kernel,color='grey',alpha=0.5)

# Plot graphic
plt.ylim(0,1)
# Kernel Density Estimation 2: Obtain Distribution

# Sum of basis functions
sum_of_kde = np.sum(kernel_list,axis=0)

# Plot figure
fig = plt.plot(x_axis,sum_of_kde,color='indianred')

# Add the initial rugplot
sns.rugplot(dataset,c = 'indianred')

# Erase y-ticks
plt.yticks([])

# Define title
plt.suptitle("Sum of the Basis Functions")
# Kernel Density Estimation 3: from dataset

sns.kdeplot(tips['tip'])
sns.rugplot(tips['tip'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11532447224394057, 'fraction_numerical': 0.009773260359655981, 'mean_word_length': 4.550976138828633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '545498', 'license': 'MIT', 'n_tokens_mistral': 929, 'n_tokens_neox': 890, 'n_words': 255, 'path': 'scripts_matplotlib_seaborn/Seaborn_01_Distribution_Plots.ipynb', 'repo_name': 'davidcoelho89/MLTool_python', 'size': '2558'}