0% found this document useful (0 votes)
6 views13 pages

Exam - QP - Machine Learning With Python

The document outlines the District Comprehensive Assessment for the Machine Learning with Python module in Rwanda, scheduled for March 25, 2025. It includes instructions for candidates, a breakdown of exam sections, and various questions related to Python programming, data analysis, and machine learning concepts. The assessment is structured into three sections, with specific requirements for answering questions and a total of 100 marks available.

Uploaded by

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

Exam - QP - Machine Learning With Python

The document outlines the District Comprehensive Assessment for the Machine Learning with Python module in Rwanda, scheduled for March 25, 2025. It includes instructions for candidates, a breakdown of exam sections, and various questions related to Python programming, data analysis, and machine learning concepts. The assessment is structured into three sections, with specific requirements for answering questions and a total of 100 marks available.

Uploaded by

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

DISTRICT COMPREHENSIVE ASSESSMENT

SECOND TERM
Date: 25/03/2025
REPUBLIC OF RWANDA SCHOOL YEAR: 2024/2025

Module Title: Machine learning with Duration: 3Hrs


Python

Max: 100 Marks


WESTERN PROVINCE
NYABIHU DISTRICT Module code: SPML501
SECTOR: ICT

SUB SECTOR/TRADES: SPE

RTQF LEVEL: 5

Names of Trainer: Louis MUKAMA


Class: A, B, C, D

INSTRUCTIONS TO CANDIDATES:

This Exam paper is composed of four Sections (A, B, C).

Follow the instructions given below, and answer the indicated questions for a total of
100 Marks

1. This is a closed book exam,


a. Attempt ALL Questions from section A.
b. Choose and answer only THREE (3) questions from Section B
c. Choose and answer only ONE (1) question from Section C
2. Use this question paper as your answer-sheet
3. Make the handwriting clear & visible
4. Write your respective names and class on the answer-sheet

Candidate name …………………………………………………………………………………………………


Class………………………………………………………………………………………………………………..

SPE LEVEL 5 – Machine Learning with Python


1
Section A: This section contains SEVENTEEN (17) compulsory questions and carries
50 marks.

01. Give a command to create a virtual environment for a Python project? (2marks)

02. Why is it recommended to configure a separate Python virtual environment for


each project?
(3marks)
A. To prevent dependency conflicts between projects
B. To improve the performance of the Python interpreter
C. To isolate project-specific dependencies
D. To increase the size of the global Python environment

03. What is a key benefit of using a virtual environment for each Python project?
(3marks)

A. It allows projects to use different package versions without conflicts


B. It forces all projects to share the same dependencies
C. It removes the need to install Python packages
D. It eliminates the need for a [Link] file

04. Identify the statement that inaccurately describes the function of Python basic
commands: (3marks)

A. pip freeze command list all packages in a python environment.


B. pip list command list all packages in a python environment.
C. pip freeze > [Link] command creates a file to contain package names.
D. pip freeze –r [Link] command installs packages in [Link].
E. pip install --upgrade -r [Link] command updates all packages listed in
[Link].

SPE LEVEL 5 – Machine Learning with Python


2
05. Interpret the following code snippet before selecting correct statement(s) from the
options below. (3marks)

A. It will print when run


B. It will print when run
C. It will print when run
D. If print(type(result))is changed to print(result), the output will be 68
E. When maintaining the sequence and summing up to 30, the line will be lengthy.
Intentionally, by avoiding loops for the summation, the code will be

06. Provide THREE (3) valid function calls using different argument combinations:
(3marks)

SPE LEVEL 5 – Machine Learning with Python


3
07. Given the following descriptions of database management tasks, identify
corresponding commands used to perform these tasks in a Django project? (3marks)

i. Lists all migrations for each app, showing which have been applied and which
are pending.
ii. Generates new migration files based on changes made to your models.
iii. Applies migrations to the database, updating its schema to reflect the current
state of your models.

08. The following code snippet represents a Python function. What is the output at line
31? (3marks)

09. Interpret the following code snippet before selecting correct statement(s) from the
options below. (3marks)

A. It will print 5.
B. It will print 5 after assuming 0 as initial value for some variables.
C. It will raise a ValueError.
D. It will raise a TypeError.
E. None from above

10. Insert the correct syntax for adding a new column 'NewColumn' that contains a
value of 0 for all rows. (3marks)
df. =0

SPE LEVEL 5 – Machine Learning with Python


4
11. Adapt with below flow of the code to answer related questions

a) What is the output at line 23? ___________ (1mark)


b) What is the output at line 24? ___________ (1mark)
c) What is the output at line 25? ___________ (1mark)

