Loading…
Final Exam Review
ABW505 Python & Predictive Analytics Final Exam: Ultimate Revision Guide
3 min read
238
🎓 Official Exam Structure
| Q | Points | Type | Coverage |
|---|---|---|---|
| Q1 | 20 | Type 2 | Python basics: objects, variables, IO, list/tuple, functions, loops, conditions |
| Q2 | 30 | Type 3 | Choose 3 of 5: decisions, repetition, boolean logic, list/tuple, functions |
| Q3 | 25 | Type 1/3 | Pandas, preprocessing, encoders, SVM, Random Forest |
| Q4 | 25 | Type 1/3/4 | Naive Bayes, decision tree, preprocessing (calculator allowed) |
Type definitions:
- Type 1: theory
- Type 2: read code, compute output
- Type 3: read output, write code
- Type 4: calculations
🟢 Part 1: Python Core & Logic (Q1 & Q2)
Q1.1 Mutable Default Parameter Trap
def extend_list(val, list=[]):
list.append(val)
return list
list1 = extend_list(10)
list2 = extend_list(123, [])
list3 = extend_list('a')Key idea: default mutable args are evaluated once at function definition. The default list is reused across calls.
Q1.2 Loop Control
x = 0
for i in range(5):
if i == 2:
continue
if i == 4:
break
x += i
print(x)Result: 4
Q1.3 Tuple Unpacking
data = (10, 20, 30, 40, 50)
a, *b, c = dataKey idea: *b collects the middle items into a list.
Q1.5 NumPy Matrix Tasks
- Create a 4×4 matrix from 1–16
- Create a length-10 zero vector, set the 7th value to 10
- Create an 8×8 checkerboard
import numpy as np
matrix_4x4 = np.arange(1, 17).reshape(4, 4)
null_vector = np.zeros(10)
null_vector[6] = 10
checkerboard = np.zeros((8, 8), dtype=int)
checkerboard[1::2, ::2] = 1
checkerboard[::2, 1::2] = 1🟠 Part 2: Data Science Foundations (Q3 & Q4)
Pandas Essentials
import pandas as pd
df = pd.read_csv("data.csv")
print(df.head())
print(df.tail())Key ops: head(), tail(), info(), describe(), groupby().
Preprocessing & Encoding
- ML models need numeric input
- Use one-hot encoding for categorical variables
- Split data into train/test before evaluation
KNN Quick Rules
- Small dataset, low dimensional → KNN works well
- Larger K → lower variance, higher bias
- Always normalize/scale features
Naive Bayes & Decision Tree
- Naive Bayes: fast, good for text; assumes independence
- Decision Tree: interpretable, but can overfit
- Random Forest: improves tree stability via bagging
✅ Final Tips
- For Type 2 questions: show step-by-step execution
- For Type 3 questions: return clean, minimal code
- Always handle edge cases (empty list, invalid input)
- Use midpoint method in any percentage change calculation
#Final Exam#ABW505#Python#NumPy#KNN#Machine Learning#Question Bank