Practical Sample Questions:
Q1: You are working as a data scientist for a real estate company. They want to create a basic
house price prediction model. The model will use three inputs:
Size of the house (in 1000 sq. ft.)
Number of rooms
Distance from city center (in km)
Write a Python program to compute the net input and output using a linear activation function
(output = input). Use X=[1.2,3,5], weights=[50,10,-5], and bias=20
SOLUTION:
CODE:
X = [1.2, 3, 5]
weights = [50, 10, -5]
bias = 20
net_input = (X[0]*weights[0])+ (X[1]*weights[1])+ (X[2]*weights[2])+bias
output = net_input
print("Net Input:", net_input)
print("Predict House Price", output)
Q2: Case Study: A stock trading bot uses a signal score to make trading decisions:
If the score is positive or zero, it buys the stock.
If the score is negative, it sells the stock.
This can be implemented using a bipolar step activation function. Task:
Write a program to compute the trading decision for a score of -0.3. Display “Buy” or “Sell.”
SOLUTION:
Bipolar Step Rule:
If score ≥ 0 → Buy
If score < 0 → Sell
CODE:
score = -0.3
if score >=0:
decision = "Buy"
else:
decision = "Sell"
print("Trading Decision",decision)
Q3: Case Study: A hospital’s AI system predicts the probability of a patient having a disease based
on a numerical test score. The logistic sigmoid function is used to map the output between 0 and
1.
Task: Write a Python program to calculate the disease probability for a patient with a test score of
0.8. Print the probability rounded to 2 decimal places
SOLUTION:
CODE:
import math
test_score = 0.8
probability = 1 / (1 + [Link](-test_score))
print("Disease Probability:", round(probability, 2))
EXAMPLE QUESTIONS EXTRA:
Q4: Predict Student Performance (Linear Activation)
A university wants to predict a student's performance score using three inputs:
Study Hours per day
Attendance percentage
Sleep hours per day
The formula is linear:
output=(X1⋅W1)+(X2⋅W2)+(X3⋅W3)+bias
Task:
Write a Python program to calculate the student's performance score using:
X = [6, 85, 7], weights = [5, 0.8, -2], and bias = 10.
SOLUTION:
CODE:
X = [6,85,7]
weights = [5,0.8, -2]
bias = 10
int_input = (X[0]*weights[0])+(X[1]*weights[1])+(X[2]*weights[2])+bias
output = int_input
print("Int_Input",int_input)
print("Predection of Student Performance", output)
Q5: Spam Detection (Binary Step Activation Function)
A simple spam detection system uses a score to classify a message:
If score ≥ 0 → Spam
If score < 0 → Not Spam
Task:
Write a Python program that classifies a message with a score of 2.5.
SOLUTION:
CODE:
span_detec_score = 2.5
if span_detec_score >= 0:
detection = "SPAM"
else:
detection = "NOT SPAM"
print("Spam Detection Score:", detection)
Q6: Loan Approval Prediction (Sigmoid Activation Function)
A bank uses logistic regression to predict whether a loan should be approved or not.
The test score for a loan applicant is -1.2.
Task:
Write a Python program to calculate the probability of loan approval using the sigmoid function.
Print the output rounded to 3 decimal places.
SOLUTION:
CODE:
import math
test_score = -1.2
probability = 1 / (1 + [Link](-test_score)) # Sigmoid function
print("Disease Probability:", round(probability, 2))