<jupyter_start><jupyter_text>Visualization. 1 Relational plotsIntroducción a la programación con Python.Autor: <NAME> (email: <EMAIL>)More Info:https://seaborn.pydata.org/api.html  The Seaborn Packagehttps://seaborn.pydata.org/index.html Statistical analysis is a process of understanding how variables in a dataset relate to each other and how those relationships depend on other variables. Visualization can be a core component of this process because, when data are visualized properly, the human visual system can see trends and patterns that indicate a relationship.We will discuss three seaborn functions in this tutorial. The one we will use most is relplot(). This is a figure-level function for visualizing statistical relationships using two common approaches: scatter plots and line plots. relplot() combines a FacetGrid with one of two axes-level functions: Visualizing statistical relationshipsStatistical analysis is a process of understanding how variables in a dataset relate to each other and how those relationships depend on other variables. Visualization can be a core component of this process because, when data are visualized properly, the human visual system can see trends and patterns that indicate a relationship.We will discuss three seaborn functions in this tutorial. The one we will use most is relplot(). This is a figure-level function for visualizing statistical relationships using two common approaches: scatter plots and line plots. relplot() combines a FacetGrid with one of two axes-level functions:- scatterplot() (with kind="scatter"; the default)- lineplot() (with kind="line")As we will see, these functions can be quite illuminating because they use simple and easily-understood representations of data that can nevertheless represent complex dataset structures. They can do so because they plot two-dimensional graphics that can be enhanced by mapping up to three additional variables using the semantics of hue, size, and style.<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
sns.set(style="darkgrid")<jupyter_output><empty_output><jupyter_text>Relating variables with scatter plotsThe scatter plot is a mainstay of statistical visualization. It depicts the joint distribution of two variables using a cloud of points, where each point represents an observation in the dataset. This depiction allows the eye to infer a substantial amount of information about whether there is any meaningful relationship between them.There are several ways to draw a scatter plot in seaborn. The most basic, which should be used when both variables are numeric, is the scatterplot() function. In the categorical visualization tutorial, we will see specialized tools for using scatterplots to visualize categorical data. The scatterplot() is the default kind in relplot() (it can also be forced by setting kind="scatter"):<jupyter_code>tips = sns.load_dataset("tips")
tips.shape
tips.head()

sns.relplot(x="total_bill", y="tip", data=tips);#  hue = "sex", hue="smoker", data=tips, s = 100 alpha = 0.3 style="time"<jupyter_output><empty_output><jupyter_text>While the points are plotted in two dimensions, another dimension can be added to the plot by coloring the points according to a third variable. In seaborn, this is referred to as using a “hue semantic”, because the color of the point gains meaning:<jupyter_code>sns.relplot(x="total_bill", y="tip", hue="smoker", data=tips) 
sns.relplot(x="total_bill", y="tip", hue="smoker", data=tips, s = 100, alpha = 0.3)<jupyter_output><empty_output><jupyter_text>To emphasize the difference between the classes, and to improve accessibility, you can use a different marker style for each class:<jupyter_code>sns.relplot(x="total_bill", y="tip", hue="smoker", style="smoker",
            data=tips);<jupyter_output><empty_output><jupyter_text>It’s also possible to represent four variables by changing the hue and style of each point independently. But this should be done carefully, because the eye is much less sensitive to shape than to color:<jupyter_code>sns.relplot(x="total_bill", y="tip", hue="smoker", style="time", data=tips);

sns.relplot(x="total_bill", y="tip", size="size", sizes=(15, 200), data=tips);
# More examples for customizing how the different semantics are used to show statistical relationships are shown in the scatterplot() API examples.<jupyter_output><empty_output><jupyter_text>Emphasizing continuity with line plotsScatter plots are highly effective, but there is no universally optimal type of visualiation. Instead, the visual representation should be adapted for the specifics of the dataset and to the question you are trying to answer with the plot.With some datasets, you may want to understand changes in one variable as a function of time, or a similarly continuous variable. In this situation, a good choice is to draw a line plot. In seaborn, this can be accomplished by the lineplot() function, either directly or with relplot() by setting kind="line":  Showing multiple relationships with facetsWe’ve emphasized in this tutorial that, while these functions can show several semantic variables at once, it’s not always effective to do so. But what about when you do want to understand how a relationship between two variables depends on more than one other variable?The best approach may be to make more than one plot. Because relplot() is based on the FacetGrid, this is easy to do. To show the influence of an additional variable, instead of assigning it to one of the semantic roles in the plot, use it to “facet” the visualization. This means that you make multiple axes and plot subsets of the data on each of them:<jupyter_code>sns.relplot(x="total_bill", y="tip", hue="smoker",
             data=tips);
#  col="time", You can also show the influence two variables this way: one by faceting on the columns and one by faceting on the rows. As you start adding more variables to the grid, you may want to decrease the figure size. Remember that the size FacetGrid is parameterized by the height and aspect ratio of each facet:<jupyter_output><empty_output><jupyter_text>Visualizing linear relationships¶<jupyter_code>sns.lmplot(x="total_bill", y="tip", data=tips);<jupyter_output><empty_output><jupyter_text>Fitting different kinds of models¶<jupyter_code>anscombe = sns.load_dataset("anscombe")
anscombe.head()
sns.lmplot(x="x", y="y", data=anscombe.query("dataset == 'I'"),
           ci=None, scatter_kws={"s": 80}); # II... robust = True
sns.residplot(x="x", y="y", data=anscombe.query("dataset == 'I'"),
              scatter_kws={"s": 80});
sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips); #  markers=["o", "x"], palette="Set1"

sns.lmplot(x="total_bill", y="tip", hue="smoker", col="time", data=tips);


g = sns.jointplot("total_bill", "tip", data=tips, kind="reg",
                  xlim=(0, 60), ylim=(0, 12),  height=7)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08091822094691535, 'fraction_numerical': 0.0040172166427546625, 'mean_word_length': 5.626425855513308, 'pattern_counts': {'":': 3, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 2, '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': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '404478', 'license': 'MIT', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1813, 'n_words': 877, 'path': 'class/MODULE_3-data_visualization/1_Relational plots_1920.ipynb', 'repo_name': 'A905322/introduccion-a-python', 'size': '6994'}