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

Grade 10 AI Practicals DATA SCIENCE-Solution

Uploaded by

suhanidevgan2009
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)
164 views

Grade 10 AI Practicals DATA SCIENCE-Solution

Uploaded by

suhanidevgan2009
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
You are on page 1/ 6

ARTIFICIAL INTELLIGENCE- 417

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

1.mean 2.mode 3.median)


Enter your choice2
Mode is 5

1.mean 2.mode 3.median)


Enter your choice3
Median is 5

2. Write a menu driven Python program to calculate variance and standard


deviation for the given data:
DATA VISUALIZATION
3. Write a Python program to represent the data on the ratings of Programming
Languages on Bar graph. The sample data is given as: Java, Python, C++, C, PHP.
The rating for each game is as: 4.5, 4.8, 4.7, 4.6, 4.3.

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.

Month January February March April May June


Sales 2500 2100 1700 3500 3000 3800

Apply the following customizations to the chart:


• Give the title for the chart – “Sales Stats”
• Use the “Month” label for X-Axis and “Sales” for Y-Axis.
• Display legends.
• Use red colour for the line.
• Use dot marker with fill colour black.
Solution:
import matplotlib.pyplot as p1
months = ['January', 'February', 'March', 'April', 'May', 'June']
sales = [2500, 2100, 1700, 3500, 3000, 3800]
p1.plot(months, sales, marker='*', linestyle='-', color='red',
markerfacecolor="black",markeredgecolor="black")
p1.title('Sales status of a Salesman', color="green",fontweight="bold")
p1.xlabel('Month',color="maroon")
p1.ylabel('Sales ($)',color="maroon")
p1.xticks(rotation=45)
p1.yticks(rotation=45)
p1.grid(True)
p1.show()

Output:

Line Styles: Marker Styles:

• '-': Solid line


• '--': Dashed line
• '-.': Dash-dot line
• ':': Dotted line

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:

You might also like