module tools.model_info#

Short summary#

module mlprodict.tools.model_info

Functions to help get more information about the models.

source on GitHub

Functions#

function

truncated documentation

_analyse_tree

Extract information from a tree.

_analyse_tree_h

Extract information from a tree in a HistGradientBoosting.

_get_info_lgb

Get informations from and lightgbm trees.

_get_info_xgb

Get informations from and lightgbm trees.

_reduce_infos

Produces agregates features.

analyze_model

Returns informations, statistics about a model, its number of nodes, its size…

enumerate_models

Enumerates models with models.

set_random_state

Sets all possible parameter random_state to 0.

Documentation#

Functions to help get more information about the models.

source on GitHub

mlprodict.tools.model_info._analyse_tree(tree)#

Extract information from a tree.

source on GitHub

mlprodict.tools.model_info._analyse_tree_h(tree)#

Extract information from a tree in a HistGradientBoosting.

source on GitHub

mlprodict.tools.model_info._get_info_lgb(model)#

Get informations from and lightgbm trees.

source on GitHub

mlprodict.tools.model_info._get_info_xgb(model)#

Get informations from and lightgbm trees.

source on GitHub

mlprodict.tools.model_info._reduce_infos(infos)#

Produces agregates features.

source on GitHub

mlprodict.tools.model_info.analyze_model(model, simplify=True)#

Returns informations, statistics about a model, its number of nodes, its size…

Parameters
  • model – any model

  • simplify – simplifies the tuple of length 1

Returns

dictionary

Extract information from a model

The function analyze_model extracts global figures about a model, whatever it is.

<<<

import pprint
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from mlprodict.tools.model_info import analyze_model

data = load_iris()
X, y = data.data, data.target
model = RandomForestClassifier().fit(X, y)
infos = analyze_model(model)
pprint.pprint(infos)

>>>

    /var/lib/jenkins/workspace/mlprodict/mlprodict_UT_39_std/_venv/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute `n_features_` was deprecated in version 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
      warnings.warn(msg, category=FutureWarning)
    /var/lib/jenkins/workspace/mlprodict/mlprodict_UT_39_std/_venv/lib/python3.9/site-packages/sklearn/utils/deprecation.py:103: FutureWarning: The attribute `n_features_` is deprecated in 1.0 and will be removed in 1.2. Use `n_features_in_` instead.
      warnings.warn(msg, category=FutureWarning)
    {'classes_.shape': 3,
     'estimators_.classes_.shape': 3,
     'estimators_.max|tree_.max_depth': 8,
     'estimators_.n_classes_': 3,
     'estimators_.n_features_': 4,
     'estimators_.size': 100,
     'estimators_.sum|tree_.leave_count': 858,
     'estimators_.sum|tree_.node_count': 1616,
     'n_classes_': 3,
     'n_features_': 4}

source on GitHub

mlprodict.tools.model_info.enumerate_models(model)#

Enumerates models with models.

Parameters

modelscikit-learn model

Returns

enumerate models

source on GitHub

mlprodict.tools.model_info.set_random_state(model, value=0)#

Sets all possible parameter random_state to 0.

Parameters
Returns

model (same one)

source on GitHub