KatInterview

Maximizing a Fixed Linear SVM Through Better Features and Validation

Machine LearningModel answer
HardModel answerMachine Learninglinear-svmfeature-engineeringcross-validation

Last updated

Raise held-out accuracy of a fixed LinearSVC classifier using preprocessing, feature engineering and leak-free tuning, then justify the improvement credibly without touching the test set.

You receive a labeled tabular dataset that may contain numeric, categorical and free-text columns. The estimator is fixed: the final classifier must be scikit-learn's LinearSVC. A hidden test set will be used to check whether your accuracy exceeds a baseline you cannot see.

You may change only preprocessing, feature construction and training hyperparameters. Swapping in another estimator is not allowed.

Write a model answer covering the following:

  1. Interface. Implement train(X_train, y_train), which fits the whole pipeline, and test(X_test), which returns predictions for unseen rows. Explain how accuracy would be reported when labels are available.
  2. Data-centric improvements. Name the changes you would try (scaling, outlier handling, text vectorization, categorical encoding, feature selection or reduction, interactions, deduplication and label-noise cleanup, imbalance handling) and explain why each helps a linear large-margin model. State whether data changes or model changes should move accuracy more, and how you would show it.
  3. Mixed column types. Describe one pipeline that sends numeric, categorical and text columns through the right transformations.
  4. Tuning without peeking. Describe a validation scheme that lets you tune and decide you have beaten the baseline using only training data, then freeze the configuration. Explain how you prevent leakage.
  5. Reproducibility and measurement. Explain how you would make the work repeatable (seeds, saved artifacts, experiment log) and how you would estimate generalization (CV mean and spread, confidence intervals, robustness checks).

Include code, complexity or cost considerations where relevant, and the common mistakes to avoid.

Hints

Hint 1

Think about what LinearSVC optimizes (hinge loss plus an L2 penalty on the weights). What does that imply about feature scale, non-linear structure, and outliers?

Hint 2

Put every transformation inside a single Pipeline/ColumnTransformer so that imputers, scalers and vocabularies are fit only on the training part of each fold. Remove exact duplicates before splitting.

Hint 3

Use stratified k-fold with a grid search for tuning, and nested CV to get an unbiased estimate of the whole procedure. Claim a win only if the lower end of the estimate clears the baseline, then freeze the configuration and refit on all training data.