Skip to content

The SVM trainers' gamma cannot be given the value scikit-learn defaults to #7945

Description

@kz930

What happened?

SklearnAdvancedSVCParameters and SklearnAdvancedSVRParameters pair each hyperparameter with the Python callable that converts the user's text. gamma names float, so the operator emits gamma = float(value).

scikit-learn accepts two different kinds of value for this parameter: one of the words scale and auto, or a non-negative number. scale is the default, and it is what makes the estimator derive gamma from the training data rather than having it pinned to a constant. Under float neither word survives:

float('scale') -> ValueError: could not convert string to float: 'scale'

So the parameter can only ever be given an explicit number, and the mode most users want is unreachable.

Naming str instead does not fix it, it only moves the loss to the other half. str turns 0.1 into the string '0.1', which scikit-learn then refuses:

The 'gamma' parameter of SVC must be a str among {'auto', 'scale'} or a float in the range [0.0, inf). Got '0.1' instead.

A correction to an earlier reading of this: one converter is enough. The column names a Python expression rather than a type, which the boolean parameters already use for a lambda, so a lambda that hands the two words through and puts everything else past float() carries both kinds of value. ParamClass needs no new shape. The declaration is simply the wrong one, as in #7593, it is just that no converter named after a type is the right one here.

Related: #7593 covers two KNN parameters with the same kind of mistake. Those are each fixed by naming a different type; this one needs an expression instead, and the value it should offer is scale, the estimator's own default.

How to reproduce?

Add an SVM Classifier Trainer, wire a numeric table to its training port and any table to its parameter port, then set the ground truth attribute and the selected features. Add one hyperparameter row, pick gamma, and give it scale. The run ends. auto behaves the same. A number such as 0.1 runs fine, which is the only way the parameter can be used today. The SVM Regressor Trainer behaves identically.

Version/Branch

1.3.0-incubating-SNAPSHOT (main)

Relevant log output

ValueError: could not convert string to float: 'scale'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions