mardi 30 juin 2020

How to select a whole string from a list and not only a single letter? [closed]

I'm applying RandomSearchCV for a deep learning model. Therefore, I have to choose randomly parameters from a list. E.g.:

import secrets

activation = ['softmax', 'softplus', 'softsign', 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear']
activation = secrets.choice(activation)

or

import random

activation = ['softmax', 'softplus', 'softsign', 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear']
activation = random.choice(activation)

I've already tried also:

activation = {'d':['softmax', 'softplus', 'softsign', 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear']}
activation = secrets.choice(activation['d'])

But every time I get this as a result when running the code:

    Traceback (most recent call last):
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 531, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 142, in fit
    self.model = self.build_fn(**self.filter_sk_params(self.build_fn))
  File "/home/shiftone/vsd-shiftone/treino.py", line 244, in conv1D
    model.add(TimeDistributed(Conv1D(filters=24, kernel_size=10, activation=activation), input_shape=(1, 40, 17)))
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/layers/convolutional.py", line 353, in __init__
    **kwargs)
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/layers/convolutional.py", line 115, in __init__
    self.activation = activations.get(activation)
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/activations.py", line 227, in get
    return deserialize(identifier)
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/activations.py", line 208, in deserialize
    printable_module_name='activation function')
  File "/home/shiftone/miniconda3/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 167, in deserialize_keras_object
    ':' + function_name)
ValueError: Unknown activation function:n

As long as a can see it is not selecting the whole item of the list, but a single letter.




Aucun commentaire:

Enregistrer un commentaire