Change8

scikit-learn

Data & ML

scikit-learn: machine learning in Python

Latest: 1.9.07 releases7 common errorsView on GitHub

Release History

View all versions →

Common Errors

InvalidParameterError3 reports

InvalidParameterError in scikit-learn usually arises from passing incorrect or unsupported parameter values to a function or class constructor. To fix it, carefully review the documentation of the function/class, ensuring all parameter names are spelled correctly and the provided values match the expected data type and allowed range/options; double-check for deprecated or renamed parameters.

NotImplementedError2 reports

The `NotImplementedError` in scikit-learn arises when a method or functionality is declared (e.g., in an abstract base class or for a specific configuration) but lacks a concrete implementation for a specific use case. To fix this, implement the missing functionality by providing the necessary code within the relevant class method, ensuring it handles the specific input and produces the expected output according to the method's defined purpose. If the functionality truly cannot be implemented, consider raising `NotImplementedError` only when the specific problematic conditions are met, and clearly document why it's not supported and suggest alternative approaches or inputs.

ValueError2 reports

ValueError in scikit-learn usually arises from providing incorrect data types to a model, like strings when expecting numerical values, or incompatible shapes/structures. Address this by ensuring your input data conforms to the expected data type and shape specified in the documentation, often by converting strings to numbers using LabelEncoder or OneHotEncoder or reshaping arrays. Check the specific model's input requirements and modify your data accordingly to resolve data type and shape mismatches.

NotFittedError2 reports

The "NotFittedError" in scikit-learn usually arises when you try to use a transformer or estimator (like a pipeline, scaler, or model) before calling its `fit` method to train it on data. To fix this, ensure you call the `fit` method on your transformer/estimator object, passing it the appropriate training data (X, and optionally y for supervised models) before using it for transformation or prediction. For pipelines, fitting the pipeline fits all its constituent steps.

NotImplementError1 report

A `NotImplementedError` in scikit-learn typically arises when a requested functionality, like using a specific solver with Array API dispatch, hasn't been fully implemented for a particular class or configuration. To fix this, either use a supported solver or ensure the necessary Array API support is implemented for the problematic solver and class, potentially requiring contributing code to scikit-learn itself and adding an explicit implementation for that path. If contributing, implement the missing functionality following the existing structure for similar features and including related tests.

AttributeError1 report

This "AttributeError" in scikit-learn often arises when a method like 'predict_proba' is called on an estimator that doesn't implement it or when using MultiOutputClassifier/Regressor with base estimators lacking the requested method. Ensure the base estimator supports the called method (e.g., use a classifier with `predict_proba` if needed) or avoid calling methods not available in the base estimator for multi-output scenarios, potentially requiring custom prediction logic. For cross_val_predict specifically, if your estimator doesn't have the requested method (e.g. predict_proba), change the method to "predict" instead.

Related Data & ML Packages

Subscribe to Updates

Get notified when new versions are released

RSS Feed