Feyn

Feyn

  • Tutorials
  • Guides
  • API Reference
  • FAQ

›Understand Your Models

Getting Started

  • Quick start
  • Using Feyn
  • Installation
  • Transition to Feyn 3.0
  • What is a QLattice?
  • Community edition
  • Commercial use

Essentials

  • Auto Run
  • Visualise a model
  • Summary plot
  • Semantic types
  • Categorical features
  • Estimating priors
  • Model parameters
  • Predicting with a model
  • Saving and loading models
  • Filtering models
  • Seeding a QLattice
  • Privacy

Evaluate Regressors

  • Regression plot
  • Residuals plot

Evaluate Classifiers

  • ROC curve
  • Confusion matrix
  • Plot probability scores

Understand Your Models

  • Plot response
  • Plot response 2D
  • Model signal
  • Segmented loss
  • Interactive flow

Primitive Operations

  • Using the primitives
  • Updating priors
  • Sample models
  • Fitting models
  • Pruning models
  • Diverse models
  • Updating a QLattice
  • Validate data

Advanced

  • Converting a model to SymPy
  • Setting themes
  • Saving a graph as an image
  • Using the query language
  • Model complexity

Plot response

by: Chris Cave
(Feyn version 3.0 or newer)

A Model is a mathematical function from the inputs to the output. If there are more than two inputs in a Model then it is difficult to visualise how the inputs affect the output.

One way to overcome this is to simplifiy the Model by fixing all the inputs except for one. This simplified Model now has one input and one output. This can be visualised by plotting the single input against the output. plot_response_1d enables you to choose and plot simplified models.

Here is an example:

import feyn

from sklearn.datasets import load_boston
import pandas as pd

from feyn.tools import split

#Download boston housing dataset
boston = load_boston()
df_boston = pd.DataFrame(boston.data, columns=boston.feature_names)
df_boston['PRICE'] = boston.target

# Train/test split
train, test = split(df_boston)

# Instantiate a QLattice
ql = feyn.QLattice()

models = ql.auto_run(
    data=train,
    output_name='PRICE'
)
# Select the best Model
best = models[0]
best

Static Mode
Interactive Mode
# Plot simplified model with only 'CRIM' manually fixed
best.plot_response_1d(
data = train,
by = 'LSTAT',
input_constraints = {'CRIM': train.CRIM.quantile(0.25)}
)

# Plot simplified model with only 'CRIM' manually fixed
best.interactive_response_1d(
data = train,
input_constraints = {'CRIM': train.CRIM.quantile(0.25)}
)


The continuous line is the plot of the simplified function. The scatter points are the values (data[by], data[output]). The histogram on the top is of data[by] and the histogram to the side is of data[output].

data

A pd.DataFrame of your data. This parameter is passed to determine the range of the non-fixed input to plot. All input names of the Model should be the name of columns in the data.

The data is also used to plot the scatter points. This is useful to visualise if the Model has had enough data points to say with confidence the output value of particular inputs.

by

The input name that is not fixed and is the single input of the simplified Model.

input_constraints

A dictionary where the keys are the names of all fixed inputs and the values are what to fix the Model at. If None and there are fewer than three inputs then 25%, 50% and 75% quartiles of each fixed input is passed. If there are more than three inputs then only the median is passed for each fixed input. Default is None.

Saving the plot

You can save the plot using the filename parameter. The plot is saved in the current working directory unless another path specifed.

best.plot_response_1d(
    data=train,
    by = 'LSTAT',
    input_constraints = {'CRIM': train.CRIM.quantile(0.25)},
    filename="feyn-plot"
)

If the extension is not specified then it is saved as a png file.

Location in Feyn

This function can also be found in feyn.plots module.

from feyn.plots import plot_model_response_1d

plot_model_response_1d(best, train, train[best[0].name])
← Plot probability scoresPlot response 2D →
  • data
  • by
  • input_constraints
  • Saving the plot
  • Location in Feyn
Copyright © 2022 Abzu.ai
Feyn®, QGraph®, and the QLattice® are registered trademarks of Abzu®