ABW505 Python & Predictive Analytics Final Exam: Ultimate Revision Guide
3 min read
0
| 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:
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.
x = 0
for i in range(5):
if i == 2:
continue
if i == 4:
break
x += i
print(x)Result: 4
data = (10, 20, 30, 40, 50)
a, *b, c = dataKey idea: *b collects the middle items into a list.
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] = 1import pandas as pd
df = pd.read_csv("data.csv")
print(df.head())
print(df.tail())Key ops: head(), tail(), info(), describe(), groupby().