Grade 10 AI Practicals DATA SCIENCE-Solution
Grade 10 AI Practicals DATA SCIENCE-Solution
GRADE 10 (2024-25)
DATA SCIENCE – PRACTICAL
STATISTICAL LEARNING (Use Numpy)
1. Write a menu-driven Python program to calculate the mean, mode and median
for the given data.
[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]
Solution:
import statistics as s1
import numpy as np
a=np.array([5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4])
print("1.mean 2.mode 3.median)")
ch=int(input("Enter your choice:"))
if(ch==1):
print("Mean is ",s1.mean(a))
elif (ch==2):
print("Mode is ",s1.mode(a))
elif (ch==3):
print("Median is ",s1.median(a))
else:
print("Invalid choice")
Output:
1.mean 2.mode 3.median)
Enter your choice:1
Mean is 4
Solution:
import matplotlib.pyplot as plt
languages = ['Java', 'Python', 'C++', 'C', 'PHP']
ratings = [4.5, 4.8, 4.7, 4.6, 4.3]
plt.bar(languages, ratings, color=['blue', 'green', 'red', 'orange', 'purple'],width=0.4,
ec="black")
plt.title('Programming Language Ratings', color="blue")
plt.xlabel('Programming Languages')
plt.ylabel('Ratings')
plt.show()
Output:
4. Consider the following data for monthly sales of one of the salesmen for 6 months. Write
a Python program to plot them on the line chart.
Output:
5. In an engineering college, number of admissions stream wise in the current year are:
Civil =15, Electrical =35, Mechanical =40, Chemical = 20, Computer Science = 50
Write a Python program to print above information on a circular pie chart, and create a wedge
for Computer Science stream.
Solution:
import matplotlib.pyplot as p1
streams = ['Civil', 'Electrical', 'Mechanical', 'Chemical', 'Computer
Science']
admissions = [15, 35, 40, 20, 50]
explode = [0, 0, 0, 0, 0.1]
# Create pie chart
p1.pie(admissions, labels=streams, explode=explode, autopct='%1.1f%%',
colors=['lightblue', 'lightgreen', 'orange', 'pink', 'yellow'])
p1.title('Admissions in Different Engineering Streams')
p1.show()
Output:
6. Marks of four students in three different subjects are available in three lists. Write a Python
program to create Boxplot for the following data with their unique labels.
Maths = [74.5,76.5,95,86]
Science = [89,95,79,92]
SST = [87,91,82, 72]
Solution:
import matplotlib.pyplot as plt
Maths = [74.5, 76.5, 95, 86]
Science = [89, 95, 79, 92]
SST = [87, 91, 82, 72]
data = [Maths, Science, SST]
plt.boxplot(data, labels=["Maths", "Science", "SST"])
plt.title("Boxplot of Students' Marks in Different Subjects")
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.show()
Output:
7. The height and weight of ten students are shown in the table. Write a Python program to
construct a Scatter plot for the given information.
Height 120 145 130 155 160 135 150 145 130 140
(cm)
Weight 40 50 47 62 60 55 58 52 50 49
(cm)
Solution:
import matplotlib.pyplot as p
height = [120, 145, 130, 155, 160, 135, 150, 145, 130, 140]
weight = [40, 50, 47, 62, 60, 55, 58, 52, 50, 49]
p.scatter(height, weight, color='purple', marker='D')
p.grid(True)
p.title("Scatter Plot of Students' Height vs Weight")
p.xlabel("Height (cm)")
p.ylabel("Weight (kg)")
p.show()
Output:
8. Given the following set of data:
Marks of 16 Students are:
[22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 5, 79, 31, 27].
Write a Python program to plot a Histogram for the given data.
Solution:
import matplotlib.pyplot as plt
marks = [22, 87, 5, 43, 56, 73, 55, 54, 11, 20, 51, 65, 79, 31, 27]
plt.hist(marks, bins=6, edgecolor='black')
plt.title('Histogram of Student Marks')
plt.xlabel('Marks')
plt.ylabel('Frequency')
plt.show()
Output: