<jupyter_start><jupyter_text>Gráficos Estatísticos com Seabornhttps://seaborn.pydata.org/<jupyter_code>import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
import numpy as np
import warnings
warnings.filterwarnings('ignore')
%matplotlib inline
sns.__version__
# Datasets importados junto com o Seaborn
sns.get_dataset_names()
# Carregando um dataset
iris = sns.load_dataset("iris")
type(iris)
iris.head()
iris.describe()
iris.columns<jupyter_output><empty_output><jupyter_text>Construindo Gráficos Estatísticos<jupyter_code># Histograma com estimativa de densidade de kernel - Distribuição univariada
sns.distplot(iris.sepal_length, rug = True, fit = stats.gausshyper);
# Scatterplot - Distribuição bivariada
sns.jointplot(x = "sepal_length", y = "petal_length", data = iris);
# Gráfico útil quando estiver trabalhando com grandes conjuntos de dados - Distribuição bivariada
with sns.axes_style("white"):
    sns.jointplot(x = "sepal_length", y = "petal_length", data = iris, kind = "hex", color  ="k");
# Distribuição bivariada
sns.jointplot(x = "sepal_length", y = "petal_length", data = iris, kind = "kde");
# Distribuição bivariada
g = sns.jointplot(x = "sepal_length", y = "petal_length", data = iris, kind = "kde", color = "m")
g.plot_joint(plt.scatter, c = "w", s = 30, linewidth = 1, marker = "+")
g.ax_joint.collections[0].set_alpha(0);
# Plot para distirbuições bi-variadas
sns.pairplot(iris);<jupyter_output><empty_output><jupyter_text>Visualização de Relacionamento Linear<jupyter_code># Carregando o dataset tips
tips = sns.load_dataset("tips")
type(tips)
tips.head()
tips.describe()
# Scatterplot com linha de regressão - Distribuição bivariada 
sns.jointplot(x = "total_bill", y = "tip", data = tips, kind = "reg");
# Regressão Linear (utiliza 95% de intervalo de confiança por padrão)
# tip - variável dependente
# total_bill - variável independente
sns.lmplot(x = "total_bill", y = "tip", data = tips);
# Alterando a variável independente
sns.lmplot(x = "size", y = "tip", data = tips, x_jitter = .05);
# Visualizando o efeito de diferentes tamanho de tips
sns.lmplot(x = "size", y = "tip", data = tips, x_estimator = np.mean);
# Carregando o dataset anscombe
anscombe = sns.load_dataset("anscombe")
# Relacionamento não-linear
sns.lmplot(x = "x", y = "y", data = anscombe.query("dataset == 'II'"), ci = None, scatter_kws = {"s": 80});
# Podemos ajustar os parâmetros para se adequarem a curva
sns.lmplot(x = "x", y = "y", data = anscombe.query("dataset == 'II'"), order = 2, ci = None, scatter_kws = {"s": 80});
## Visualizando outliers
sns.lmplot(x = "x", y = "y", data = anscombe.query("dataset == 'III'"), ci = None, scatter_kws = {"s": 80});
## Usando o lowess smoother para variáveis com relacionamento não linear.
sns.lmplot(x = "total_bill", y = "tip", data = tips, lowess = True);
# Usando mais de 2 variáveis
sns.lmplot(x = "total_bill", y = "tip", hue = "smoker", data = tips);
# Alterando a configuração do gráfico
sns.lmplot(x = "total_bill", y = "tip", hue = "smoker", data = tips, markers = ["o", "x"], palette = "Set1");
# Dividindo a área de desenho
sns.lmplot(x = "total_bill", y = "tip", hue = "smoker", col = "time", data = tips);
# Dividindo a área de desenho
sns.lmplot(x = "total_bill", y = "tip", hue = "smoker", col = "time", row = "sex", data = tips);
# Dividindo a área de desenho
sns.lmplot(x = "total_bill", y = "tip", col = "day", data = tips, col_wrap = 2, size = 3);
# Dividindo a área de desenho
sns.lmplot(x = "total_bill", y = "tip", col = "day", data = tips, aspect = .5);<jupyter_output><empty_output><jupyter_text>Gráficos para Variáveis Categóricas<jupyter_code># stripplot
sns.stripplot(x = "day", y = "total_bill", data = tips);
# stripplot
sns.stripplot(x = "day", y = "total_bill", data = tips, jitter = True);
# swarmplot - Evitando overlap dos pontos
sns.swarmplot(x = "day", y = "total_bill", data = tips);
# boxplot
sns.boxplot(x = "day", y = "total_bill", hue = "time", data = tips);
# boxplot
sns.boxplot(data = iris, orient = "h");
# violinplot
sns.violinplot(x = "total_bill", y = "day", hue = "time", data = tips);
# violinplot
sns.violinplot(x = "total_bill", y = "day", hue = "time", data = tips, bw = .1, scale = "count", scale_hue = False);
 # violinplot
sns.violinplot(x = "day", y = "total_bill", hue = "sex", data = tips, split = True);
# barplot
sns.barplot(x = "day", y = "total_bill", hue = "sex", data = tips);
# countplot
sns.countplot(x = "day", data = tips, palette = "Greens_d");
# countplot
sns.countplot(y = "day", hue = "sex", data = tips, palette = "Greens_d");
# countplot
f, ax = plt.subplots(figsize=(7, 3))
sns.countplot(y = "day", data = tips, color = "c");
# pointplot
sns.pointplot(x = "sex", y = "total_bill", hue = "smoker", data = tips);
# factorplot
sns.factorplot(x = "day", y = "total_bill", hue = "smoker", data = tips);<jupyter_output><empty_output><jupyter_text>Visualizando DataFrames Pandas com Seaborn<jupyter_code>import random
import pandas as pd
df = pd.DataFrame()
df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
df.head()
# Scatterplot
sns.lmplot('x', 'y', data = df, fit_reg = False)
# Density Plot
sns.kdeplot(df.y)
# Distplot
sns.distplot(df.x)
# Histograma
plt.hist(df.x, alpha = .3)
sns.rugplot(df.x);
# Boxplot
sns.boxplot([df.y, df.x])
# Heatmap
sns.heatmap([df.y, df.x], annot = True, fmt = "d")
# Clustermap
sns.clustermap(df)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16525735294117647, 'fraction_numerical': 0.006801470588235294, 'mean_word_length': 5.239678899082569, 'pattern_counts': {'":': 3, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '121179', 'license': 'MIT', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2125, 'n_words': 556, 'path': 'Cap03/14-Cap03-Graficos-Estatisticos-Seaborn.ipynb', 'repo_name': 'silvioedu/DSA-BigDataAnalytics-Python-Spark2', 'size': '5440'}