0% found this document useful (0 votes)
9 views7 pages

AI Python Short Answers Updated

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

AI Python Short Answers Updated

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AICTE QIP PG Certification Program

AI and its Application , IIIT Lucknow


Submitted by- Avinash Kumar, R.NO. 08 , ID(QIPFPG25000040)

Section A: Very Short Answer Type Questions


(Total: 15 Marks)
Answer all questions. Each answer should not exceed 40 words
Q.1. Name two popular Python Integrated Development Environments (IDEs).

Answer: PyCharm and Jupyter Notebook.

Q.2. What is the key difference between a ‘list’ and a ‘tuple’?

Answer: List is mutable (can change), Tuple is immutable (cannot change).

Q.3. Which loop is preferable when iterations are known: ‘for’ or ‘while’?

Answer: The 'for' loop is preferable.

Q.4. What does the ‘open()’ function return in read mode (‘r’)?

Answer: It returns a file object.

Q.5. What is the output of the string slice ‘Hello[1:4]’?

Answer: It gives 'ell'.

Q.6. Which Python library is essential for data manipulation?

Answer: Pandas.

Q.7. Define an ‘Agent’ in Artificial Intelligence.

Answer: An agent is an entity that perceives its environment and acts on it.

Q.8. What does the acronym PEAS stand for?

Answer: Performance, Environment, Actuators, Sensors.

Q.9. Differentiate Supervised and Unsupervised Learning in one point.

Answer: Supervised uses labeled data, Unsupervised uses unlabeled data.

Q.10. Which search algorithm uses path cost and a heuristic?

Answer: A* Search Algorithm.


Q.11. Is Linear Regression for classification or regression?

Answer: It is used for regression.

Q.12. State the primary objective of K-means clustering.

Answer: To group data into K clusters based on similarity.

Q.13. Name the technique for reducing dataset variables.

Answer: Dimensionality Reduction (e.g., PCA).

Q.14. What is the common learning rule for training ANNs?

Answer: Backpropagation.

Q.15. Which NN is best for image processing?

Answer: Convolutional Neural Network (CNN).

Section B: Short Answer Type Questions

Q.16. Differentiate between actual and formal arguments in a Python function with
a code example.

Answer: In Python, actual arguments are the values passed to a function when it is called,
whereas formal arguments are the variables defined in the function definition that receive
those values.

Example:
def add(a, b): # 'a' and 'b' are formal arguments
return a + b

result = add(5, 10) # 5 and 10 are actual arguments

Here, 5 and 10 are actual arguments, and 'a' and 'b' are formal arguments.

Q.17. Explain the use of ‘os’ and ‘sys’ modules. Write code to list files in a directory.

Answer: The 'os' module provides functions to interact with the operating system like file
handling, directory management, etc. The 'sys' module provides access to system-specific
parameters and functions, such as command line arguments and Python interpreter
controls.

Example code to list files in a directory: import os


files = os.listdir('.')
print(files)

Q.19. Describe Boolean logic and write the truth table for the ‘AND’ operator.

Answer: Boolean logic is a form of algebra in which all values are either True or False. It
forms the basis of logic gates in computing. The AND operator returns True only if both
operands are True.

Truth Table (AND):


A B A AND B
0 0 0
0 1 0
1 0 0
1 1 1

Q.21. (10 Marks)

(a)
A Python dictionary is a built-in data structure that stores data in the form of key-value
pairs. It allows quick retrieval of values using unique keys. Dictionaries are unordered,
mutable, and indexed by keys, whereas lists are ordered collections accessed by
numerical indices.

Difference:
• List: Ordered, indexed numerically, allows duplicates.

• Dictionary: Unordered, indexed by unique keys, stores mappings.

Example: A student record can be stored as follows:

student = {
'Name': 'Alice',
'Roll No': 101,
'Class': '10th',
'Marks': 89
}

(b)
Program to read a text file, count word frequency, and write results to a CSV file. This is
useful in Natural Language Processing (NLP), for example, analyzing the frequency of
words in a document.
import csv
from collections import Counter

with open('input.txt', 'r') as f:


words = f.read().split()

freq = Counter(words)

with open('word_count.csv', 'w', newline='') as f:


writer = csv.writer(f)
writer.writerow(['Word', 'Frequency'])
for word, count in freq.items():
writer.writerow([word, count])

Fig: Example Word Frequency Visualization

Q.22. (10 Marks)

(a)
The K-Nearest Neighbors (KNN) algorithm is a supervised learning technique used for
both classification and regression. It predicts the class of a data point by looking at the 'K'
closest labeled points in the feature space. Distance is usually calculated using Euclidean,
Manhattan, or Minkowski distance.

Effect of 'K':

• Small K (e.g., K=1): Model becomes very sensitive to noise (overfitting).


• Large K: Model becomes smoother and less sensitive to noise but may underfit.
Choosing the right K is crucial and often done using cross-validation.
(b)
The A* search algorithm is a graph traversal and pathfinding algorithm widely used in AI
for games, robotics, and route planning. It uses a cost function:
f(n) = g(n) + h(n)
where:
• g(n): Cost from start node to current node
• h(n): Heuristic (estimated cost from current node to goal)

Why complete? A* will always find a solution if one exists.


Why optimal? If the heuristic h(n) is admissible (never overestimates), then A*
guarantees the shortest/least-cost path.

Example: In a grid maze, A* can find the shortest path using Manhattan distance as
heuristic.

Section D: Application & Case Study Based Questions

Q.24. (25 Marks) The Data Analyst


(a) Python code using Pandas:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('sales_data.csv')
print(df.info())
print(df.describe())

total_sales = df.groupby('Product Category')['Sales Amount'].sum()


west_sales = df[(df['Region']=='West') & (df['Sales Amount']>1000)]

print(total_sales)
print(west_sales)

(b) Visualizations: A bar chart and pie chart help interpret data trends.

Findings: The bar chart shows which region has the highest sales (West). The pie chart
reveals category contribution—Electronics dominates, followed by Groceries and
Clothing.

Q.25. (25 Marks) The Machine Learning Engineer


(a) Choice of algorithms:

For predicting loan default, I choose:


• KNN: Works well for smaller datasets and is easy to interpret.
• Decision Tree: Handles mixed data types (categorical/numerical) and provides
interpretable rules.

(b) Concept explanation:

Decision Tree works by splitting the dataset into subsets based on feature values. It uses
metrics like Gini Index or Information Gain to decide the best splits. For example, 'credit
score' may be the root node, splitting applicants into high vs low risk.

(c) Evaluation measures:

• Precision: Accuracy of positive predictions (important to avoid false defaults).


• Recall: Ability to capture actual defaulters (important to minimize bank losses).
• F1-Score: Balance between precision and recall.
Accuracy alone is insufficient because if most applicants do not default, a model
predicting 'No Default' always would give high accuracy but be useless.

• These anomalies can be flagged and removed.


Alternatively, clustering (e.g., K-Means) can group similar fruits; rotten ones appear as
outliers.

You might also like