12. Which of the following correctly describes the differences between count(),
value_counts(), and nunique() methods in a Pandas DataFrame? (3marks)

A. count() counts all values, including nulls, while value_counts() and nunique()
ignore nulls.
B. value_counts() returns the frequency of unique values, while count() counts non-
null values and nunique() counts distinct values.
C. nunique() provides the total count of all values, while count() and value_counts()
return only unique values.
D. count(), value_counts(), and nunique() all perform the same operation but on
different data types.

13. In data preprocessing, the process of identifying and correcting errors or


inconsistencies in data to ensure its accuracy and quality is called ______________
(3marks)

SPE LEVEL 5 – Machine Learning with Python


5
14. Below table shows regression evaluation metrics with their corresponding usage:
Metrics Usage

1. Measures the average magnitude of prediction errors in


the same units as the target variable.
A) RMSE (Root Mean Squared Error)
2. Measures how well the model explains the variability of
B) R-squared (R²) the target variable.

C) MAE (Mean Absolute Error) 3. Measures the average absolute difference between
predicted and actual values.
D) MSE (Mean Squared Error)
4. Penalizes larger errors more than MAE by squaring the
differences before averaging.

Match the following regression evaluation metrics with their corresponding usage by
choosing in below options: (3marks)
A. A → 1, B → 2, C → 3, D → 4
B. A → 2, B → 1, C → 4, D → 3
C. A → 3, B → 4, C → 2, D → 1
D. A → 4, B → 3, C → 2, D → 1

15. Which of the following statements best describes the difference between overfitting
and underfitting in machine learning? (3marks)

A. Overfitting occurs when a model is too simple, while underfitting happens when a
model is too complex.
B. Overfitting occurs when a model performs well on training data but poorly on new
data, while underfitting happens when a model performs poorly on both training
and test data.
C. Overfitting and underfitting both result in high accuracy on training and test data.
D. Overfitting occurs when a model ignores training data, while underfitting
memorizes the training data.

16. True or False. The term R2 score refers to a statistical measure that represents the
proportion of variance for a dependent variable that is explained by an independent
variable or variables in a regression model. It ranges from 0 to 1, where 0 indicates
that the model explains none of the variability in the response data and 1 indicates
that the model explains all the variability in the response data. (3marks)

SPE LEVEL 5 – Machine Learning with Python


6
17. To answer related question, analyze the following refrigerator sales dataset that
contains features such as manufacturer, year, energy rating, capacity, status, owner
profession, selling date and price.

Manufacturer Year Energy Rating Capacity Status Price (USD) Selling Date
Samsung 2020 A+ 300L Used 800 2021-06-15
LG 2019 A++ 350L New 900 2022-03-10
Panasonic 2021 A+++ 400L Used 1,200 2023-01-20
Sharp 2022 A 250L New 700 2022-09-05
Samsung 2018 A+ 280L Used 600 2021-11-11
LG 2021 A++ 320L New 1,000 2022-05-25
Panasonic 2020 A 310L Used 1,100 2023-02-15
… … … … … … …
Sharp 2022 A+++ 450L New 950 2022-07-30
Samsung 2021 A++ 275L Used 750 2021-12-01
LG 2022 A+ 360L New 850 2022-08-14
Panasonic 2020 A 290L New 620 2023-03-03
Sharp 2021 A+++ 310L New 1,050 2022-10-10
Samsung 2022 A++ 240L Used 700 2022-11-20
LG 2021 A+ 260L Used 680 2022-02-28

Create a new column ‘season’ in existing dataset classifying each refrigerator's


selling date into its respective season, (Winter[12, 1, 2], Spring[3, 4, 5], Summer[6,
7, 8], and Fall) (3marks)

SPE LEVEL 5 – Machine Learning with Python


7
Section B: This section contains FIVE (5) questions. A candidate is required to choose
and answer only THREE (3) questions. Each question carries 10 marks.

18. Create a flexible Python function that can accept an number of:
a. Positional arguments. (5marks)
b. Keyword arguments. (5marks)

19. Adapt with below flow of the code to answer related questions

A. What is the output at line 9? ___________ (3marks)


B. What is the output at line 10? ___________ (4marks)
C. What is the output at line 11? ___________ (3marks)

SPE LEVEL 5 – Machine Learning with Python


