0% found this document useful (0 votes)
10 views13 pages

Old Yeller Chapter 5 Summary

matplotlib and seaborn are two popular Python libraries for data visualization. Matplotlib allows for basic line plots, scatter plots, while seaborn provides additional statistical plot types like box plots, distribution plots, and heatmaps. Seaborn plots were demonstrated on an employee dataset to visualize distributions, relationships between variables, and correlations between dataset features.

Uploaded by

Shania Jone
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Old Yeller Chapter 5 Summary

matplotlib and seaborn are two popular Python libraries for data visualization. Matplotlib allows for basic line plots, scatter plots, while seaborn provides additional statistical plot types like box plots, distribution plots, and heatmaps. Seaborn plots were demonstrated on an employee dataset to visualize distributions, relationships between variables, and correlations between dataset features.

Uploaded by

Shania Jone
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Data Visualization

Data visualization is visual representation of data or information

matplotlib and seaborn are two libraries used for data visualization

matplotlib:
--lineplot,scatterplot

seaborn:
--univariant analysis(distplot,boxplot,countplot)
--bivariant analysis(barplot,scatterplot)
--multivariant analysis(heatmap)

In [1]:

import numpy as np
import pandas as pd
import [Link] as plt
executed in 1.20s, finished 11:39:15 2023-03-28

In [8]:

a=[Link]([1,2,3,4,5])
b=[Link](10,60,10)
executed in 12ms, finished 11:48:15 2023-03-28

In [6]:

a
executed in 17ms, finished 11:46:46 2023-03-28

Out[6]:

array([1, 2, 3, 4, 5])

In [9]:

b
executed in 16ms, finished 11:48:17 2023-03-28

Out[9]:

array([10, 20, 30, 40, 50])


In [10]:

[Link](a,b)
executed in 86ms, finished 11:48:20 2023-03-28

Out[10]:

[<[Link].Line2D at 0x21af1118310>]

In [11]:

[Link](a,b)
[Link]("age")
[Link]("height")
[Link]("age vs height")
executed in 91ms, finished 11:57:18 2023-03-28

Out[11]:

Text(0.5, 1.0, 'age vs height')


In [13]:

c=[Link](20,70,10)
c
executed in 16ms, finished 12:01:12 2023-03-28

Out[13]:

array([20, 30, 40, 50, 60])

In [14]:

[Link](a,b)
[Link](a,c)
[Link]("age")
[Link]("height")
[Link]("age vs height")
executed in 89ms, finished 12:02:42 2023-03-28

Out[14]:

Text(0.5, 1.0, 'age vs height')


In [15]:

[Link](a,b,label='A')
[Link](a,c,label='B')
[Link]("age")
[Link]("height")
[Link]("age vs height")
[Link]()
executed in 121ms, finished 12:11:45 2023-03-28

Out[15]:

<[Link] at 0x21af1ff8370>

In [18]:

a=[Link](10,50,10)
b=[Link](0,10)
c=[Link](5,15)
[Link](a,b,label='A')
[Link](a,c,label='B')
[Link]()
executed in 103ms, finished 12:26:54 2023-03-28

Out[18]:

<[Link] at 0x21af19e77f0>
In [9]:

import [Link] as plt


import numpy as np
import seaborn as sns
executed in 6ms, finished 09:52:20 2023-03-29

In [3]:

a=[Link]([1,2,3,4,5])
b=[Link]([4,8,10,8,7])
fig,ax=[Link](figsize=(5,4))
[Link](a,b)
executed in 147ms, finished 07:45:07 2023-03-29

Out[3]:

[<[Link].Line2D at 0x1b82ce43460>]

In [4]:

[Link](a,b)
executed in 88ms, finished 07:45:16 2023-03-29

Out[4]:

<[Link] at 0x1b82cf46610>
In [5]:

a=[Link](1,10,20)
executed in 29ms, finished 07:45:18 2023-03-29

In [22]:

executed in 5ms, finished 13:51:13 2023-03-28

Out[22]:

array([3, 4, 8, 3, 3, 3, 6, 6, 8, 3, 4, 9, 1, 9, 8, 8, 4, 3, 8, 3])

In [11]:

import pandas as pd
executed in 3ms, finished 09:52:31 2023-03-29

In [7]:

emp=pd.read_csv("[Link]")
executed in 39ms, finished 07:45:25 2023-03-29

In [8]:

[Link]()
executed in 32ms, finished 07:45:27 2023-03-29

Out[8]:

