machinelens.analyzer package#

Submodules#

machinelens.analyzer.analyzer_controller module#

Processing layer — the calculation engine for MachineLens.

ModelAnalyzer takes a ModelInterface, routes it to the correct specialized analyzer, and returns a fully populated DiagnosticResults instance.

class machinelens.analyzer.analyzer_controller.ModelAnalyzer(interface: ModelInterface)[source]#

Bases: object

Calculation engine that produces DiagnosticResults.

This analyzer automatically delegates calculations to the specialized RegressionAnalyzer or ClassificationAnalyzer based on the detected problem type, keeping the domain logic perfectly split and decoupled.

Parameters:

interface (ModelInterface) – A validated interface wrapping the fitted model and data splits.

Examples

>>> from machinelens.core import ModelInterface
>>> from machinelens.analyzer import ModelAnalyzer
>>> mi = ModelInterface(model, X_train, X_test, y_train, y_test, y_pred)
>>> analyzer = ModelAnalyzer(mi)
>>> results = analyzer.analyze()

Methods

analyze()

Run all diagnostics and return a populated result object.

analyze() DiagnosticResults[source]#

Run all diagnostics and return a populated result object.

Returns:

Fully populated diagnostic state.

Return type:

DiagnosticResults

machinelens.analyzer.classification_analyzer module#

Classification diagnostics calculation engine for MachineLens.

class machinelens.analyzer.classification_analyzer.ClassificationAnalyzer(interface: ModelInterface)[source]#

Bases: object

Specialized engine for classification diagnostics.

Parameters:

interface (ModelInterface) – A validated interface wrapping the fitted model and data splits.

Methods

analyze(dr)

Populate dr with all classification diagnostics.

analyze(dr: DiagnosticResults) None[source]#

Populate dr with all classification diagnostics.

Parameters:

dr (DiagnosticResults) – The result container to populate.

machinelens.analyzer.regression_analyzer module#

Regression diagnostics calculation engine for MachineLens.

class machinelens.analyzer.regression_analyzer.RegressionAnalyzer(interface: ModelInterface)[source]#

Bases: object

Specialized engine for regression diagnostics.

Parameters:

interface (ModelInterface) – A validated interface wrapping the fitted model and data splits.

Methods

analyze(dr)

Populate dr with all regression diagnostics.

analyze(dr: DiagnosticResults) None[source]#

Populate dr with all regression diagnostics.

Parameters:

dr (DiagnosticResults) – The result container to populate.

machinelens.analyzer.shap_calculator module#

Helper module to compute SHAP values safely and efficiently.

machinelens.analyzer.shap_calculator.compute_shap_values(model: Any, X_train: DataFrame, X_eval: DataFrame, is_classification: bool = False) ShapData | None[source]#

Compute SHAP values for a given evaluation set using the training set as background.

Parameters:
  • model (Any) – The fitted scikit-learn compatible estimator.

  • X_train (pd.DataFrame) – The training data to use as background.

  • X_eval (pd.DataFrame) – The data to explain.

  • is_classification (bool) – Whether the model is a classifier.

Returns:

The computed SHAP data, or None if computation fails.

Return type:

ShapData or None

Module contents#

Specialized diagnostics calculation engines and processors for MachineLens.

class machinelens.analyzer.ClassificationAnalyzer(interface: ModelInterface)[source]#

Bases: object

Specialized engine for classification diagnostics.

Parameters:

interface (ModelInterface) – A validated interface wrapping the fitted model and data splits.

Methods

analyze(dr)

Populate dr with all classification diagnostics.

analyze(dr: DiagnosticResults) None[source]#

Populate dr with all classification diagnostics.

Parameters:

dr (DiagnosticResults) – The result container to populate.

class machinelens.analyzer.ModelAnalyzer(interface: ModelInterface)[source]#

Bases: object

Calculation engine that produces DiagnosticResults.

This analyzer automatically delegates calculations to the specialized RegressionAnalyzer or ClassificationAnalyzer based on the detected problem type, keeping the domain logic perfectly split and decoupled.

Parameters:

interface (ModelInterface) – A validated interface wrapping the fitted model and data splits.

Examples

>>> from machinelens.core import ModelInterface
>>> from machinelens.analyzer import ModelAnalyzer
>>> mi = ModelInterface(model, X_train, X_test, y_train, y_test, y_pred)
>>> analyzer = ModelAnalyzer(mi)
>>> results = analyzer.analyze()

Methods

analyze()

Run all diagnostics and return a populated result object.

analyze() DiagnosticResults[source]#

Run all diagnostics and return a populated result object.

Returns:

Fully populated diagnostic state.

Return type:

DiagnosticResults

class machinelens.analyzer.RegressionAnalyzer(interface: ModelInterface)[source]#

Bases: object

Specialized engine for regression diagnostics.

Parameters:

interface (ModelInterface) – A validated interface wrapping the fitted model and data splits.

Methods

analyze(dr)

Populate dr with all regression diagnostics.

analyze(dr: DiagnosticResults) None[source]#

Populate dr with all regression diagnostics.

Parameters:

dr (DiagnosticResults) – The result container to populate.