772 строки
38 KiB
Plaintext
772 строки
38 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Pipeline visualization\n",
|
|
"\n",
|
|
"A pipeline built with NimbusML can be visualized easily using the visualization method:\n",
|
|
"\n",
|
|
" fig = img_export_pipeline(pipeline, stream)\n",
|
|
"It helps users to track the input/output of each step and can be used for sanity check of the features, especially for complicated pipelines with a large number of transforms. This notebook demonstrates how to visualize a pipeline."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Install Graphviz\n",
|
|
"[graphviz](https://www.graphviz.org/) is one tool often used to represent a graph described with the DOT language. In NimbusML, to use the img_export_pipeline function, we need to install graphviz.\n",
|
|
"To use graphviz in this notebook, [download the executables](https://graphviz.gitlab.io/download/), add them to your system path, and then run \"pip install graphviz\"."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"import sys\n",
|
|
"\n",
|
|
"\n",
|
|
"def install_and_import(package):\n",
|
|
" import importlib\n",
|
|
" try:\n",
|
|
" importlib.import_module(package)\n",
|
|
" except ImportError:\n",
|
|
" import pip\n",
|
|
" pip.main(\n",
|
|
" ['install', package])\n",
|
|
" finally:\n",
|
|
" globals()[package] = importlib.import_module(package)\n",
|
|
"\n",
|
|
"\n",
|
|
"install_and_import('graphviz')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Data\n",
|
|
"\n",
|
|
"We consider a very small dataset with tweets for demonstration."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pandas\n",
|
|
"import pprint\n",
|
|
"from nimbusml.feature_extraction.text import NGramFeaturizer\n",
|
|
"from nimbusml.preprocessing.schema import ColumnConcatenator\n",
|
|
"from nimbusml.feature_extraction.categorical import OneHotVectorizer\n",
|
|
"from nimbusml.ensemble import FastTreesBinaryClassifier\n",
|
|
"from nimbusml import Pipeline, FileDataStream, Role"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"data = \"\"\"\n",
|
|
"\"ItemID\",\"Sentiment\",\"SentimentSource\",\"SentimentText\",\"RowNum\",\"Positive\",\"Train\",\"Small\"\n",
|
|
"1,0,\"Sentiment140\",\"is so sad for my APL friend.............\",1,FALSE,TRUE,FALSE\n",
|
|
"2,0,\"Sentiment140\",\"I missed the New Moon trailer...\",2,FALSE,TRUE,FALSE\n",
|
|
"3,1,\"Sentiment140\",\"omg its already 7:30 :O\",3,TRUE,TRUE,FALSE\n",
|
|
"4,0,\"Sentiment140\",\".. Omgaga. Im sooo im gunna CRy. I've been at this dentist since 11.. I was suposed 2 just get a crown put on (30mins)...\",4,FALSE,TRUE,FALSE\n",
|
|
"5,0,\"Sentiment140\",\"i think mi bf is cheating on me!!! T_T\",5,FALSE,TRUE,FALSE\n",
|
|
"6,0,\"Sentiment140\",\"or i just worry too much?\",6,FALSE,TRUE,FALSE\n",
|
|
"7,1,\"Sentiment140\",\"Juuuuuuuuuuuuuuuuussssst Chillin!!\",7,TRUE,TRUE,FALSE\n",
|
|
"8,0,\"Sentiment140\",\"Sunny Again Work Tomorrow :-| TV Tonight\",8,FALSE,TRUE,FALSE\n",
|
|
"9,1,\"Sentiment140\",\"handed in my uniform today . i miss you already\",9,TRUE,TRUE,FALSE\n",
|
|
"\"\"\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"with open(\"data_train.csv\", \"w\") as f:\n",
|
|
" f.write(data.replace(\"\\t\", \",\"))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<div>\n",
|
|
"<style scoped>\n",
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
" vertical-align: middle;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe tbody tr th {\n",
|
|
" vertical-align: top;\n",
|
|
" }\n",
|
|
"\n",
|
|
" .dataframe thead th {\n",
|
|
" text-align: right;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
" <thead>\n",
|
|
" <tr style=\"text-align: right;\">\n",
|
|
" <th></th>\n",
|
|
" <th>ItemID</th>\n",
|
|
" <th>Positive</th>\n",
|
|
" <th>RowNum</th>\n",
|
|
" <th>Sentiment</th>\n",
|
|
" <th>SentimentSource</th>\n",
|
|
" <th>SentimentText</th>\n",
|
|
" <th>Small</th>\n",
|
|
" <th>Train</th>\n",
|
|
" </tr>\n",
|
|
" </thead>\n",
|
|
" <tbody>\n",
|
|
" <tr>\n",
|
|
" <th>0</th>\n",
|
|
" <td>1</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Sentiment140</td>\n",
|
|
" <td>is so sad for my APL friend.............</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>1</th>\n",
|
|
" <td>2</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>2</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Sentiment140</td>\n",
|
|
" <td>I missed the New Moon trailer...</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>2</th>\n",
|
|
" <td>3</td>\n",
|
|
" <td>True</td>\n",
|
|
" <td>3</td>\n",
|
|
" <td>1</td>\n",
|
|
" <td>Sentiment140</td>\n",
|
|
" <td>omg its already 7:30 :O</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>3</th>\n",
|
|
" <td>4</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>4</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Sentiment140</td>\n",
|
|
" <td>.. Omgaga. Im sooo im gunna CRy. I've been at...</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" <tr>\n",
|
|
" <th>4</th>\n",
|
|
" <td>5</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>5</td>\n",
|
|
" <td>0</td>\n",
|
|
" <td>Sentiment140</td>\n",
|
|
" <td>i think mi bf is cheating on me!!! T_T</td>\n",
|
|
" <td>False</td>\n",
|
|
" <td>True</td>\n",
|
|
" </tr>\n",
|
|
" </tbody>\n",
|
|
"</table>\n",
|
|
"</div>"
|
|
],
|
|
"text/plain": [
|
|
" ItemID Positive RowNum Sentiment SentimentSource \\\n",
|
|
"0 1 False 1 0 Sentiment140 \n",
|
|
"1 2 False 2 0 Sentiment140 \n",
|
|
"2 3 True 3 1 Sentiment140 \n",
|
|
"3 4 False 4 0 Sentiment140 \n",
|
|
"4 5 False 5 0 Sentiment140 \n",
|
|
"\n",
|
|
" SentimentText Small Train \n",
|
|
"0 is so sad for my APL friend............. False True \n",
|
|
"1 I missed the New Moon trailer... False True \n",
|
|
"2 omg its already 7:30 :O False True \n",
|
|
"3 .. Omgaga. Im sooo im gunna CRy. I've been at... False True \n",
|
|
"4 i think mi bf is cheating on me!!! T_T False True "
|
|
]
|
|
},
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"stream = FileDataStream.read_csv(\"data_train.csv\")\n",
|
|
"stream.head()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## A pipeline\n",
|
|
"\n",
|
|
"The following pipeline includes a couple of transform to process and convert text into numerical features."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"transform_1 = NGramFeaturizer() << {'transformed1':'SentimentText'}\n",
|
|
"transform_2 = OneHotVectorizer() << 'SentimentSource'\n",
|
|
"transform_3 = ColumnConcatenator() << {'finalfeatures': ['transformed1', 'SentimentSource']}\n",
|
|
"algo = FastTreesBinaryClassifier() << {Role.Feature:'finalfeatures', Role.Label: \"Positive\"}\n",
|
|
"\n",
|
|
"pipeline = Pipeline([transform_1, transform_2, transform_3, algo])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Method *get_fit_info* gives information on input, output for each transfrom and learner of the pipeline. The output is a list of dictionaries, each of them describes one element of the pipeline."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[{'name': None,\n",
|
|
" 'operator': None,\n",
|
|
" 'outputs': ['ItemID',\n",
|
|
" 'Sentiment',\n",
|
|
" 'SentimentSource',\n",
|
|
" 'SentimentText',\n",
|
|
" 'RowNum',\n",
|
|
" 'Positive',\n",
|
|
" 'Train',\n",
|
|
" 'Small'],\n",
|
|
" 'schema_after': ['ItemID',\n",
|
|
" 'Sentiment',\n",
|
|
" 'SentimentSource',\n",
|
|
" 'SentimentText',\n",
|
|
" 'RowNum',\n",
|
|
" 'Positive',\n",
|
|
" 'Train',\n",
|
|
" 'Small'],\n",
|
|
" 'type': 'start'},\n",
|
|
" {'inputs': ['SentimentText'],\n",
|
|
" 'name': 'NGramFeaturizer',\n",
|
|
" 'operator': NGramFeaturizer(char_feature_extractor=None,\n",
|
|
" columns={'transformed1': 'SentimentText'}, dictionary=None,\n",
|
|
" keep_diacritics=False, keep_numbers=True, keep_punctuations=True,\n",
|
|
" language='English', output_tokens=False, stop_words_remover=None,\n",
|
|
" text_case='Lower', vector_normalizer='L2',\n",
|
|
" word_feature_extractor={'Name': 'NGram', 'Settings': {'NgramLength': 1, 'SkipLength': 0, 'AllLengths': True, 'MaxNumTerms': [10000000], 'Weighting': 'Tf'}}),\n",
|
|
" 'outputs': ['transformed1', 'transformed1_TransformedText'],\n",
|
|
" 'schema_after': ['ItemID',\n",
|
|
" 'Sentiment',\n",
|
|
" 'SentimentSource',\n",
|
|
" 'SentimentText',\n",
|
|
" 'RowNum',\n",
|
|
" 'Positive',\n",
|
|
" 'Train',\n",
|
|
" 'Small',\n",
|
|
" 'transformed1',\n",
|
|
" 'transformed1_TransformedText'],\n",
|
|
" 'type': 'transform'},\n",
|
|
" {'inputs': ['SentimentSource'],\n",
|
|
" 'name': 'OneHotVectorizer',\n",
|
|
" 'operator': OneHotVectorizer(columns='SentimentSource', max_num_terms=1000000,\n",
|
|
" output_kind='Ind', sort='Occurrence', term=None,\n",
|
|
" text_key_values=True),\n",
|
|
" 'outputs': ['SentimentSource'],\n",
|
|
" 'schema_after': ['ItemID',\n",
|
|
" 'Sentiment',\n",
|
|
" 'SentimentSource',\n",
|
|
" 'SentimentText',\n",
|
|
" 'RowNum',\n",
|
|
" 'Positive',\n",
|
|
" 'Train',\n",
|
|
" 'Small',\n",
|
|
" 'transformed1',\n",
|
|
" 'transformed1_TransformedText'],\n",
|
|
" 'type': 'transform'},\n",
|
|
" {'inputs': ['transformed1', 'SentimentSource'],\n",
|
|
" 'name': 'ColumnConcatenator',\n",
|
|
" 'operator': ColumnConcatenator(columns={'finalfeatures': ['transformed1', 'SentimentSource']}),\n",
|
|
" 'outputs': ['finalfeatures'],\n",
|
|
" 'schema_after': ['ItemID',\n",
|
|
" 'Sentiment',\n",
|
|
" 'SentimentSource',\n",
|
|
" 'SentimentText',\n",
|
|
" 'RowNum',\n",
|
|
" 'Positive',\n",
|
|
" 'Train',\n",
|
|
" 'Small',\n",
|
|
" 'transformed1',\n",
|
|
" 'transformed1_TransformedText',\n",
|
|
" 'finalfeatures'],\n",
|
|
" 'type': 'transform'},\n",
|
|
" {'inputs': ['Feature:finalfeatures', 'Label:Positive'],\n",
|
|
" 'name': 'FastTreesBinaryClassifier',\n",
|
|
" 'operator': FastTreesBinaryClassifier(allow_empty_trees=True, bagging_size=0,\n",
|
|
" baseline_alpha_risk=None, baseline_scores_formula=None,\n",
|
|
" best_step_trees=False, bias=0.0, bundling='None',\n",
|
|
" caching='Auto', categorical_split=False,\n",
|
|
" compress_ensemble=False, disk_transpose=None,\n",
|
|
" dropout_rate=0.0, early_stopping_metrics=0,\n",
|
|
" early_stopping_rule=None, enable_pruning=False,\n",
|
|
" entropy_coefficient=0.0, example_fraction=0.7,\n",
|
|
" execution_times=False, feature='finalfeatures',\n",
|
|
" feature_compression_level=1, feature_flocks=True,\n",
|
|
" feature_fraction=1.0, feature_reuse_penalty=0.0,\n",
|
|
" feature_select_seed=123, filter_zero_lambdas=False,\n",
|
|
" first_use_penalty=0.0, gain_conf_level=0.0,\n",
|
|
" get_derivatives_sample_rate=1, group_id=None,\n",
|
|
" histogram_pool_size=-1, label='Positive', learning_rate=0.2,\n",
|
|
" max_categorical_groups_per_node=64,\n",
|
|
" max_categorical_split_points=64, max_tree_output=100.0,\n",
|
|
" max_trees_after_compression=-1,\n",
|
|
" min_docs_for_categorical_split=100,\n",
|
|
" min_docs_percentage_split=0.001, min_split=10,\n",
|
|
" min_step_size=0.0, normalize='Auto', num_bins=255,\n",
|
|
" num_leaves=20, num_post_bracket_steps=0, num_trees=100,\n",
|
|
" optimizer='GradientDescent', parallel_trainer=None,\n",
|
|
" position_discount_freeform=None, pruning_threshold=0.004,\n",
|
|
" pruning_window_size=5, random_start=False, random_state=123,\n",
|
|
" shrinkage=1.0, smoothing=0.0, softmax_temperature=0.0,\n",
|
|
" sparsify_threshold=0.7, split_fraction=1.0,\n",
|
|
" test_frequency=2147483647, train_threads=None,\n",
|
|
" unbalanced_sets=False, use_line_search=False,\n",
|
|
" use_tolerant_pruning=False, weight=None,\n",
|
|
" write_last_ensemble=False),\n",
|
|
" 'outputs': ['PredictedLabel', 'PredictedProba', 'Score'],\n",
|
|
" 'schema_after': ['PredictedLabel', 'PredictedProba', 'Score'],\n",
|
|
" 'type': 'classifier'}]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"pprint.pprint(pipeline.get_fit_info(stream)[0])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Graph representation\n",
|
|
"\n",
|
|
"Previous information can be summarized in a nice graph much easier to read. The graph is described with the [DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language)) language. That's what the function *dot_export_pipeline* does. For raw text of the graph, users can use the dot_export_pipeline function:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"digraph{\n",
|
|
" orientation=portrait;\n",
|
|
" sch0[label=\"<f0> ItemID|<f1> Sentiment|<f2> SentimentSource|<f3> SentimentText|<f4> RowNum|<f5> Positive|<f6> Train|<f7> Small\",shape=record,fontsize=8];\n",
|
|
"\n",
|
|
" node1[label=\"NGramFeaturizer\",shape=box,style=\"filled,rounded\",color=cyan,fontsize=12];\n",
|
|
" sch0:f3 -> node1;\n",
|
|
" sch1[label=\"<f0> transformed1|<f1> transformed1_TransformedText\",shape=record,fontsize=8];\n",
|
|
" node1 -> sch1:f0;\n",
|
|
" node1 -> sch1:f1;\n",
|
|
"\n",
|
|
" node2[label=\"OneHotVectorizer\",shape=box,style=\"filled,rounded\",color=cyan,fontsize=12];\n",
|
|
" sch0:f2 -> node2;\n",
|
|
" sch2[label=\"<f0> SentimentSource\",shape=record,fontsize=8];\n",
|
|
" node2 -> sch2:f0;\n",
|
|
"\n",
|
|
" node3[label=\"ColumnConcatenator\",shape=box,style=\"filled,rounded\",color=cyan,fontsize=12];\n",
|
|
" sch1:f0 -> node3;\n",
|
|
" sch2:f0 -> node3;\n",
|
|
" sch3[label=\"<f0> finalfeatures\",shape=record,fontsize=8];\n",
|
|
" node3 -> sch3:f0;\n",
|
|
"\n",
|
|
" node4[label=\"FastTreesBinaryClassifier\",shape=box,style=\"filled,rounded\",color=yellow,fontsize=12];\n",
|
|
" sch3:f0 -> node4 [label=\"Feature\",fontsize=8];\n",
|
|
" sch0:f5 -> node4 [label=\"Label\",fontsize=8];\n",
|
|
" sch4[label=\"<f0> PredictedLabel|<f1> PredictedProba|<f2> Score\",shape=record,fontsize=8];\n",
|
|
" node4 -> sch4:f0;\n",
|
|
" node4 -> sch4:f1;\n",
|
|
" node4 -> sch4:f2;\n",
|
|
"}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"from nimbusml.utils.exports import dot_export_pipeline\n",
|
|
"dot_vis = dot_export_pipeline(pipeline, stream)\n",
|
|
"print(dot_vis)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Visualize with graphviz"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/svg+xml": [
|
|
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
|
|
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
|
|
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
|
|
"<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
|
|
" -->\r\n",
|
|
"<!-- Title: %3 Pages: 1 -->\r\n",
|
|
"<svg width=\"409pt\" height=\"502pt\"\r\n",
|
|
" viewBox=\"0.00 0.00 409.00 502.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
|
|
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 498)\">\r\n",
|
|
"<title>%3</title>\r\n",
|
|
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-498 405,-498 405,4 -4,4\"/>\r\n",
|
|
"<!-- sch0 -->\r\n",
|
|
"<g id=\"node1\" class=\"node\"><title>sch0</title>\r\n",
|
|
"<polygon fill=\"none\" stroke=\"black\" points=\"0,-457.5 0,-493.5 401,-493.5 401,-457.5 0,-457.5\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"21\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">ItemID</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"42,-457.5 42,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"68\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Sentiment</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"94,-457.5 94,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"131\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">SentimentSource</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"168,-457.5 168,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"202.5\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">SentimentText</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"237,-457.5 237,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"261\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">RowNum</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"285,-457.5 285,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"307.5\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Positive</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"330,-457.5 330,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"348\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Train</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"366,-457.5 366,-493.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"383.5\" y=\"-473.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Small</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node1 -->\r\n",
|
|
"<g id=\"node2\" class=\"node\"><title>node1</title>\r\n",
|
|
"<path fill=\"cyan\" stroke=\"cyan\" d=\"M238.5,-420C238.5,-420 166.5,-420 166.5,-420 160.5,-420 154.5,-414 154.5,-408 154.5,-408 154.5,-396 154.5,-396 154.5,-390 160.5,-384 166.5,-384 166.5,-384 238.5,-384 238.5,-384 244.5,-384 250.5,-390 250.5,-396 250.5,-396 250.5,-408 250.5,-408 250.5,-414 244.5,-420 238.5,-420\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"202.5\" y=\"-398.9\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">NGramFeaturizer</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch0->node1 -->\r\n",
|
|
"<g id=\"edge1\" class=\"edge\"><title>sch0:f3->node1</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M202.5,-457C202.5,-448.299 202.5,-438.809 202.5,-430.246\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"206,-430.025 202.5,-420.025 199,-430.025 206,-430.025\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node2 -->\r\n",
|
|
"<g id=\"node4\" class=\"node\"><title>node2</title>\r\n",
|
|
"<path fill=\"cyan\" stroke=\"cyan\" d=\"M110,-420C110,-420 33,-420 33,-420 27,-420 21,-414 21,-408 21,-408 21,-396 21,-396 21,-390 27,-384 33,-384 33,-384 110,-384 110,-384 116,-384 122,-390 122,-396 122,-396 122,-408 122,-408 122,-414 116,-420 110,-420\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"71.5\" y=\"-398.9\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">OneHotVectorizer</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch0->node2 -->\r\n",
|
|
"<g id=\"edge4\" class=\"edge\"><title>sch0:f2->node2</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M130.5,-457C130.5,-444.742 123.484,-434.516 114.29,-426.379\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"116.199,-423.429 106.162,-420.037 111.893,-428.948 116.199,-423.429\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node4 -->\r\n",
|
|
"<g id=\"node8\" class=\"node\"><title>node4</title>\r\n",
|
|
"<path fill=\"yellow\" stroke=\"yellow\" d=\"M335.5,-110C335.5,-110 227.5,-110 227.5,-110 221.5,-110 215.5,-104 215.5,-98 215.5,-98 215.5,-86 215.5,-86 215.5,-80 221.5,-74 227.5,-74 227.5,-74 335.5,-74 335.5,-74 341.5,-74 347.5,-80 347.5,-86 347.5,-86 347.5,-98 347.5,-98 347.5,-104 341.5,-110 335.5,-110\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"281.5\" y=\"-88.9\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">FastTreesBinaryClassifier</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch0->node4 -->\r\n",
|
|
"<g id=\"edge10\" class=\"edge\"><title>sch0:f5->node4</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M307.5,-457C307.5,-432.799 314.5,-427.201 314.5,-403 314.5,-403 314.5,-403 314.5,-172.5 314.5,-153.566 306.416,-133.899 298.251,-118.864\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"301.254,-117.065 293.227,-110.149 295.189,-120.56 301.254,-117.065\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"324\" y=\"-285.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Label</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch1 -->\r\n",
|
|
"<g id=\"node3\" class=\"node\"><title>sch1</title>\r\n",
|
|
"<polygon fill=\"none\" stroke=\"black\" points=\"93,-310.5 93,-346.5 286,-346.5 286,-310.5 93,-310.5\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"124.5\" y=\"-326.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">transformed1</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"156,-310.5 156,-346.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"221\" y=\"-326.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">transformed1_TransformedText</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node1->sch1 -->\r\n",
|
|
"<g id=\"edge2\" class=\"edge\"><title>node1->sch1:f0</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M154.434,-385.559C141.643,-378.88 130.229,-369.656 126.12,-357.183\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"129.528,-356.326 124.5,-347 122.615,-357.426 129.528,-356.326\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node1->sch1 -->\r\n",
|
|
"<g id=\"edge3\" class=\"edge\"><title>node1->sch1:f1</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M212,-383.541C215.488,-375.962 218.977,-366.669 220.584,-357.228\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"224.094,-357.272 221.5,-347 217.121,-356.648 224.094,-357.272\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node3 -->\r\n",
|
|
"<g id=\"node6\" class=\"node\"><title>node3</title>\r\n",
|
|
"<path fill=\"cyan\" stroke=\"cyan\" d=\"M169,-265C169,-265 80,-265 80,-265 74,-265 68,-259 68,-253 68,-253 68,-241 68,-241 68,-235 74,-229 80,-229 80,-229 169,-229 169,-229 175,-229 181,-235 181,-241 181,-241 181,-253 181,-253 181,-259 175,-265 169,-265\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"124.5\" y=\"-243.9\" font-family=\"Times New Roman,serif\" font-size=\"12.00\">ColumnConcatenator</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch1->node3 -->\r\n",
|
|
"<g id=\"edge6\" class=\"edge\"><title>sch1:f0->node3</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M124.5,-310C124.5,-298.617 124.5,-286.059 124.5,-275.239\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"128,-275.105 124.5,-265.105 121,-275.106 128,-275.105\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch2 -->\r\n",
|
|
"<g id=\"node5\" class=\"node\"><title>sch2</title>\r\n",
|
|
"<polygon fill=\"none\" stroke=\"black\" points=\"0.5,-310.5 0.5,-346.5 74.5,-346.5 74.5,-310.5 0.5,-310.5\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"37.5\" y=\"-326.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">SentimentSource</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node2->sch2 -->\r\n",
|
|
"<g id=\"edge5\" class=\"edge\"><title>node2->sch2:f0</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M63.4425,-383.819C59.5365,-375.49 54.7501,-365.283 50.3567,-355.915\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"53.389,-354.138 45.9741,-346.57 47.0513,-357.11 53.389,-354.138\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch2->node3 -->\r\n",
|
|
"<g id=\"edge7\" class=\"edge\"><title>sch2:f0->node3</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M57.2416,-310.233C69.4791,-298.91 85.3351,-284.239 98.5781,-271.985\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"101.063,-274.454 106.026,-265.094 96.3092,-269.316 101.063,-274.454\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch3 -->\r\n",
|
|
"<g id=\"node7\" class=\"node\"><title>sch3</title>\r\n",
|
|
"<polygon fill=\"none\" stroke=\"black\" points=\"194,-155.5 194,-191.5 253,-191.5 253,-155.5 194,-155.5\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"223.5\" y=\"-171.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">finalfeatures</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node3->sch3 -->\r\n",
|
|
"<g id=\"edge8\" class=\"edge\"><title>node3->sch3:f0</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M147.962,-228.819C160.652,-219.525 176.534,-207.894 190.456,-197.699\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"192.825,-200.302 198.825,-191.57 188.689,-194.654 192.825,-200.302\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch3->node4 -->\r\n",
|
|
"<g id=\"edge9\" class=\"edge\"><title>sch3:f0->node4</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M236.661,-155.233C244.514,-144.333 254.603,-130.331 263.222,-118.369\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"266.178,-120.253 269.184,-110.094 260.499,-116.161 266.178,-120.253\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"269.5\" y=\"-130.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Feature</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- sch4 -->\r\n",
|
|
"<g id=\"node9\" class=\"node\"><title>sch4</title>\r\n",
|
|
"<polygon fill=\"none\" stroke=\"black\" points=\"178.5,-0.5 178.5,-36.5 350.5,-36.5 350.5,-0.5 178.5,-0.5\"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"212.5\" y=\"-16.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">PredictedLabel</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"246.5,-0.5 246.5,-36.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"281\" y=\"-16.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">PredictedProba</text>\r\n",
|
|
"<polyline fill=\"none\" stroke=\"black\" points=\"315.5,-0.5 315.5,-36.5 \"/>\r\n",
|
|
"<text text-anchor=\"middle\" x=\"333\" y=\"-16.6\" font-family=\"Times New Roman,serif\" font-size=\"8.00\">Score</text>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node4->sch4 -->\r\n",
|
|
"<g id=\"edge11\" class=\"edge\"><title>node4->sch4:f0</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M238.586,-73.9564C227.624,-67.2564 217.868,-58.403 214.125,-47.0891\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"217.546,-46.3162 212.5,-37 210.635,-47.4293 217.546,-46.3162\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node4->sch4 -->\r\n",
|
|
"<g id=\"edge12\" class=\"edge\"><title>node4->sch4:f1</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M281.5,-73.9754C281.5,-66.1689 281.5,-56.561 281.5,-47.1065\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"285,-47 281.5,-37 278,-47 285,-47\"/>\r\n",
|
|
"</g>\r\n",
|
|
"<!-- node4->sch4 -->\r\n",
|
|
"<g id=\"edge13\" class=\"edge\"><title>node4->sch4:f2</title>\r\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M310.843,-73.9961C319.966,-66.8956 328.53,-57.7566 331.943,-46.9346\"/>\r\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"335.409,-47.4214 333.5,-37 328.494,-46.3374 335.409,-47.4214\"/>\r\n",
|
|
"</g>\r\n",
|
|
"</g>\r\n",
|
|
"</svg>\r\n"
|
|
],
|
|
"text/plain": [
|
|
"<graphviz.files.Source at 0x188fb80cdd8>"
|
|
]
|
|
},
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"from nimbusml.utils.exports import img_export_pipeline\n",
|
|
"fig = img_export_pipeline(pipeline, stream)\n",
|
|
"fig"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Let's give some insights on what it represents."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"<img src=\"images/pipeline-visualization_16_0.png\" align=\"middle\" />"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Visualize with viz.js\n",
|
|
"\n",
|
|
"There exists a javascript alternative to *graphivz* which does not requiree installation but only works in a notebook:\n",
|
|
"[viz.js](https://github.com/mdaines/viz.js/)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"\n",
|
|
"<div id=\"dotgraph\" style=\"width:100%;height:100%;\"></div></div>\n",
|
|
"<script>\n",
|
|
"\n",
|
|
"require(['http://viz-js.com/bower_components/viz.js/viz.js'], function() { \n",
|
|
" var svgGraph = Viz(\"digraph{\\n orientation=portrait;\\n sch0[label=\\\"<f0> ItemID|<f1> Sentiment|<f2> SentimentSource|<f3> SentimentText|<f4> RowNum|<f5> Positive|<f6> Train|<f7> Small\\\",shape=record,fontsize=8];\\n\\n node1[label=\\\"NGramFeaturizer\\\",shape=box,style=\\\"filled,rounded\\\",color=cyan,fontsize=12];\\n sch0:f3 -> node1;\\n sch1[label=\\\"<f0> transformed1\\\",shape=record,fontsize=8];\\n node1 -> sch1:f0;\\n\\n node2[label=\\\"OneHotVectorizer\\\",shape=box,style=\\\"filled,rounded\\\",color=cyan,fontsize=12];\\n sch0:f2 -> node2;\\n sch2[label=\\\"<f0> SentimentSource\\\",shape=record,fontsize=8];\\n node2 -> sch2:f0;\\n\\n node3[label=\\\"ColumnConcatenator\\\",shape=box,style=\\\"filled,rounded\\\",color=cyan,fontsize=12];\\n sch1:f0 -> node3;\\n sch2:f0 -> node3;\\n sch3[label=\\\"<f0> finalfeatures\\\",shape=record,fontsize=8];\\n node3 -> sch3:f0;\\n\\n node4[label=\\\"FastTreesBinaryClassifier\\\",shape=box,style=\\\"filled,rounded\\\",color=yellow,fontsize=12];\\n sch3:f0 -> node4 [label=\\\"Feature\\\",fontsize=8];\\n sch0:f5 -> node4 [label=\\\"Label\\\",fontsize=8];\\n sch4[label=\\\"<f0> PredictedLabel|<f1> PredictedProba|<f2> Score\\\",shape=record,fontsize=8];\\n node4 -> sch4:f0;\\n node4 -> sch4:f1;\\n node4 -> sch4:f2;\\n}\");\n",
|
|
" document.getElementById('dotgraph').innerHTML = svgGraph; \n",
|
|
"});\n",
|
|
"\n",
|
|
"</script>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"%%html\n",
|
|
"\n",
|
|
"<div id=\"dotgraph\" style=\"width:100%;height:100%;\"></div></div>\n",
|
|
"<script>\n",
|
|
"\n",
|
|
"require(['http://viz-js.com/bower_components/viz.js/viz.js'], function() { \n",
|
|
" var svgGraph = Viz(\"digraph{\\n orientation=portrait;\\n sch0[label=\\\"<f0> ItemID|<f1> Sentiment|<f2> SentimentSource|<f3> SentimentText|<f4> RowNum|<f5> Positive|<f6> Train|<f7> Small\\\",shape=record,fontsize=8];\\n\\n node1[label=\\\"NGramFeaturizer\\\",shape=box,style=\\\"filled,rounded\\\",color=cyan,fontsize=12];\\n sch0:f3 -> node1;\\n sch1[label=\\\"<f0> transformed1\\\",shape=record,fontsize=8];\\n node1 -> sch1:f0;\\n\\n node2[label=\\\"OneHotVectorizer\\\",shape=box,style=\\\"filled,rounded\\\",color=cyan,fontsize=12];\\n sch0:f2 -> node2;\\n sch2[label=\\\"<f0> SentimentSource\\\",shape=record,fontsize=8];\\n node2 -> sch2:f0;\\n\\n node3[label=\\\"ColumnConcatenator\\\",shape=box,style=\\\"filled,rounded\\\",color=cyan,fontsize=12];\\n sch1:f0 -> node3;\\n sch2:f0 -> node3;\\n sch3[label=\\\"<f0> finalfeatures\\\",shape=record,fontsize=8];\\n node3 -> sch3:f0;\\n\\n node4[label=\\\"FastTreesBinaryClassifier\\\",shape=box,style=\\\"filled,rounded\\\",color=yellow,fontsize=12];\\n sch3:f0 -> node4 [label=\\\"Feature\\\",fontsize=8];\\n sch0:f5 -> node4 [label=\\\"Label\\\",fontsize=8];\\n sch4[label=\\\"<f0> PredictedLabel|<f1> PredictedProba|<f2> Score\\\",shape=record,fontsize=8];\\n node4 -> sch4:f0;\\n node4 -> sch4:f1;\\n node4 -> sch4:f2;\\n}\");\n",
|
|
" document.getElementById('dotgraph').innerHTML = svgGraph; \n",
|
|
"});\n",
|
|
"\n",
|
|
"</script>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## In a function\n",
|
|
"\n",
|
|
"If you have many pipeline to draw."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
" \n",
|
|
"<div id=\"ce614e3d-ebed-4cc9-b3c4-d57408606615\" style=\"width:100%;height:100%;\"></div></div>\n",
|
|
"<script>\n",
|
|
"\n",
|
|
"require(['http://viz-js.com/bower_components/viz.js/viz.js'], function() { \n",
|
|
" var dot = 'digraph{\\n orientation=portrait;\\n sch0[label=\"<f0> ItemID|<f1> Sentiment|<f2> SentimentSource|<f3> SentimentText|<f4> RowNum|<f5> Positive|<f6> Train|<f7> Small\",shape=record,fontsize=8];\\n\\n node1[label=\"NGramFeaturizer\",shape=box,style=\"filled,rounded\",color=cyan,fontsize=12];\\n sch0:f3 -> node1;\\n sch1[label=\"<f0> transformed1|<f1> transformed1_TransformedText\",shape=record,fontsize=8];\\n node1 -> sch1:f0;\\n node1 -> sch1:f1;\\n\\n node2[label=\"OneHotVectorizer\",shape=box,style=\"filled,rounded\",color=cyan,fontsize=12];\\n sch0:f2 -> node2;\\n sch2[label=\"<f0> SentimentSource\",shape=record,fontsize=8];\\n node2 -> sch2:f0;\\n\\n node3[label=\"ColumnConcatenator\",shape=box,style=\"filled,rounded\",color=cyan,fontsize=12];\\n sch1:f0 -> node3;\\n sch2:f0 -> node3;\\n sch3[label=\"<f0> finalfeatures\",shape=record,fontsize=8];\\n node3 -> sch3:f0;\\n\\n node4[label=\"FastTreesBinaryClassifier\",shape=box,style=\"filled,rounded\",color=yellow,fontsize=12];\\n sch3:f0 -> node4 [label=\"Feature\",fontsize=8];\\n sch0:f5 -> node4 [label=\"Label\",fontsize=8];\\n sch4[label=\"<f0> PredictedLabel|<f1> PredictedProba|<f2> Score\",shape=record,fontsize=8];\\n node4 -> sch4:f0;\\n node4 -> sch4:f1;\\n node4 -> sch4:f2;\\n}';\n",
|
|
" var svgGraph = Viz(dot);\n",
|
|
" document.getElementById('ce614e3d-ebed-4cc9-b3c4-d57408606615').innerHTML = svgGraph; \n",
|
|
"});\n",
|
|
"\n",
|
|
"</script>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"from nimbusml.utils.exports import dot_export_pipeline\n",
|
|
"from jinja2 import Template\n",
|
|
"import uuid\n",
|
|
"from IPython.display import HTML\n",
|
|
"\n",
|
|
"\n",
|
|
"template = Template(\"\"\" \n",
|
|
"<div id=\"{{divid}}\" style=\"width:{{width}};height:{{height}};\"></div></div>\n",
|
|
"<script>\n",
|
|
"\n",
|
|
"require(['http://viz-js.com/bower_components/viz.js/viz.js'], function() { \n",
|
|
" var dot = '{{dot}}';\n",
|
|
" var svgGraph = Viz(dot);\n",
|
|
" document.getElementById('{{divid}}').innerHTML = svgGraph; \n",
|
|
"});\n",
|
|
"\n",
|
|
"</script>\n",
|
|
"\"\"\")\n",
|
|
"\n",
|
|
"\n",
|
|
"def display_pipeline(pipeline, stream, divid=None, width=\"100%\", height=\"100%\"):\n",
|
|
" global template\n",
|
|
" if divid is None:\n",
|
|
" divid = uuid.uuid4()\n",
|
|
" dot = dot_export_pipeline(pipeline, stream)\n",
|
|
" html = template.render(dot=dot.replace(\"\\n\", \"\\\\n\"), divid=divid,\n",
|
|
" width=width, height=height)\n",
|
|
" return HTML(html)\n",
|
|
"\n",
|
|
"display_pipeline(pipeline, stream)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.6.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|