CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →
CBSE Class 12 · Artificial Intelligence · Practical

CBSE Class 12 Artificial Intelligence Practical File, Python Programs with Output

The CBSE Class 12 Artificial Intelligence (843) practical covers data handling, model evaluation and the Capstone Project. The programs below were run before publishing, so the confusion matrix, the accuracy and the precision figures you see are the numbers the code actually produced.

1. Read a CSV into pandas and describe it

Program
import pandas as pd
pd.DataFrame({"hours": [1, 2, 3, 4, 5],
              "score": [35, 48, 55, 68, 79]}).to_csv("study.csv", index=False)
df = pd.read_csv("study.csv")
print(df)
print()
print(df.describe())
Output
   hours  score
0      1     35
1      2     48
2      3     55
3      4     68
4      5     79

          hours      score
count  5.000000   5.000000
mean   3.000000  57.000000
std    1.581139  17.131842
min    1.000000  35.000000
25%    2.000000  48.000000
50%    3.000000  55.000000
75%    4.000000  68.000000
max    5.000000  79.000000

2. Find and handle missing values

Program
import pandas as pd
import numpy as np
df = pd.DataFrame({"name": ["Aarav", "Diya", "Ishaan"],
                   "marks": [78, np.nan, 66]})
print("Missing values per column:")
print(df.isnull().sum())
df["marks"] = df["marks"].fillna(df["marks"].mean())
print()
print(df)
Output
Missing values per column:
name     0
marks    1
dtype: int64

     name  marks
0   Aarav   78.0
1    Diya   72.0
2  Ishaan   66.0

3. Split data into training and testing sets

Program
import pandas as pd
df = pd.DataFrame({"hours": [1, 2, 3, 4, 5, 6, 7, 8],
                   "score": [35, 48, 55, 68, 72, 79, 85, 91]})
train = df.iloc[:6]
test = df.iloc[6:]
print("Training rows:", len(train), " Testing rows:", len(test))
print("Test set:")
print(test)
Output
Training rows: 6  Testing rows: 2
Test set:
   hours  score
6      7     85
7      8     91

4. Build a confusion matrix by hand and read it

Program
actual    = [1, 0, 1, 1, 0, 1, 0, 0]
predicted = [1, 0, 1, 0, 0, 1, 1, 0]
tp = sum(1 for a, p in zip(actual, predicted) if a == 1 and p == 1)
tn = sum(1 for a, p in zip(actual, predicted) if a == 0 and p == 0)
fp = sum(1 for a, p in zip(actual, predicted) if a == 0 and p == 1)
fn = sum(1 for a, p in zip(actual, predicted) if a == 1 and p == 0)
print("True Positive :", tp)
print("True Negative :", tn)
print("False Positive:", fp)
print("False Negative:", fn)
print("Accuracy      :", round((tp + tn) / len(actual) * 100, 2), "%")
Output
True Positive : 3
True Negative : 3
False Positive: 1
False Negative: 1
Accuracy      : 75.0 %

5. Calculate precision, recall and F1 score

Program
tp, fp, fn = 3, 1, 1
precision = tp / (tp + fp)
recall = tp / (tp + fn)
f1 = 2 * precision * recall / (precision + recall)
print("Precision:", round(precision, 2))
print("Recall   :", round(recall, 2))
print("F1 Score :", round(f1, 2))
Output
Precision: 0.75
Recall   : 0.75
F1 Score : 0.75

6. Count word frequency for a simple NLP bag of words

Program
text = "an ai model learns from data and a model improves with more data"
bag = {}
for word in text.split():
    bag[word] = bag.get(word, 0) + 1
for word, count in sorted(bag.items(), key=lambda x: (-x[1], x[0]))[:5]:
    print(word, ":", count)
Output
data : 2
model : 2
a : 1
ai : 1
an : 1

7. Normalise a column between 0 and 1

Program
import pandas as pd
df = pd.DataFrame({"marks": [35, 48, 55, 68, 79]})
low, high = df["marks"].min(), df["marks"].max()
df["normalised"] = ((df["marks"] - low) / (high - low)).round(3)
print(df)
Output
   marks  normalised
0     35       0.000
1     48       0.295
2     55       0.455
3     68       0.750
4     79       1.000

8. Plot a bar chart and save it as an image

Program
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
subjects = ["CS", "IP", "AI"]
students = [42, 31, 27]
plt.bar(subjects, students)
plt.title("Students per subject")
plt.savefig("subjects.png")
print("Chart saved as subjects.png")
print("Bars:", dict(zip(subjects, students)))
Output
Chart saved as subjects.png
Bars: {'CS': 42, 'IP': 31, 'AI': 27}

Get the full practical-file pack, free

Every program, the exact practical-file format your school expects, and the viva questions that come up most — sent on WhatsApp.

Get it on WhatsApp Book a free demo class

Related: Class 12 AI syllabus · Class 10 AI syllabus · Try the code in the Python Playground

Stuck on your practical file or the viva?

Kajal Ma'am has been teaching these practicals since 2004. See a real class first — no payment, no commitment.

Book a free demo class

Every program on this page was executed and its output captured from the run. Curated by Kajal Ma'am (MCA), teaching computer subjects since 2004.

Frequently asked questions

What does the Class 12 AI practical file need?

CBSE Artificial Intelligence (843) expects a practical file of Python programs on data handling and model evaluation, a written exam based on the file, a viva, and the Capstone Project. The practical side carries 50 of the 100 marks.

Do I need scikit-learn for these programs?

Not for the ones on this page. They use pandas, numpy and plain Python so they run on any school computer, and they show the maths of accuracy, precision and recall rather than hiding it behind a library call.

Can you help with the Capstone Project?

Yes. Ask on WhatsApp and Kajal Ma'am's team will help you choose a problem, prepare the AI Project Cycle write-up, and get the file ready for the viva.

{ }

Frequently asked questions

How many programs are needed in the CBSE Class 12 CS practical file?+
As per CBSE, the report file should contain a minimum of 15 Python programs and 5 sets of SQL queries. The practical is 30 marks (lab test 12, report file 7, project 8, viva 3).
Are these programs part of the CBSE syllabus?+
Yes, these are standard CBSE Class 12 Computer Science (083) practical concepts: stacks, file handling, recursion, searching, dictionaries and Python-MySQL connectivity. Every program here has been run and its output verified.
Can I get the full practical file and viva questions?+
Yes, request the full pack (15+ programs, the CBSE practical-file format and likely viva questions) on WhatsApp, free. Kajal Ma'am's team can also guide you through your own file.

Want to ace your boards?

See a real class before you decide. No pressure, no payment.

Book Free Demo on WhatsApp

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →