Skip to content

scikit-learn

The scikit-learn pack catches train and test leakage, split and group errors, swapped metric arguments, removed scikit-learn 1.9 APIs, duplicate fits, and missing random seeds on files that import sklearn. Rules fire only on names bound to sklearn imports.

Rules Safe fix Unsafe fix Manual fix
46 1 23 22
Rule Severity Fix What it finds
scaler-fit-before-split info none Fit scalers and imputers on training rows only.
prefit-before-cross-validation error none Refit preprocessing inside every cross-validation fold.
fit-on-test error unsafe Fitting on the test rows makes a score on those rows meaningless, and a model fitted this way scored 0.997 AUC on data with no signal.
fit-before-split error none A step that learned from the target on every row before the split lets the test rows choose what the model sees, so the test score is too high.
cross-val-on-fitted-data error none A step that learned from the target on every row before cross-validation lets each fold be scored on rows whose labels chose the features.
tune-on-test error none Picking a setting by its score on the test rows makes the best score too high.
stateful-function-transformer info unsafe A FunctionTransformer that computes statistics of its input scales test rows by test statistics, so a prediction changes with the other rows in the batch.
Rule Severity Fix What it finds
groups-ignored error unsafe The chosen cv ignores groups=, so rows of one group land in both the training and the test folds, and the score is too high.
missing-groups error none A group splitter without groups= raises ValueError.
leave-one-out-score error unsafe With LeaveOneOut each fold tests one row, and scores such as R2 or ROC AUC need more than one row, so every fold scores nan.
manual-cv-loop warning none Hand-rolled cross-validation, walk-forward, and hyperparameter-sweep loops reimplement scikit-learn's evaluation machinery, risk reusing estimator state across folds when clone() is forgotten, and bypass metadata routing, purge gaps, and parallel execution.
manual-param-sweep warning none A loop that builds and fits a model once per hyperparameter value and scores each fit by hand reimplements validation_curve and GridSearchCV.
manual-threshold-loop warning none A loop that scores one decision threshold per pass recomputes the metric for every threshold.
manual-bootstrap-loop info none A loop that draws a bootstrap sample of the rows and refits on it once per pass fits the resampled models one after another.
fit-per-group-loop info none A loop over the groups of a frame that fits one model per group keeps the models in a dictionary and needs its own code to route new rows.
Rule Severity Fix What it finds
auc-from-labels error unsafe A metric that ranks rows by score, such as roc_auc_score or log_loss, gets class labels from predict, which leaves only two values to rank.
make-scorer-loss-direction warning none sklearn.metrics.make_scorer defaults to greater_is_better=True.
metric-arguments-swapped error unsafe Metrics take the true values first and the predictions second, so swapping them gives another number, such as the recall in place of the precision.
score-on-training-rows error none Scoring a model on the rows it was fitted on says nothing about new data, and a decision tree scored 1.00 this way on data with no signal.
tuned-threshold-prefit-refit error none TunedThresholdClassifierCV(..., cv="prefit") raises ValueError: When cv='prefit', refit cannot be True. because refit defaults to True.
unknown-scoring-name error unsafe A scoring text that is not a scorer name raises.
class-weight-balanced-uncalibrated warning none Setting class_weight="balanced", "balanced_subsample", or a custom class-weight mapping shifts predicted probabilities away from the true event prevalence.
Rule Severity Fix What it finds
removed-in-sklearn error unsafe These modules, names and arguments were removed from scikit-learn, so the code raises.
deprecated-in-sklearn warning unsafe These forms warn FutureWarning on scikit-learn 1.9.1 because a later release removes them or changes their default.
removed-metric-api error unsafe These metric names were removed from scikit-learn, so the code raises.
deprecated-metric-api warning safe These metric arguments and names warn on scikit-learn 1.9.1 and go away in a later release.
fit-params-keyword error unsafe fit_params= was removed and raises TypeError on scikit-learn 1.9.
column-transformer-removed error unsafe ColumnTransformer no longer takes force_int_remainder_cols, so the call raises TypeError on scikit-learn 1.9.
Rule Severity Fix What it finds
scaled-target-without-inverse error none Restore predictions to their original units before scoring a transformed target.
metadata-routing error unsafe These forms work only with metadata routing on, or only with it off, so the call raises RuntimeError or ValueError here.
pipeline-fit-params error none Pipeline.fit raises ValueError on a bare sample_weight=, because it takes step parameters as the step name, two underscores and the name.
pipeline-step-form error unsafe Step names with two underscores in a row, and Pipelines built from the wrong kind of argument, raise ValueError at fit.
transformed-target-pair error unsafe TransformedTargetRegressor raises ValueError at fit when it gets func without inverse_func, or both a transformer and functions.
transformed-target-pipeline-weight error none TransformedTargetRegressor.fit(X, y, sample_weight=...) passes sample_weight straight to self.regressor.fit.
unscaled-pipeline-estimator warning none Distance, kernel, neural, and SGD estimators (SVR, SVC, KNeighbors*, MLP*, SGD*, KernelRidge) degrade sharply when input features sit on different scales (on features with scale ratio 1:1000, unscaled SVR had RMSE 2.794 vs 1.153 scaled, and KNeighborsRegressor had 2.850 vs 0.827).
pandas-output-sparse error unsafe OneHotEncoder returns a sparse matrix by default, and pandas output raises ValueError on it.
Rule Severity Fix What it finds
predict-per-row warning unsafe Calling predict once per row checks the input and sets up the model again for every row.
score-after-predict warning unsafe model.score(X, y) predicts X again when you already hold the predictions.
predict-and-predict-proba warning unsafe predict computes the same probabilities as predict_proba and returns the class with the largest one, so calling both does the work twice.
cross-val-score-per-metric warning none Each cross_val_score call fits the model on every fold again to compute one more score.
vectorizer-fit-then-transform warning unsafe fit already builds the matrix of the documents and drops it, so transform reads them a second time.
refit-per-n-estimators warning none Fitting a new forest for each tree count in a loop grows every tree again.
manual-importance-loop warning none A loop that shuffles a column, sets a column to grid values, or drops a feature and then predicts or refits, hand-rolls permutation importance, partial dependence or leave-one-covariate-out importance.
tsne-exact info unsafe TSNE(method="exact") computes the force between every pair of rows, and the default method gave the same quality 4.5 to 16 times faster.
Rule Severity Fix What it finds
random-state-without-shuffle error unsafe KFold uses random_state only when it shuffles, so without shuffle=True the call raises ValueError.
missing-random-state info unsafe Without random_state, a split or a model takes a new seed on every run, so the score changes from run to run.