Feyn Documentation

Feyn Documentation

  • Learn
  • Guides
  • Tutorials
  • API Reference
  • FAQ

›Understand Your Models

Getting Started

  • Quick start
  • Using Feyn
  • Installation
  • What is the QLattice?

Essentials

  • Auto Run
  • Summary plot
  • Plot response
  • Splitting a dataset
  • Seeding a QLattice
  • Predicting with a model
  • Saving and loading models
  • Categorical features

Evaluate Regressors

  • Regression plot
  • Residuals plot

Evaluate Classifiers

  • ROC curve
  • Confusion matrix
  • Plot probability scores

Understand Your Models

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

Primitive Operations

  • Using the primitives
  • Updating priors
  • Sample models
  • Fitting models
  • Pruning models
  • Visualise a model
  • Diverse models
  • Updating a QLattice
  • Validate data
  • Semantic types

Advanced

  • Converting a model to SymPy
  • Logging in Feyn
  • Setting themes
  • Saving a graph as an image
  • Using the query language
  • Estimating priors
  • Filtering models
  • Model parameters
  • Model complexity

Privacy & Commercial

  • Privacy
  • Community edition
  • Commercial use
  • Transition to Feyn 3.0

Plot response 2D

by: Meera Machado
(Feyn version 3.4.0 or newer)


The plot_response_2d function enables the visualisation of the Model response as we vary two of its features. For a Model with more then two inputs, we should assign fixed values for the remaining input features. The Model response will then be a function of the non-fixed (variable) features.

Example

import feyn
import pandas as pd
from sklearn.datasets import load_breast_cancer


# Load into a pandas dataframe
breast_cancer = load_breast_cancer(as_frame=True)
data = breast_cancer.frame

# Train/test split
train, test = feyn.tools.split(data, ratio=[0.6, 0.4], stratify='target', random_state=666)

# Instantiate a QLattice
ql = feyn.QLattice(random_seed=666)

# Sample and fit models
models = ql.auto_run(
    data=train,
    output_name='target'
)

best = models[0]

Plotting the 2D response

By fixing the values of worst texture, the function plot_response_2d plots the Model response with varying worst concave points and worst area.

# Fixing the input features we're not interested in displaying
best.plot_response_2d(
    data=train,
    fixed={
        'worst texture': train['worst texture'].median()
    }
)

A 2D response plot showing the decision boundary between the positive and negative class.

We can clearly see the boundary that separates the positive class from the negative class. Lastly, large markers are the samples whose values correspond to those in fixed.

Flipping the colors

There's a helper function on Theme to flip the order of the colormap used for this plot, so you can easily control the positive and negative end of the color scale without having to supply a new colormap for each plot you do throughout.

As a shorthand for the diverging colormap:

from feyn import Theme
Theme.flip_diverging_cmap()

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_2d(
    data=train,
    fixed={
        'worst texture': train['worst texture'].median(),
    },
    filename="feyn-plot"
)

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


Parameters of plot_response_2d

data

The data to be analysed. It should be a pandas.DataFrame.

fixed

A dictionary where the keys are the names of the input features to be fixed and the values are the numbers/categories the features should be fixed to. The value corresponding to each key should be a scalar.

Location in Feyn

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

from feyn.plots import plot_model_response_2d

plot_model_response_2d(
    model=best,
    data=train,
    fixed={
        'worst texture': train['worst texture'].median()
    }
)
← Plot response 1DModel signal →
  • Example
    • Plotting the 2D response
    • Flipping the colors
    • Saving the plot
  • Parameters of plot_response_2d
    • data
    • fixed
  • Location in Feyn

Subscribe to get news about Feyn and the QLattice.

You can opt out at any time, and you can read our privacy policy here.

Copyright © 2024 Abzu.ai - Feyn license: CC BY-NC-ND 4.0
Feyn®, QGraph®, and the QLattice® are registered trademarks of Abzu®