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

X-AI Practical File-2 (2024)

Uploaded by

Priyanshu Murari
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)
207 views

X-AI Practical File-2 (2024)

Uploaded by

Priyanshu Murari
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/ 17

DPS RUBY PARK, KOLKATA

CLASS X [2024 - 25]


ARTIFICIAL INTELLIGENCE

BOARD PRACTICAL FILE PROGRAMS Part- II

Submission Deadline: 15 NOVEMBER, 2024

NB: If you submit any time after the deadline, you will not receive full credit
points

Instructions for Preparing the Practical File:

1. Take printouts of all programs on A4 size pages.


2. Do NOT take printouts on both sides of the pages (single-sided only).
3. Ensure to take color printouts so that the output is clearly visible.
4. Add your Name and Class-Section on the front page (to be provided
separately).
5. The Index Page will be provided separately.
6. Include the previously given 10 programs at the front of your file.
7. Place all pages in a transparent channel file.
8. Ensure that the front page is visible in the file.
9. Each student must submit their file individually.
10.This Practical File will carry 15 marks in the Pre-Board Practical Exam.
11.The Practical File is required for the Board Practical Exam 2025.

********************

10
DATA SCIENCE PROGRAMS
1 Write a program to create a 2D array using NumPy
Program:
import numpy as np
arr = np.arange(5,45,5)
arr = arr.reshape(2,4)
print(arr)

Output:

2 Write a program to convert a python list to a NumPy array.


Program:
import numpy as np
l = []
n=int(input("Enter the no. of elements:"))

for i in range(n):
val=int(input("Enter value " + str(i+1) + ":" ))
l.append(val)

arr = np.array(l)
print("Array:",arr)

Output:

Page 11
3 Write a program to create a matrix of 3x3 from 11 to 30.

Program:
import numpy as np

arr = np.arange(11,28,2)
arr = arr.reshape(3,3)
print(arr)

Output:

4 Write a program to calculate variance and standard deviation for the given
data: [33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]

Program:
import statistics

l=[33,44,55,67,54,22,33,44,56,78,21,31,43,90,21,33,44,55,87]

