<jupyter_start><jupyter_text>_Lambda School Data Science_ Choose appropriate visualizations  Upgrade SeabornMake sure you have at least version 0.9.0<jupyter_code>!pip install --upgrade seaborn
import seaborn as sns
sns.__version__<jupyter_output><empty_output><jupyter_text>Fix misleading visualizations<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
!wget https://raw.githubusercontent.com/LambdaSchool/DS-Sprint-02-Storytelling-With-Data/master/module2-choose-appropriate-visualizations/misleading.py
    
import misleading<jupyter_output>--2018-11-13 17:11:54--  https://raw.githubusercontent.com/LambdaSchool/DS-Sprint-02-Storytelling-With-Data/master/module2-choose-appropriate-visualizations/misleading.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 172.16.31.10, 192.168.127.12, 192.168.127.12, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|172.16.31.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1641 (1.6K) [text/plain]
Saving to: ‘misleading.py’


misleading.py         0%[                    ]       0  --.-KB/s               
misleading.py       100%[===================>]   1.60K  --.-KB/s    in 0s      

2018-11-13 17:11:54 (163 MB/s) - ‘misleading.py’ saved [1641/1641]<jupyter_text>Fix misleading plot 1<jupyter_code>misleading.plot1()
misleading??<jupyter_output><empty_output><jupyter_text>Fix misleading plot 2<jupyter_code>misleading.plot2()
misleading.plot2??<jupyter_output><empty_output><jupyter_text>Not 100%, add another row with the remainder of 100%  Fix misleading plot 3<jupyter_code>misleading.plot3()<jupyter_output><empty_output><jupyter_text>Fix misleading plot 4 _If you're on Jupyter (not Colab) then uncomment and run this cell below:_<jupyter_code># import altair as alt
# alt.renderers.enable('notebook')
misleading.plot4()<jupyter_output><empty_output><jupyter_text>Links- [How to Spot Visualization Lies](https://flowingdata.com/2017/02/09/how-to-spot-visualization-lies/)- [Where to Start and End Your Y-Axis Scale](http://stephanieevergreen.com/y-axis/)- [xkcd heatmap](https://xkcd.com/1138/)- [Surprise Maps: Showing the Unexpected](https://medium.com/@uwdata/surprise-maps-showing-the-unexpected-e92b67398865)  Use Seaborn to visualize distributions and relationships with continuous and discrete variables Links- [Seaborn tutorial](https://seaborn.pydata.org/tutorial.html)- [Seaborn example gallery](https://seaborn.pydata.org/examples/index.html)- [Chart Chooser](https://extremepresentation.typepad.com/files/choosing-a-good-chart-09.pdf)  1. Anscombe dataset  Load dataset<jupyter_code>df = sns.load_dataset('anscombe')<jupyter_output><empty_output><jupyter_text>See the data's shape<jupyter_code>df.shape<jupyter_output><empty_output><jupyter_text>See the data<jupyter_code>df<jupyter_output><empty_output><jupyter_text>[Group by](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html) `'dataset'`<jupyter_code>groups = df.groupby(by='dataset')<jupyter_output><empty_output><jupyter_text>[Describe](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.describe.html) the groups<jupyter_code>groups.describe()<jupyter_output><empty_output><jupyter_text>Get the [count](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.count.html), for each column in each group<jupyter_code>groups.count()<jupyter_output><empty_output><jupyter_text>Get the [mean](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.mean.html) ...<jupyter_code>groups.mean()<jupyter_output><empty_output><jupyter_text>Get the [standard deviation](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.std.html) ...<jupyter_code>groups.std()<jupyter_output><empty_output><jupyter_text>Get the [correlation](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.corr.html) ...<jupyter_code>groups.corr()<jupyter_output><empty_output><jupyter_text>Use pandas to [plot](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html) the groups, as scatter plots<jupyter_code>groups.plot(x='x', y='y', kind='scatter');<jupyter_output><empty_output><jupyter_text>Use Seaborn to make [relational plots](http://seaborn.pydata.org/generated/seaborn.relplot.html)<jupyter_code>sns.relplot(x="x", y="y", col='dataset', data=df, hue='dataset', col_wrap=2);<jupyter_output><empty_output><jupyter_text>Use Seaborn to make [linear model plots](http://seaborn.pydata.org/generated/seaborn.lmplot.html)<jupyter_code>sns.lmplot(x="x", y="y", col='dataset', data=df, hue='dataset', col_wrap=2);
# add ci=None  to remove the confidence interval from chart<jupyter_output><empty_output><jupyter_text>Links- [Seaborn examples: Anscombe's quartet](http://seaborn.pydata.org/examples/anscombes_quartet.html)- [Wikipedia: Anscombe's quartet](https://en.wikipedia.org/wiki/Anscombe%27s_quartet)- [The Datasaurus Dozen](https://www.autodeskresearch.com/publications/samestats)  2. Tips dataset  Load dataset<jupyter_code>tips = sns.load_dataset('tips')<jupyter_output><empty_output><jupyter_text>See the data's shape<jupyter_code>tips.shape<jupyter_output><empty_output><jupyter_text>See the first 5 rows<jupyter_code>tips.head()
# tips.tail() for last 5
# tips.random(5) for random 5<jupyter_output><empty_output><jupyter_text>Describe the data<jupyter_code>tips.describe()
# tips.describe(include='all')  to see all data described
# tips.describe(exclude=[np.number]) to exclude a variable<jupyter_output><empty_output><jupyter_text>Make univariate [distribution plots](https://seaborn.pydata.org/generated/seaborn.distplot.html)<jupyter_code>sns.distplot(tips.tip);
sns.distplot(tips.total_bill);<jupyter_output><empty_output><jupyter_text>Make bivariate [relational plots](https://seaborn.pydata.org/generated/seaborn.relplot.html)<jupyter_code>sns.relplot(x="tip", y="total_bill", data=tips, alpha=0.5);<jupyter_output><empty_output><jupyter_text>Make univariate [categorical plots](https://seaborn.pydata.org/generated/seaborn.catplot.html)<jupyter_code>sns.catplot(x="tip", y="total_bill", hue="day", data=tips);
sns.catplot('tip', data=tips, kind='count');<jupyter_output><empty_output><jupyter_text>Make bivariate [categorical plots](https://seaborn.pydata.org/generated/seaborn.catplot.html)<jupyter_code>sns.catplot(x="sex", y="tip", data=tips, kind='box');
sns.catplot(x="sex", y="tip", data=tips, kind='strip', alpha=0.5);
sns.catplot(x="sex", y="tip", data=tips, kind='swarm');
sns.catplot(x="sex", y="tip", data=tips, kind='bar');
# auto calculates average and adds a confidence interval line
sns.catplot(x="sex", y="total_bill", data=tips, kind='bar');<jupyter_output><empty_output><jupyter_text>3. Flights  Load dataset<jupyter_code>flights = sns.load_dataset('flights')<jupyter_output><empty_output><jupyter_text>See the data's shape<jupyter_code>flights.shape<jupyter_output><empty_output><jupyter_text>See the first 5 rows<jupyter_code>flights.head()<jupyter_output><empty_output><jupyter_text>Describe the data<jupyter_code>flights.describe()<jupyter_output><empty_output><jupyter_text>Plot year & passengers<jupyter_code>flights.plot('year', 'passengers');<jupyter_output><empty_output><jupyter_text>Plot month & passengers<jupyter_code>flights.plot('month', 'passengers');<jupyter_output><empty_output><jupyter_text>Create a [pivot table](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot_table.html) of passengers by month and year<jupyter_code>pivot = flights.pivot_table(values='passengers', index="month", columns="year")<jupyter_output><empty_output><jupyter_text>Plot the pivot table as a [heat map](https://seaborn.pydata.org/generated/seaborn.heatmap.html)<jupyter_code>sns.set(rc={'figure.figsize':(10,10)})
sns.heatmap(pivot, annot=True, fmt="d");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1518827394490776, 'fraction_numerical': 0.02122820318423048, 'mean_word_length': 7.913288288288288, 'pattern_counts': {'":': 0, '<': 136, '<?xml version=': 0, '>': 137, 'https://': 23, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 4, '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': '34', 'dir': 'jupyter-structured-clean-dedup', 'id': '581480', 'license': 'MIT', 'n_tokens_mistral': 3106, 'n_tokens_neox': 2894, 'n_words': 380, 'path': 'module2-choose-appropriate-visualizations/LS_DS_122_Choose_appropriate_visualizations.ipynb', 'repo_name': 'BrianBehnke/DS-Sprint-02-Storytelling-With-Data', 'size': '7917'}