Chapter 5: Data Visualization

Why Data Visualization?Data ko sirf table me dekhne se pattern samajh nahi aata. Graphs se hum 1 min me trend, outlier, correlation pakad lete hain.

Key Goals:

  • Explore: Data me kya chal raha hai samjhna
  • Explain: Result dusro ko dikhana
  • Detect: Outliers, missing values, distribution

2.Types of Charts & Kab Use Karein

Chart TypeUse CasePython Library
Bar ChartCategories compare karnamatplotlib.pyplot.bar()
Line ChartTime series trendplt.plot()
HistogramData ka distributionplt.hist()
Scatter Plot2 variables ka relationplt.scatter()
Box PlotOutliers + Quartilessns.boxplot()
HeatmapCorrelation matrixsns.heatmap()
Pie Chart Percentage compositionplt.pie()

3.Important Python Libraries

import matplotlib.pyplot as plt # Basic plots
import seaborn as sns # Better looking plots
import plotly.express as px # Interactive plots
import pandas as pd

4. IMPO Programs for Chapter 5

Program 1: Bar Chart

import matplotlib.pyplot as plt
subjects = [‘Python’, ‘SQL’, ‘ML’, ‘Stats’]
scores = [90, 80, 85, 75]
plt.bar(subjects, scores, color=’skyblue’)
plt.title(“Gatestudy Student Scores”)
plt.show()

Program 2: Histogram – Data Distribution

import seaborn as sns
data = [12, 15, 18, 20, 20, 22, 25, 30, 35]
sns.histplot(data, bins=5, kde=True)
plt.title(“Age Distribution”)

Program 3: Scatter Plot – Correlation

import matplotlib.pyplot as plt
study_hours = [1, 2, 3, 4, 5]
marks = [40, 50, 60, 70, 90]
plt.scatter(study_hours, marks)
plt.xlabel(“Study Hours”); plt.ylabel(“Marks”)
plt.show()

Program 4: Heatmap – Correlation

import seaborn as sns
import pandas as pd
df = pd.DataFrame({‘A’:[1,2,3], ‘B’:[3,2,1], ‘C’:[1,1,2]})
sns.heatmap(df.corr(), annot=True, cmap=”YlGnBu”)

Program 5: Box Plot – Outlier Detection

import seaborn as sns
data = [10,12,12,13,14,15,100] # 100 is outlier
sns.boxplot(data=data)

6.Interview/Gate PYQ Type Questions

1-plt.hist() aur sns.histplot() me kya difference hai?

2-Correlation dekhne ke liye kaunsa chart best hai?

3-Overplotting ko kaise handle karenge scatter plot me?

4-Categorical data ke liye kaunsa plot?

Leave a Comment

Your email address will not be published. Required fields are marked *