Age Attrition BusinessTravel DailyRate Department DistanceFromHome Education E

0 41 Yes Travel_Rarely 1102 Sales 1 2

Research &
1 49 No Travel_Frequently 279 8 1
Development

Research &
2 37 Yes Travel_Rarely 1373 2 2
Development

Research &
3 33 No Travel_Frequently 1392 3 4
Development

Research &
4 27 No Travel_Rarely 591 2 1
Development

5 rows × 35 columns

In [10]:

import seaborn as sns


executed in 3ms, finished 09:52:24 2023-03-29

# Distribution plot
Distribution plot are used for analyzing the detailed distribution of a dataset.

In [28]:

[Link](emp["DistanceFromHome"])
executed in 1.04s, finished 14:00:18 2023-03-28

C:\Users\Harshitha GS\anaconda3\lib\site-packages\seaborn\distributions.p
y:2619: FutureWarning: `distplot` is a deprecated function and will be rem
oved in a future version. Please adapt your code to use either `displot`
(a figure-level function with similar flexibility) or `histplot` (an axes-
level function for histograms).
[Link](msg, FutureWarning)

Out[28]:

<AxesSubplot:xlabel='DistanceFromHome', ylabel='Density'>

# box plot
Box plot are used for analyzing the detailed distribution of a dataset and detection of
outliers.
In [29]:

[Link](emp["MonthlyIncome"])
executed in 150ms, finished 14:20:16 2023-03-28

