user14388704
user14388704

Reputation:

KeyError: 'key of type tuple not found and not a MultiIndex' Optunity

trying to use pso in combination with svm through optunity. however im geting the error:

KeyError: 'key of type tuple not found and not a MultiIndex'

the code ive beeen using is the following, found on github.

search = {
    'C': (0,50),
    'kernel':[0,3],
    'epsilon': (0, 1)
         }
@optunity.cross_validated(x=X_train, y=y_train, num_folds=3)
def performance(x_train, y_train, x_test, y_test,C=None,kernel=None,epsilon=None):
    # fit the model
    if kernel<1:
        ke='poly'
    elif kernel<2:
        ke='rbf'
    else:
        ke='sigmoid'
    model = SVR(C=float(C),
                kernel=ke,
                gamma='scale',
                epsilon=float(epsilon)
                                  )

    scores=-np.mean(cross_val_score(model, X, y, cv=3, n_jobs=-1,
                                    scoring="neg_mean_squared_error"))

    return scores

optimal_configuration, info, _ = optunity.minimize(performance,
                                                  solver_name='particle swarm',
                                                  num_evals=20,
                                                   **search
                                                  )

Any help to solve this issue would be appreciated.

this is the traceback ive received:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-165-280687c322ce> in <module>()
     30                                                   solver_name='particle swarm',
     31                                                   num_evals=20,
---> 32                                                    **search
     33                                                   )
     34 print(optimal_configuration)

13 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/series.py in _get_values_tuple(self, key)
    954 
    955         if not isinstance(self.index, MultiIndex):
--> 956             raise KeyError("key of type tuple not found and not a MultiIndex")
    957 
    958         # If key is contained, would have returned by now

KeyError: 'key of type tuple not found and not a MultiIndex'

Upvotes: 0

Views: 1824

Answers (1)

Sarim Sikander
Sarim Sikander

Reputation: 406

The key for search isnt of type tuple, as you can see the second key of your search dictionary is getting value as a list. I thing you should change the kernel to either a tuple or a single value in tuple.

Upvotes: 0

Related Questions