Package: rfvis
RFVisA tool for visualizing the structure and performance of Random Forests (and other ensemble methods based on decision trees).RFVis offers aCommand Line APIand aPython APIwhich works on asklearn.ensemble.RandomForestClassifier.Getting StartedInstall and update RFVis viapip:$ pip install rfvisThis will allow you interactively visualize a fitted Random Forest (RF) in your
browser. To directly generate SVG files from your model you also need to installNode.js, seeCommand Line Interfacefor more information.Command Line APIRFVis offers a command line tool to either generate SVG files directly from
your input data (rfvis cli <data>) or to spin up a web-based GUI for a more
interactive analysis (rfvis gui <data>).To see all available commands run:$ rfvis --help
Usage: rfvis [OPTIONS] COMMAND [ARGS]...

  A tool for visualizing the structure and performance of Random Forests

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  cli  Command line interface to generate SVGs.
  gui  Web-based graphical user interface.Graphical User InterfaceTo interactively analyze your forest with the web-based GUI run:$ rfvis gui /path/to/data
 * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)You can now open up your browser athttp://localhost:8080to see something like this:Command Line InterfaceTo use the Command Line Interface (CLI) you need to haveNode.jsv8+ installed on your system. This
is a technical limitation due to the fact that the rendering is written in
Javascript. You do not need to install any other package though, the CLI
integrates into the command line tool you already installed via pip:$ rfvis cli /path/to/data
>> Exported "/dev/random-forest-visualization/tree-0.svg"
>> Exported "/dev/random-forest-visualization/tree-1.svg"
>> Exported "/dev/random-forest-visualization/tree-2.svg"
>> Exported "/dev/random-forest-visualization/tree-3.svg"
...Get a full list of available options with--help:$ rfvis cli --help
Usage: rfvis cli [OPTIONS] FOREST_JSON

  Web-based graphical user interface.

  As Python is unable to render React components, we make a subprocess call to a small
  Node.js application which will do the rendering and also store the created SVG
  files. This command requires that Node.js is installed on your system!

  FOREST_JSON: Path to the JSON file that contains the forest's data.

Options:
  -o, --out PATH                  Output path of the SVG files.  [default: (current
                                  working directory)]
  -w, --width INTEGER             Width of the SVG.  [default: 800]
  -h, --height INTEGER            Height of the SVG.  [default: 800]
  --trunk-length INTEGER          Length of the trunk which influences the overall tree
                                  size.  [default: 100]
  --display-depth INTEGER         Maximum depth of the tree rendering. Cut of leaves are
                                  visualized as pie chart consolidation nodes.
  --branch-color [Impurity]       Coloring of the branches.  [default: Impurity]
  --leaf-color [Impurity|Best Class]
                                  Coloring of the leaves.  [default: Impurity]
  --help                          Show this message and exit.Input DataThe data for the Command Line API must be available on your filesystem as a JSON file
for the forest and additionally one CSV file per tree. Both data formats will
be extended with properties in the future, this is just the minimal set.You can find a working example underexamples/PolSAR.Forest JSONThe mainforest.jsonholds all information about the ensemble model:name(string): Name of your forest, will be displayed in the GUIerror(float): The error (e.g. the out-of-bag or validation error) of the
entire ensemble model, will be displayed in the GUIn_samples(int): Number of samples the model was trained oncorrelationMatrix(float[][]): Correlation between the single trees within
the model. Has dimensionsNxNwhereNis the number of trees.
This will be used to compute the forest map.classes: The output classesname(string): Name of the classcolor(int, int, int): RGB values in the range of 0-255 which
determine the color of the class in the visualizationtrees: The trees in the foresterror(float): The error (again could be either the out-of-bag or
validation error) of the single treedata(string): Relative path to the CSV file containing the tree dataTree CSVFor each tree specified in theforest.jsonRFVis expects a CSV file where one
entry represents one node in the tree. An entry has the following format:id(int): ID of the nodedepth(int) Depth of the node in the tree (starting at0)n_node_samples(int): Number of training samples reaching the nodeimpurity(float): Impurity of the node (0-1)value(int[]): Class distribution within the node, i.e. every entry
represents the amount of samples within the node that respond to a specific
class. The index corresponds to the indices inforest.classes.Python APIRFVis also offers a Python API which works directly on a scikit-learn RandomForestClassifier.
You can find a working example underexamples/scikit_learn.py.The functionrfvis.gui()visualizes a fitted RandomForestClassifier in a web based graphical user interface.
The server runs in a separate process and is available athttp://localhost:<port>.gui(model,data=None,target=None,name=None,class_names=None,class_colors=None,port=8080)Args:model(sklearn.ensemble.RandomForestClassifier):
The model to visualize.data(array-like, shape=(n_samples, n_features)): The training input samples that were used to fit the model.
Used to compute the out-of-bag error and correlation of the individual trees.
If not provided, the forest view will have no significance.target(array-like, shape=n_samples): The target values (class labels) that were used to fit the model.
Used to compute the out-of-bag error and correlation of the individual trees.
If not provided, the forest view will have no significance.name(str): Optional name of the model which will be displayed in the frontend.class_names(List[str]): Optional list of names of the target classesclass_colors(List[str]): Optional list of browser interpretable colors for the target classes.
Seehttps://developer.mozilla.org/en-US/docs/Web/CSS/color_value.port(int): Port on which the frontend will run on. Defaults to 8080.Returns:process(multiprocessing.Process): Subprocess that runs the server. Can be terminated withprocess.terminate().DevelopmentThe repository contains aPipfilefor conveniently creating a virtualenv
for development. Just installpipenvand run:$ pipenv installYou can now e.g. start the server on the default port 8080 via:$ pipenv run rfvis gui <path_to_forest_json>Note that you need to build the frontend bundle first before you can
actually see the application working onhttp://localhost:8080.To build the frontend you need Node.js installed. First install all
dev-dependencies by running the following
from within the./rfvis/clientdirectory:$ npm installNow you can build a production-ready bundle via:$ npm run buildIf you have the Python server running you should now be able to see the
application athttp://localhost:8080.For developing on the frontend more conveniently run:$ npm startTo start a development server with hot reloading athttp://localhost:3000.PublicationsIf you are using RFVis in your research, please cite the following paper:Ronny Hänsch, Philipp Wiesner, Sophie Wendler, and Olaf Hellwich. "Colorful Trees: Visualizing Random Forests for Analysis and Interpretation" In 2019IEEE Winter Conference on Applications of Computer Vision (WACV), pp. 294-302. IEEE, 2019.