ARTIFICIAL INTELLIGENCE RECORD – GRADE XII (2025–2026) EX.NO: 1(a) CREATING AND ACCESSING ELEMENTS OF A NUMPY 2D ARRAY USING INDEXING AND SLICING AIM: To write a Python program to generate a 2D array using NumPy and access its elements using forward indexing, backward indexing, and slicing. SOURCE CODE: import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) print("Forward Indexing:", arr[0][1]) print("Backward Indexing:", arr[-1][-2]) print("Slicing:\n", arr[0:2, 1:3]) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 1(b) ELEMENT-WISE ARITHMETIC OPERATIONS ON 2D NUMPY ARRAYS AIM: To write a Python program to perform element-wise addition, subtraction, multiplication, and division on two NumPy arrays. SOURCE CODE: import numpy as np a = np.array([[2, 4], [6, 8]]) b = np.array([[1, 2], [3, 4]]) print("Addition:\n", a + b) print("Subtraction:\n", a - b) print("Multiplication:\n", a * b) print("Division:\n", a / b) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 2 CREATING A PANDAS SERIES USING A DICTIONARY AIM: To create a Pandas Series using a dictionary and access its elements using indexing and slicing. SOURCE CODE: import pandas as pd data = {'a': 10, 'b': 20, 'c': 30, 'd': 40} s = pd.Series(data) print(s) print("Indexing:", s['b']) print("Slicing:\n", s['a':'c']) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 3 CREATING A DATAFRAME FOR EMPLOYEE DETAILS AIM: To create a Pandas DataFrame using a dictionary of lists and display records. SOURCE CODE: import pandas as pd data = { 'Emp_ID': [101,102,103,104,105,106], 'Name': ['A','B','C','D','E','F'], 'Department': ['HR','IT','IT','HR','Finance','IT'], 'Salary': [30000,40000,45000,35000,50000,42000] } df = pd.DataFrame(data) print(df) print(df.head()) print(df.tail(3)) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 4 DATAFRAME USING SERIES FOR HEALTH PARAMETERS AIM: To create a Pandas DataFrame using Series and access rows and columns. SOURCE CODE: import pandas as pd df = pd.DataFrame({ 'RBC': [4.5, 4.8, 5.0], 'WBC': [7000, 7200, 7100], 'Platelets': [250000, 260000, 255000], 'Hemoglobin': [13.5, 14.0, 13.8] }, index=['Patient1','Patient2','Patient3']) print(df['RBC']) print(df.loc[['Patient1','Patient2']]) print(df.loc[['Patient2','Patient3'], ['WBC','Hemoglobin']]) print(df.iloc[0:3, 0:3]) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 5 PLANT GROWTH PROFILE DATAFRAME OPERATIONS AIM: To create a DataFrame and perform column insertion, row addition, and row deletion. SOURCE CODE: import pandas as pd data = { 'Light Intensity': [200,300,250,280], 'CO2 Level': [350,400,380,360], 'Water Volume': [800,900,850,870], 'Growth Rate': [15.2,18.5,16.8,17.1] } df = pd.DataFrame(data, index=['Neem','Rose','Tulsi','Lily']) df['Soil pH'] = [6.5,7.0,6.8,7.2] df.loc['Tulsi'] = [250,380,950,18.4,6.9] df = df.drop('Neem') print(df) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 6 DISPLAYING DATAFRAME ATTRIBUTES AIM: To display various attributes of a Pandas DataFrame. SOURCE CODE: import pandas as pd df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]}) print("Shape:", df.shape) print("Size:", df.size) print("Data Types:\n", df.dtypes) print("Index:", df.index) print("Columns:", df.columns) print("Transpose:\n", df.T) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 7 WRITING AND READING EMPLOYEE DETAILS USING CSV FILE AIM: To store and read employee details using a CSV file. SOURCE CODE: import csv with open('Employee.csv','w',newline='') as f: writer = csv.writer(f) writer.writerow(['Empno','Name','Salary','Department']) writer.writerow([101,'A',30000,'HR']) writer.writerow([102,'B',40000,'IT']) with open('Employee.csv','r') as f: reader = csv.reader(f) for row in reader: print(row) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 8 ANALYSING STUDENT MARKS USING PANDAS AIM: To analyse student marks using statistical functions and handle missing values. SOURCE CODE: import pandas as pd df = pd.read_csv('students.csv') df.fillna(df.mean(numeric_only=True), inplace=True) print("Mean:\n", df.mean()) print("Median:\n", df.median()) print("Mode:\n", df.mode()) print("Standard Deviation:\n", df.std()) RESULT: Thus, the above Python program has been executed and the output is verified successfully. EX.NO: 9 EVALUATING STUDENT EXAM RESULT PREDICTION MODEL AIM: To evaluate a classification model using accuracy, precision, recall, and F1-score. SOURCE CODE: from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score y_true = [1,0,1,1,0] y_pred = [1,0,1,0,0] print("Accuracy:", accuracy_score(y_true,y_pred)) print("Precision:", precision_score(y_true,y_pred)) print("Recall:", recall_score(y_true,y_pred)) print("F1 Score:", f1_score(y_true,y_pred)) RESULT: Thus, the above Python program has been executed and the output is verified successfully.