C:\Users\Harshitha GS\anaconda3\lib\site-packages\seaborn\_decorators.py:3
6: FutureWarning: Pass the following variable as a keyword arg: x. From ve
rsion 0.12, the only valid positional argument will be `data`, and passing
other arguments without an explicit keyword will result in an error or mis
interpretation.
[Link](

Out[29]:

<AxesSubplot:xlabel='MonthlyIncome'>

#countplot used to univariant analysis of categorical features


In [30]:

[Link](emp["Department"])
executed in 171ms, finished 14:36:55 2023-03-28

C:\Users\Harshitha GS\anaconda3\lib\site-packages\seaborn\_decorators.py:3
6: FutureWarning: Pass the following variable as a keyword arg: x. From ve
rsion 0.12, the only valid positional argument will be `data`, and passing
other arguments without an explicit keyword will result in an error or mis
interpretation.
[Link](

Out[30]:

<AxesSubplot:xlabel='Department', ylabel='count'>

In [31]:

[Link](data=emp,x="Department")
executed in 91ms, finished 14:48:54 2023-03-28

Out[31]:

<AxesSubplot:xlabel='Department', ylabel='count'>
In [12]:

import numpy as np
import pandas as pd
import [Link] as plt
import seaborn as sns
executed in 10ms, finished 10:12:22 2023-03-29

In [13]:

emp=pd.read_csv("[Link]")
[Link]()
executed in 79ms, finished 10:14:19 2023-03-29

Out[13]:

Age Attrition BusinessTravel DailyRate Department DistanceFromHome Education E

0 41 Yes Travel_Rarely 1102 Sales 1 2

Research &
1 49 No Travel_Frequently 279 8 1
Development

Research &
2 37 Yes Travel_Rarely 1373 2 2
Development

Research &
3 33 No Travel_Frequently 1392 3 4
Development

Research &
4 27 No Travel_Rarely 591 2 1
Development

5 rows × 35 columns

# Bar plot
Bar plot shows the relationship between a numeric and a categoric variable.
In [15]:

[Link](data=emp,x="Department",y='MonthlyIncome')
executed in 226ms, finished 10:21:42 2023-03-29

Out[15]:

<AxesSubplot:xlabel='Department', ylabel='MonthlyIncome'>

In [16]:

[Link](data=emp,x="Department",y='MonthlyIncome',hue="Attrition")
executed in 308ms, finished 10:31:30 2023-03-29

Out[16]:

<AxesSubplot:xlabel='Department', ylabel='MonthlyIncome'>

# Scatter plot
Scatter plot shows the relationship between two numerical variables.
In [17]:

[Link](data=emp,x="DailyRate",y="MonthlyIncome")
executed in 156ms, finished 10:44:58 2023-03-29

Out[17]:

<AxesSubplot:xlabel='DailyRate', ylabel='MonthlyIncome'>

In [19]:

[Link](data=emp,x="DailyRate",y="MonthlyIncome",hue="MonthlyIncome",style="Dep
executed in 382ms, finished 10:52:03 2023-03-29

Out[19]:

<AxesSubplot:xlabel='DailyRate', ylabel='MonthlyIncome'>

# Heatmap
A heatmap is a two-dimensional graphical representation of data where the individual
values that are contained in a matrix are represented as colours
In [20]:

[Link]([Link]())
executed in 330ms, finished 11:02:28 2023-03-29

Out[20]:

<AxesSubplot:>

In [22]:

ins=pd.read_csv("[Link]")
executed in 23ms, finished 11:08:24 2023-03-29

In [25]:

[Link]([Link](),annot=True)
executed in 198ms, finished 11:18:52 2023-03-29

Out[25]:

<AxesSubplot:>

Common questions

Powered by AI

Bar plots efficiently convey information about the relationship between numerical and categorical variables by providing a visual representation of aggregated data values for each category. They offer insights into differences between categories by showing variations in the height of bars, corresponding to measures like mean, median, or sum of a numerical variable for each category . Bar plots support comparative analysis, allowing observers to easily discern patterns, trends, and discrepancies among groups or classifications within the dataset.

Adapting data visualization code to changes in library versions is crucial for maintaining functionality, compatability, and taking advantage of improved performance and features. Seaborn's warnings, such as those regarding the distplot function, emphasize the necessity of using recommended alternatives like displot or histplot to prevent future compatibility issues . This practice ensures that data visualizations remain reliable and accurate, leveraging modern developments to enhance data analysis capabilities and avoid disruptions caused by deprecated functions.

Univariate analysis in seaborn focuses on single-variable distributions and includes techniques like distplot (deprecated), like histplot, and countplot which analyze categorical features . Bivariate analysis deals with two variables, often using scatterplots and barplots to show relationships between a numeric and a categorical variable or between two numerical variables . Multivariate analysis involves more than two variables, such as heatmaps that visualize correlation matrices using color coding to represent data values .

Seaborn offers several functions for conducting bivariate analysis, including barplots and scatterplots. Barplots are used to analyze relationships between numerical and categorical variables, enabling insights into distributions and category differences . Scatterplots, on the other hand, allow the examination of relationships between two numerical variables, highlighting trends, patterns, and potential correlations within the dataset. Bivariate analyses can uncover associations that inform hypotheses and data-driven decision-making.

Warnings about future changes in seaborn's distplot function indicate that it will be deprecated, so users need to adapt their code to maintain future compatibility. This can be addressed by switching to either the displot or histplot functions, which offer similar functionality for generating distribution plots as figure-level or axes-level functions, respectively . Such warnings highlight the importance of staying updated with library documentation to avoid deprecated functionalities that might break in future updates.

Box plots provide unique benefits for data analysis by succinctly summarizing key distribution metrics such as median, quartiles, and potential outliers in a dataset. They aid in detecting outliers by visually highlighting values that deviate significantly from the rest of the data, often represented as points beyond the whiskers. This makes box plots effective in comparative analysis contexts, allowing analysts to visually assess variability and symmetry of data distributions across categories or groups .

Legends in matplotlib plots are important because they help distinguish between different data series by providing a clear label for each line or point set. This enhances the readability and interpretability of the data, especially when multiple datasets are plotted in the same figure . Legends aid in quickly identifying which data corresponds to which scenario or parameter, making complex visualizations more accessible to users.

Heatmaps are used to represent complex data relationships by visually encoding matrix values into colors, making it easy to identify patterns, correlations, and anomalies across large datasets. They are particularly effective for showing correlation matrices because colors quickly convey the magnitude and direction of correlations between pairs of variables, providing a clear and immediate understanding of potentially significant relationships . Annotations in heatmaps further enhance interpretation by displaying numerical correlation values on individual blocks, aiding precise data analysis.

Scatter plots are crucial in visualizing relationships between two numerical variables, allowing for the identification of trends, clusters, and potential correlations. In seaborn, scatter plots can be augmented with additional dimensions by using colors (hue) and shapes (style) to represent different categories or values, enhancing their capability to depict complex datasets . They effectively illustrate patterns and anomalies in the data by plotting data points along x and y axes, where the axes represent the variables being compared.

Distribution plots assist in understanding dataset characteristics by displaying how values are spread across the range of the variable, highlighting the frequency of observations within different value intervals . Following the deprecation of distplot, seaborn recommends using displot, which is a figure-level function, or histplot, an axes-level function for histograms. These functions provide more flexible and comprehensive options for examining distributions, supporting better customization and analysis of the underlying data characteristics.

You might also like