Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Scikit learn Scikit learn Exceptions

From Leeroopedia
Revision as of 16:34, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Scikit_learn_Scikit_learn_Exceptions.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Machine Learning, Error Handling
Last Updated 2026-02-08 15:00 GMT

Overview

Concrete tool for providing custom warnings and error classes used across scikit-learn.

Description

The sklearn.exceptions module defines custom exception and warning classes used throughout scikit-learn. Key classes include NotFittedError (raised when an estimator is used before fitting), ConvergenceWarning (for convergence issues), DataConversionWarning, FitFailedWarning, UndefinedMetricWarning, and UnsetMetadataPassedError for metadata routing errors.

Usage

Use these exception and warning classes when you need to handle scikit-learn-specific errors, such as catching NotFittedError to check if an estimator has been fitted, or filtering specific warnings during model training and evaluation.

Code Reference

Source Location

Signature

class NotFittedError(ValueError, AttributeError):
class ConvergenceWarning(UserWarning):
class DataConversionWarning(UserWarning):
class DataDimensionalityWarning(UserWarning):
class EfficiencyWarning(UserWarning):
class FitFailedWarning(RuntimeWarning):
class UndefinedMetricWarning(UserWarning):
class UnsetMetadataPassedError(ValueError):
    def __init__(self, *, message, unrequested_params, routed_params):

Import

from sklearn.exceptions import NotFittedError, ConvergenceWarning

I/O Contract

Inputs

Name Type Required Description
message str Yes The error or warning message (for UnsetMetadataPassedError)
unrequested_params dict Yes Parameters provided but not requested (for UnsetMetadataPassedError)
routed_params dict Yes Dictionary of routed parameters (for UnsetMetadataPassedError)

Outputs

Name Type Description
exception Exception Raised exception to be caught by the caller

Usage Examples

Basic Usage

from sklearn.svm import LinearSVC
from sklearn.exceptions import NotFittedError

try:
    LinearSVC().predict([[1, 2], [2, 3]])
except NotFittedError as e:
    print("Estimator not fitted:", e)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment