Train LinearSVC to beat baseline accuracy
Task: Train and Evaluate a LinearSVC to Beat a Baseline
Context
You are provided with a binary or multi-class classification dataset, split into distinct training and hidden test sets. An accuracy baseline (e.g., from a previous model or a heuristic) is also supplied. Your primary objective is to implement train() and test() functions that achieve the following:
- Train a
LinearSVCmodel that surpasses the given baseline accuracy on the hidden test set. - Employ sound validation techniques, such as cross-validation, strictly without any access or 'peeking' at the hidden test set during development or tuning.
- Experiment with both model-level and data-level adjustments. Document your attempts and identify which changes contributed to improved performance, with a particular emphasis on the effectiveness of data-side tweaks.
Assume that input features may consist of numeric data (which can be dense or sparse) and/or text data. Your implementation should include a flexible preprocessing pipeline or parameterization within your functions to appropriately handle these diverse input types.
Requirements
- Implement a
train()function that:- Accepts training data
(X_train, y_train)and abaseline_accuracy. - Constructs a
scikit-learn Pipelineincorporating necessary preprocessing steps and aLinearSVCclassifier. - Tunes key hyperparameters for the
LinearSVCvia cross-validation. This function should report the cross-validation scores and the best-found parameters. - Returns the fitted pipeline and relevant training diagnostics (e.g., cross-validation accuracy).
- Accepts training data
- Implement a
test()function that:- Takes the previously fitted pipeline and the test data
(X_test, y_test). - Returns the calculated test accuracy and a brief report confirming whether the baseline was successfully beaten.
- Takes the previously fitted pipeline and the test data
- Experiments and Reporting:
- Explore model-level adjustments (e.g.,
Cregularization parameter,class_weighthandling, feature selection techniques). - Explore data-side adjustments (e.g., feature scaling, TF–IDF transformation for text, stop-word removal, data deduplication).
- Provide a concise summary detailing which changes led to accuracy improvements. Specifically highlight instances where data-side tweaks proved particularly effective.
- Explore model-level adjustments (e.g.,
Constraints
- The classifier used must be
sklearn.svm.LinearSVC. - Accuracy is the sole evaluation metric.
- Strictly avoid data leakage: all preprocessing steps must be fitted exclusively on training folds.
- Cross-validation should be performed solely on the training data; the hidden test set is to be used only once, at the very end, for final evaluation.
AI interview prep
Core dilemma
Achieving a specific performance target (beating a baseline) with a constrained model (`LinearSVC`) by intelligently leveraging data preprocessing and hyperparameter tuning, all while rigorously adhering to sound ML validation practices to prevent data leakage and overfitting.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Train LinearSVC to beat baseline accuracy
Task: Train and Evaluate a LinearSVC to Beat a Baseline
Context
You are provided with a binary or multi-class classification dataset, split into distinct training and hidden test sets. An accuracy baseline (e.g., from a previous model or a heuristic) is also supplied. Your primary objective is to implement train() and test() functions that achieve the following:
- Train a
LinearSVCmodel that surpasses the given baseline accuracy on the hidden test set. - Employ sound validation techniques, such as cross-validation, strictly without any access or 'peeking' at the hidden test set during development or tuning.
- Experiment with both model-level and data-level adjustments. Document your attempts and identify which changes contributed to improved performance, with a particular emphasis on the effectiveness of data-side tweaks.
Assume that input features may consist of numeric data (which can be dense or sparse) and/or text data. Your implementation should include a flexible preprocessing pipeline or parameterization within your functions to appropriately handle these diverse input types.
Requirements
- Implement a
train()function that:- Accepts training data
(X_train, y_train)and abaseline_accuracy. - Constructs a
scikit-learn Pipelineincorporating necessary preprocessing steps and aLinearSVCclassifier. - Tunes key hyperparameters for the
LinearSVCvia cross-validation. This function should report the cross-validation scores and the best-found parameters. - Returns the fitted pipeline and relevant training diagnostics (e.g., cross-validation accuracy).
- Accepts training data
- Implement a
test()function that:- Takes the previously fitted pipeline and the test data
(X_test, y_test). - Returns the calculated test accuracy and a brief report confirming whether the baseline was successfully beaten.
- Takes the previously fitted pipeline and the test data
- Experiments and Reporting:
- Explore model-level adjustments (e.g.,
Cregularization parameter,class_weighthandling, feature selection techniques). - Explore data-side adjustments (e.g., feature scaling, TF–IDF transformation for text, stop-word removal, data deduplication).
- Provide a concise summary detailing which changes led to accuracy improvements. Specifically highlight instances where data-side tweaks proved particularly effective.
- Explore model-level adjustments (e.g.,
Constraints
- The classifier used must be
sklearn.svm.LinearSVC. - Accuracy is the sole evaluation metric.
- Strictly avoid data leakage: all preprocessing steps must be fitted exclusively on training folds.
- Cross-validation should be performed solely on the training data; the hidden test set is to be used only once, at the very end, for final evaluation.