print("Variance:”, statistics.variance(l))
print("Standard Deviation:”, statistics.stdev(l))

Output:

5 Write a 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]

Page 12
Program:
import statistics
l=[5,6,1,3,4,5,6,2,7,8,6,5,4,6,5,1,2,3,4]

print("Mean Value: “, statistics.mean(l))


print("Mode Value: “, statistics.mode(l))
print("Median Value: “, statistics.median(l))

Output:

6 Write a program to create a data frame to store data of candidates who


appeared in interviews. The data frame columns are name, score, attempts,
and qualify (Yes/No). Assign rowindex as C001,C002, and so on.

Program:
import pandas as pd

d = { 'Name':['Anil','Bhavna','Chirag','Dhara','Giri'],
'Score':[25,20,22,23,21],
'Attempts':[1,2,2,1,1],
'Qualified':['Yes','No','Yes','Yes','No']
}

df = pd.DataFrame(d, index=['C001','C002','C003','C004','C005'] )

print(df)

Output:

Page 13
7 Write a program to create a dataframe named player and store their data in
the columns like team, no. of matches runs, and average. Assign player name
as row index and Display only those player details whose score is more than
1000.

Program:
import pandas as pd

d = { 'Team':['India','Pakistan','England','Australia'],
'Matches':[25,23,19,17],
'Runs':[1120,1087,954,830],
'Average':[44.80,47.26,50.21,48.82]
}

player=pd.DataFrame(d,index=['Virat kohli','Babar Azam','Ben


Stokes','Steve Smith'])

print(player[player['Runs']>1000])

Output:

Page 14
8 Write a program to represent the data on the ratings of mobile games on a bar
chart.
The sample data is given as: Games:Pubg, FreeFire, MineCraft, GTA-V, Call
of duty, FIFA 22. The rating for each game is as: 4.5,4.8,4.7,4.6,4.1,4.3.

Program:

import matplotlib.pyplot as plt

games = ['Pubg', 'FreeFire', 'MineCraft', 'GTA-V','Call of duty', 'FIFA 22']


rating = [4.5,4.8,4.7,4.6,4.1,4.3]

plt.bar(games, rating, color = ['black', 'red', 'green', 'blue', 'yellow'] )


plt.title("Games Rating 2022")
plt.xlabel('Games')
plt.ylabel('Rating')
plt.legend()
plt.show()

Output:

Page 15
9 Write a program to represent the data given on a scatter plot chart.
Height (cm) = [120,145,130,155,160,135,150]
Weight (kg) = [40,50,47,62,60,55,58]

Program

import matplotlib.pyplot as plt


# data to display on plots
x = [120,145,130,155,160,135,150]
y = [40,50,47,62,60,55,58]

# This will plot a simple scatter chart


plt.scatter(x, y)

# Adding legend to the plot


plt.legend("A")

# Title to the plot


plt.title("Scatter chart")
plt.show()
Output:

Page 16
10 Consider the following data of a clothes store and plot the data on the line
chart and customize the chart as you wish:

Program:

import matplotlib.pyplot as pp

mon =['March','April','May','June','July','August']
jeans= [1500,3500,6500,6700,6000,6800]
ts = [4400,4500,5500,6000,5600,6300]
sh = [6500,5000,5800,6300,6200,4500]

pp.plot(mon,jeans,label='Mask',color='g',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='r')

pp.plot(mon,ts,label='Mask',color='b',linestyle='dashed', linewidth=4,\
marker='3', markerfacecolor='k', markeredgecolor='g')

pp.plot(mon,sh,label='Mask',color='r',linestyle='dashed', linewidth=4,\
marker='v', markerfacecolor='k', markeredgecolor='b')

pp.title("Apna Garment Store")


pp.xlabel("Months")
pp.ylabel("Garments")
pp.legend()
pp.show()

Output:

Page 17
11 Observe the given data for monthly sales of one of the salesmen for 6
months. 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 dashed lines with the width 5 points.
• Use red color for the line.
• Use dot marker with blue edge color and black fill color.

Program:
import matplotlib.pyplot as pp

mon = ['January','February','March','April','May','June']
sales = [2500,2100,1700,3500,3000,3800]

plt.plot(mon,sales,label='Sales',color='r',linestyle='dashed', linewidth=4,\
marker='o', markerfacecolor='k', markeredgecolor='b')

Page 18
plt.title("Sales Report")
plt.xlabel("Months")
plt.ylabel("Sales")
plt.legend()
plt.show()

Output:

12 Consider the following marks of students and plot the data on the histogram
and customize the chart as you wish:

Program:

import matplotlib.pyplot as plt


marks =[18, 16, 82, 41, 75, 86, 28, 79, 68, 13, 42, 39, 96, 49, 74, 90, 25, 65,
10, 30]
# This will plot a simple histogram
plt.hist(marks, bins = 5, edgecolor='red', color='green')
# Title to the plot
plt.title("Marks Distribution of Students ")
plt.xlabel("Marks of Students")

Page 19
plt.ylabel("Count of Students")
plt.show()

Output:

Page 20
COMPUTER VISION PROGRAMS

1 On the basis of this online tool, try and write answers to all the below-mentioned questions.

What is the output colour when you put R=G=B=255?


What is the output colour when you put R=G=255,B=0?
What is the output colour when you put R=255,G=0,B=255?
What is the output colour when you put R=0,G=255,B=255?
What is the output colour when you put R=G=B=0?
What is the output colour when you Put R=0,G=0,B=255?
What is the output colour when you Put R=255,G=0,B=0?
What is the output colour when you put R=0,G=255,B=0?
What is the value of your colour?

Solution:
White
Yellow
Pink
Cyan
Black
Blue
Red
Green
R=0,G=0,B=255

2 Create your own pixels on piskelapp (https://www.piskelapp.com/) and make a gif image.

Solution:

Steps:
1. Open piskelapp on your browser.
2. Apply background for the picture.
3. Use pen to draw letter A
4. Copy the layer and paste it
5. Now erase letter A written previously
6. Apply the background colour for layer 2
7. Change the pen colour and Write I
8. Export the image.
9. Follow this link to access animated GIF: Click here

Page 21
3 Do the following tasks in OpenCV.

a. Load an image and Give the title of the image.


b. Change the colour of the image and Change the image to grayscale.
c. Print the shape of the image.
d. Display the maximum and minimum pixels of the image.
e. Crop the image and extract the part of an image.
f. Save the Image.

1. Load an image and give the title of the image


#import required module cv2, matplotlib and numpy
import cv2
import matplotlib.pyplot as plt
import numpy as np

#Load the image file into memory


img = cv2.imread('octopus.png')

#Display Image
plt.imshow(img)
plt.title('Octopus')
plt.axis('off')
plt.show()

Page 22
2. Change the colour of image and Change the image to grayscale
#import required module cv2, matplotlib and numpy
import cv2
import matplotlib.pyplot as plt
import numpy as np

#Load the image file into memory


img = cv2.imread('octopus.png')

#Changing default image colour into RGB image colour


plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('Octopus')
plt.axis('off')
plt.show()

Page 23
#Changing image colour into gray image
image = cv2.imread('octopus.png')
cv2.imshow('Original',image)
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow('Grayscale', grayscale)

OUTPUT

Page 24
3. Print the shape of image
import cv2
img = cv2.imread('octopus.png',0)
print(img.shape)

OUTPUT:

(441, 453)
4. Display the maximum and minimum pixels of image
import cv2
img = cv2.imread('octopus.png',0)
print(img.min())
print(img.max())

OUTPUT

0
250
5. Crop the image and extract the part of an image
import cv2
import matplotlib.pyplot as plt

img = cv2.imread('octopus.png')
pi=img[150:400,100:200]
plt.imshow(cv2.cvtColor(pi, cv2.COLOR_BGR2RGB))
plt.title('Octopus')
plt.axis('off')
plt.show()

Page 25
6. Save the Image import cv2

import matplotlib.pyplot as plt


img = cv2.imread('octopus.png')
plt.imshow(img)
cv2.imwrite('oct.jpg',img)
plt.title('Octopus')
plt.axis('off')
plt.show()

Page 26

You might also like