Ai Class 12 Practical 2
Ai Class 12 Practical 2
Session
2024-25
Practical File
Subject: Artificial
Intelligence (843)
Submitted By Submitted To
Student Name: Chiranjeev Seth Teacher Name: Mrs. Narayani
Roll No: Singh
Class & Sec: XII A (PGT Computer Science)
AISSCE (CLASS XII) Practical Examination in
Artificial Intelligence
Session 2024-25
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to my Artificial
Intelligence teacher Mrs. Narayani Singh , as well as our Principal,
Mrs. Roli Tripathi for providing me with the opportunity to work on
this beautiful project.
2 Write a python program for Training and Test Data in Python Machine
Learning.
3 Write python program to calculate Mean Absolute Error for given dataset.
4 Write python program to calculate Root Mean Absolute Error for given
dataset.
5 Write python program to calculate Mean Squared Error for given dataset.
6 WAP to check given year is a leap year.
Q1. Write a python program to show Decompose Time Series Data into Trend.
Source Code:
Source Code:
import numpy as np
data = np.random.randn(1000)
plt.xlabel('Values')
plt.ylabel('Frequency')
plt.title('Basic Histogram')
plt.show()
Output:
Q11. WAP in python to draw two plots on the same figure for age verses speed of cycling.
Source Code:
plt.show()
Output:
Q13. WAP in python to plot pie chart for five fruits and their quantity in basket and Pull the "Apples"
wedge 0.2 from the center of the pie.
Source Code:
import matplotlib.pyplot as plt
import numpy as np
Output:
Q15. WAP in python with Pyplot, use the grid() function to add grid lines to the plot.
Source Code:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
plt.plot(x, y)
plt.grid()
plt.show()
Output:
Q2. Write a python program for Training and Test Data in Python Machine Learning.
Source Code:
# Import necessary libraries
import pandas as pd
from sklearn.model_selection import train_test_split
# Sample dataset: You can replace this with your actual data
# Creating a simple dataset
data = {
'Feature1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'Feature2': [11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
'Target': [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
}
Output:
Mean Absolute Error : 0.3
Q4. Write python program to calculate Root Mean Absolute Error for given dataset
Source Code:
import numpy as np
def calculate_rmae(predictions, actuals):
Returns:
float: The RMAE value.
predictions = np.array(predictions)
actuals = np.array(actuals)
if len(predictions) != len(actuals):
raise ValueError("The length of predictions and actuals must be the same.")
absolute_errors = np.abs(predictions - actuals)
mean_absolute_error = np.mean(absolute_errors)
rmae = np.sqrt(mean_absolute_error)
return rmae
predictions = [3.2, 2.8, 4.1, 5.0]
actuals = [3.0, 2.5, 4.0, 5.2]
Output:
Root Mean Absolute Error: 0.4472
Q5. Write python program to calculate Mean Squared Error for given dataset
Source Code:
# import necessary libraries
import pandas as pd
import numpy as np
Output:
Mse: 0.25
Q14. WAP to read data from CSV file and print top and bottom record using head () and tail () from
dataset.
Source Code:
import pandas as pd
2 3 Bob Johnson 45 IT
3 4 Emily Davis 29 HR
Last 5 rows:
6 7 Chris Green 30 IT
9 10 Olivia Lee 33 HR
Q12. WAP in python to plot bar graph for four cricket teams and their highest score in T-20 match.
Use different colour for different team.
Source Code:
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 6))
plt.xlabel('Teams')
plt.ylabel('Highest Score')
plt.show()
Output:
Q7. WAP in python to print sum of ten natural numbers.
Source Code:
total_sum = 0
Output:
percentage =[85,78,89,95,100]
plt.bar(subject,percentage)
plt.xlabel('Subject')
plt.show()
Output:
Q10. WAP in python to Draw a line in a diagram from position (1, 3) to (2, 8) then to (6, 1) and
finally to position (8, 10)
Source Code:
import numpy as np
plt.plot(xpoints, ypoints)
plt.show()
Output:
Q6. WAP to check given year is a leap year.
Source Code:
def CheckLeap(Year):
# Checking if the given year is leap year
if((Year % 400 == 0) or (Year % 100 != 0) and (Year % 4 == 0)):
print("Yes! This Year is a leap Year");
# Else it is not a leap year
else:
print ("This Year is not a leap Year")
# Taking an input year from user
Year = int(input("Enter the number here: "))
# Printing result
CheckLeap(Year)
Output:
Enter the number here: 1700
Yes! This Year is a leap Year