Model parameters
by: Kevin Broløs & Meera Machado
(Feyn version 3.0 or newer)
You can output and inspect all parameters as a python dict
using the params
property on a Model
. It's mostly useful for programmatic parsing and relies on the positional node orderings.
For other cases, we recommend you use the get_parameters
function on the Model
instead.
It takes the name of the input or output and returns a pandas.DataFrame
with its parameter values.
If your Model
has multiple inputs with the same name in different positions, this is disambiguated with their ordinal position that you can cross-reference in the Model
graph by checking the number in the corner of the node.
Example
Here is an example of how to display the parameters for a model that contains categorical and numerical inputs.
import pandas as pd
import feyn
ql = feyn.QLattice()
data = pd.DataFrame(
{
'a': [1, 2, 3, 4, 5, 6],
'cat': ["Three", "Two", "Four", "Three", "Two", "One"],
'y': [4, 4, 7, 7, 7, 7]
}
)
models = ql.auto_run(data, output_name='y', stypes={'cat':'c'}, max_complexity=3, n_epochs=1)
best_model = models[0]
best_model
best_model.get_parameters(name='cat')
cat | |
---|---|
category | |
Four | 0.376742 |
Three | 0.143783 |
Two | -0.089089 |
One | -0.321966 |
best_model.get_parameters(name='a')
a | |
---|---|
scale | 0.400000 |
scale_offset | 3.500000 |
w | 0.582286 |
bias | 0.993797 |
detect_scale | 0.000000 |
best_model.get_parameters(name='y')
y | |
---|---|
scale | 1.500000 |
scale_offset | 0.000000 |
w | 2.862249 |
bias | 0.572713 |
detect_scale | 0.000000 |
Feyn
Location in This function can also be found in the feyn.tools
module.
from feyn.tools import get_model_parameters
get_model_parameters(best_model, 'cat')