0% found this document useful (0 votes)
7 views

Tutorial 6

Uploaded by

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

Tutorial 6

Uploaded by

VIDIT SHAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Somaiya Vidyavihar University

(Constituent College – K J Somaiya College


of Engineering)

Problem statement:

1. Find Stem-Leaf plot for the following data and provide the key to
interpret the plot. 8.6, 2.5, 9.5, 7.3, 8.4, 2.1, 9, 2.5, 6.7, 7.1, 2.5, 9.4,
8.2, 2.1, 8.4, 7.5, 2.8, 7.2. 2.2
Ans :
Code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Data
data = [8.6, 2.5, 9.5, 7.3, 8.4, 2.1, 9, 2.5, 6.7, 7.1, 2.5, 9.4, 8.2, 2.1, 8.4, 7.5, 2.8, 7.2, 2.2]

# Create a stem-and-leaf plot


def stem_leaf_plot(data):
# Find the minimum and maximum values
min_val = int(min(data))
max_val = int(max(data))

# Create a dictionary to store the stem and leaf values


stem_leaf = {}
for num in data:
stem = int(num)
leaf = int((num - stem) * 10)
if stem not in stem_leaf:
stem_leaf[stem] = []
stem_leaf[stem].append(leaf)

# Print the stem-and-leaf plot


for stem in range(min_val, max_val + 1):
if stem in stem_leaf:
print(f"{stem} | {''.join(str(leaf) for leaf in stem_leaf[stem])}")

# Print the stem-and-leaf plot


stem_leaf_plot(data)

# Key: 2|1 represents 2.1

Output:
2 | 5155172
6|7
7 | 2052
8 | 5414
Somaiya Vidyavihar University
(Constituent College – K J Somaiya College
of Engineering)
9 | 504

Find Box plot for the following data and provide the key to interpret the plot. 23,
67, 62, 52, 23, 25, 33, 55, 58, 44, 33, 32, 29, 39, 31, 55, 66, 45, 41, 43, 36, 43,
41, 41, 62
Find the minimum, maximum, first quartile, third quartile and median values from the plot.

Implement program for any one of the above.

Flow chart/pseudo code:

Box Plot

Flow chart/pseudo code:

 Start
 Import Libraries: Import necessary libraries (NumPy, Matplotlib).
 Define Data: Store the dataset in a variable.
 Calculate Statistics:
 Sort the data.
 Compute:
o Minimum
o First Quartile (Q1)
o Median (Q2)
o Third Quartile (Q3)
o Maximum
 Create Box Plot: Use Matplotlib to create a box plot.
 Display Box Plot: Show the plot.
 Print Statistics: Output the calculated statistics.
 Interpret Plot: Analyze the box plot.
Somaiya Vidyavihar University
(Constituent College – K J Somaiya College
of Engineering)
Somaiya Vidyavihar University
(Constituent College – K J Somaiya College
of Engineering)
Results Analysis:

 Minimum (23): The lowest value in the dataset, shown as the leftmost whisker of
the box plot.
 First Quartile (Q1 = 36): This indicates that 25% of the data points are below 36,
represented by the left edge of the box.
 Median (Q2 = 41): The middle value of the dataset, where 50% of the data points are
below and 50% are above, indicated by the line inside the box.
 Third Quartile (Q3 = 55): This shows that 75% of the data points are below 55,
represented by the right edge of the box.
 Maximum (67): The highest value in the dataset, shown as the rightmost whisker of
the box plot.

You might also like