8
20. Consider below given dataset and answer related questions.
Manufacturer Year Body Type Transmission Fuel Type Seats Status Owner Profession Owner Age
Toyota 2020 Sedan Automatic Gasoline 5 Used Teacher 35
Honda 2019 SUV Manual Gasoline 7 New Engineer 40
Ford 2021 Truck Automatic Diesel 2 Used Business Owner 50
Tesla 2022 Sedan Automatic Electric 5 New IT Specialist 30
Chevrolet 2018 SUV Automatic Gasoline 7 Used Nurse 28
BMW 2001 Coupe Automatic Gasoline 4 New Lawyer 45
Mercedes 2020 Sedan Automatic Diesel 5 Used Lawyer 48
Hyundai 2019 Truck Manual Gasoline 2 Used Marketing Manager 22
… … … … … … … … …
Subaru 2022 SUV Automatic Gasoline 7 New Student 34
Nissan 2000 Sedan Automatic Gasoline 5 Used Scientist 705
Hyundai 2022 Sedan Automatic Electric 5 Used Retired 22
Kia 2020 SUV Automatic Gasoline 7 New Artist 29
Volkswagen 2021 Coupe Manual Hybrid 4 New Developer 31
Mazda 2022 Convertible Automatic Gasoline 3 Used Photographer 27
Tesla 1999 Convertible Automatic Diesel 3 New Chef 44
Tesla 2022 Sedan Automatic Diesel 5 New Chef 44

a) If you want to find the standard deviation of owner_age for cars manufactured
after the year 2000, decide what code to use? (5marks)
b) Decide code snippet that adds car_age feature in existing dataset (5marks)

SPE LEVEL 5 – Machine Learning with Python


9
21. A pharmaceutical company, HealthMed Inc., has developed a new drug aimed at
treating hypertension (high blood pressure) and must demonstrate its effectiveness
before market release. The objective of the study is to determine whether the new
drug significantly reduces blood pressure in patients diagnosed with this condition.
To achieve this, HealthMed Inc. conducts a clinical trial involving 10 patients, each
of whom undergoes two measurements of their blood pressure: once before starting
the treatment and again after a prescribed treatment period with the new drug. The
blood pressure measurements (in mmHg) are recorded as it is indicated in below
code snippet.

a. State hypotheses (5marks)


b. Make a decision on this hypothesis test (5marks)

SPE LEVEL 5 – Machine Learning with Python


10
22. In a collaborative effort, two companies have joined forces to enhance their business
outcomes. One company, TechCorp, specializes in software product development,
while the other, MarketSolutions, focuses on marketing strategies. Together, they
launched a joint campaign aimed at promoting the product and driving sales. This
partnership allows both companies to benefit from increased visibility and revenue.
To assess the effectiveness of this collaboration, monthly sales figures for both
companies were collected over six months from one year of partnership.

Monthly Sales Data (in thousands of dollars):


Month TechCorp sales MarketSolutions sales
1 100 30
2 120 40
3 140 50
4 160 60
5 150 55
6 180 70

a. Compute the covariance (8marks)


b. Indicate if the two companies are growing together or not (2marks)

SPE LEVEL 5 – Machine Learning with Python


11
Section C: This section contains TWO (2) questions. A candidate is required to choose
and answer ONLY ONE (1) question. Each question carries 20 marks.

23. Let us assume we have the following actual and predicted values for a classification
model. (P represents Positive outcome where N represents Negative outcome)
Actual class P P P N N P N P N P
Predicted class P P N P N P N N N P

To evaluate the model:


a) Calculate the Accuracy. (5mark)
b) Calculate the Precision. (5mark)
c) Calculate the Recall. (5mark)
d) Calculate the F1 Score. (5mark)

SPE LEVEL 5 – Machine Learning with Python


12
24. Refer to below given hypothetical dataset, that reflects the relationship between
house sizes and their prices, to answer ALL related questions:
Size (m2) Price (rwfs)
800 150,000
1,200 200,000
1,500 250,000
1,800 300,000
2,000 350,000

For a simple linear regression given by model Y= β0+β1X where β0 is an intercept


∑(xi−x̄ )(yi−ȳ )
calculated by 𝑦̄ −β1x̄ , and β1 being the slope calculated by . The ȳ and x̄ are
∑(xi− x̄ )2
means of dependent and independent variables respectively.
Calculate the coefficient of determination (R2) and Root Mean Squared Error (RMSE)
metrics that evaluates the model (20marks)

Model Evaluation Metrics Formulas:


TP+TN
i. Accuracy = TotalPredictions

TP
ii. Precision = (TP+FP)

TP
iii. Recall = (FN+TP)

Precision+Recall
iv. F1 = 2 × (Precision×Recall)

∑ (actual values − predicted values)2


v. coefficient of determination (R 𝑠𝑞𝑢𝑎𝑟𝑒) = 1 − (∑ (actual values−mean of the actual values)2 )

1
vi. RMSE = √n ∑(actual values − predicted values)2

SPE LEVEL 5 – Machine Learning with Python


13

You might also like