EXIN BCS ML Award study materials
EXIN BCS ML Award study resources

EXIN BCS ML Award: Programming in Machine Learning

EXIN BCS ML Award · Work through your exam, one topic at a time.

All guide sections

Programming in Machine Learning

The Programming in Machine Learning domain tests your ability to read and write the small amount of Python that underpins practical ML: data handling with pandas and NumPy, the scikit-learn estimator API, train/test splitting, preprocessing, and reproducible experiment code. Expect questions that show a short script and ask what it outputs or what is wrong with it.

Core rules

  • Python data structures: lists preserve order; dictionaries map keys to values; functions group reusable logic; imports load libraries. NumPy arrays support vectorized arithmetic and are faster than Python loops for numeric work.
  • pandas: a DataFrame is a table with named columns; a Series is one column. Use head(), info(), and describe() to inspect data, isna().sum() to find missing values, and fillna() or dropna() to handle them.
  • scikit-learn uses a consistent API: instantiate an estimator, call fit(X, y) to train, predict(X) to output, transform(X) to preprocess, and score(X, y) for the default metric. Preprocessing steps such as scaling must be fitted on training data only.
  • Use train_test_split with a fixed random_state for reproducibility and stratify=y for classification so class proportions are preserved. Wrap preprocessing and the model in a Pipeline so cross-validation refits the scaler inside each fold, preventing data leakage.
  • Reproducibility also requires pinned library versions, version control, and clean script execution order; notebook cells run out of order can hide bugs.

Worked example

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.linear_model import LogisticRegression
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)
pipe = make_pipeline(StandardScaler(), LogisticRegression())
pipe.fit(X_tr, y_tr)
print(pipe.score(X_te, y_te))

Reasoning: stratify keeps the minority class proportion in both splits; random_state makes the split repeatable; the pipeline fits the scaler on X_tr only, then applies the same means and standard deviations to X_te; score returns mean accuracy for a classifier. If scaling had been done on all of X before splitting, test information would leak into training and the estimate would be optimistic.

Traps

Calling fit_transform on the full dataset before splitting is the classic leakage error. Calling fit on test data is also wrong. Confusing transform (apply learned parameters) with fit_transform (learn and apply) costs marks. Omitting random_state makes results irreproducible. Using accuracy on imbalanced classes hides failure.