module plotting.visualize#

Short summary#

module mlinsights.plotting.visualize

Helpers to visualize a pipeline.

source on GitHub

Functions#

function

truncated documentation

_pipeline_info

Internal function to convert a pipeline into some graph.

pipeline2dot

Exports a scikit-learn pipeline to DOT language. See Visualize a scikit-learn pipeline for an example.

pipeline2str

Exports a scikit-learn pipeline to text.

Documentation#

Helpers to visualize a pipeline.

source on GitHub

mlinsights.plotting.visualize._pipeline_info(pipe, data, context, former_data=None)#

Internal function to convert a pipeline into some graph.

source on GitHub

mlinsights.plotting.visualize.pipeline2dot(pipe, data, **params)#

Exports a scikit-learn pipeline to DOT language. See Visualize a scikit-learn pipeline for an example.

Parameters:
  • pipescikit-learn pipeline

  • data – training data as a dataframe or a numpy array, or just a list with the variable names

  • params – additional params to draw the graph

Returns:

string

Default options for the graph are:

options = {
    'orientation': 'portrait',
    'ranksep': '0.25',
    'nodesep': '0.05',
    'width': '0.5',
    'height': '0.1',
}

source on GitHub

mlinsights.plotting.visualize.pipeline2str(pipe, indent=3)#

Exports a scikit-learn pipeline to text.

Parameters:

pipescikit-learn pipeline

Returns:

str

<<<

from sklearn.linear_model import LogisticRegression
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline

from mlinsights.plotting import pipeline2str

numeric_features = ['age', 'fare']
numeric_transformer = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='median')),
    ('scaler', StandardScaler())])

categorical_features = ['embarked', 'sex', 'pclass']
categorical_transformer = Pipeline(steps=[
    ('imputer', SimpleImputer(strategy='constant', fill_value='missing')),
    ('onehot', OneHotEncoder(handle_unknown='ignore'))])

preprocessor = ColumnTransformer(
    transformers=[
        ('num', numeric_transformer, numeric_features),
        ('cat', categorical_transformer, categorical_features),
    ])

clf = Pipeline(steps=[('preprocessor', preprocessor),
                      ('classifier', LogisticRegression(solver='lbfgs'))])
text = pipeline2str(clf)
print(text)

>>>

    Pipeline
       ColumnTransformer
          Pipeline(age,fare)
             SimpleImputer
             StandardScaler
          Pipeline(embarked,sex,pclass)
             SimpleImputer
             OneHotEncoder
       LogisticRegression

source on GitHub