Auto Run
by: Kevin Broløs & Chris Cave
(Feyn version 3.4.0 or newer)
The auto_run method on the QLattice is a convenience function for running the QLattice simulator.
This enables you to get receive Models fitted to your data with a single line of code.
Example
First, load a data set and initialise a QLattice
import feyn
from feyn.datasets import make_classification
train, test = make_classification()
ql = feyn.QLattice()
Then we use only one line of code to obtain models fitted to the data.
models = ql.auto_run(
data=train,
output_name='y',
)
One epoch of auto_run is roughly equivalent to:
- sample
Models from aQLattice. - fit the
Models to the data. - prune the list of
Models. - update the
QLatticewith the remaining models.
If you are running this in a Jupyter environment then it will display the best model at the current epoch. Underneath the model it displays the current epoch, the amount of Models that have been sampled from the QLattice and the loss of the Model's predictions of the data.
Data preparation and types
Feyn requires very little data preparation since the models have inputs that do automatic scaling and treatment of certain types. The QLattice does require knowing what type you intend an input to be, and we call those semantic types, or stypes.
auto_run aims to be fully automatic, so it tries to guess those types when you train, meaning you can get started with most data sets without making decisions on the types.
You can specify the types manually, and we refer to the guide on semantic types (stypes) for more on that.
Model kind
When sampling models, the QLattice needs to know the kind of model you want to train - regression or classification.
auto_run will automatically infer the kind of model from the stype that is designated to the output column, unless a different kind parameter is given manually.
In the event that kind is not specified (or auto), and there's no stype given for the output column due to manually specifying stypes, it'll default back to regression.
Binary columns will be treated as classification and the rest as regression.
Reproducible results
The QLattice is a stochastic algorithm, but like many other machine learning techniques, you can supply a random seed in order to obtain reproducible results between runs. You can read more about that on Seeding a QLattice.
Further exploration
The method auto_run is a convenience function that wraps the Primitive Operations, and you should read through each of those guides if you want a more customised workflow or would just like to dive deeper into the options.
Most of the parameters for the Primitive Operations also exist on auto_run.
We didn't tackle all the options of auto_run. Here's a list of some additional options you can read into:
Parameters of auto_run
Go to the API Reference to see the full list of parameters to auto_run. Here are descriptions of the ones we've used in this example.
data
This is the data that the Models will be fitted to. This needs to be a pandas.DataFrame object where a sample is represented by a single row and the variable names are the names of the columns.
output_name
This is the name of the target variable as a string.
kind
The kind parameter can take one of classification or regression and this specifies whether the Models will be binary classifiers or regressors. The default is auto, and will infer the kind of model based on the output column's stype. The loss function the Models will be fitted to is squared_loss for regressors or binary_cross_entropy for classifiers.