TypeError: unsupported operand type(s) for +: 'dict' and 'dict'

Viewed 36

I am tryin to get average of the range, but i get the Error. I hope someone can help me!

average = []
for i in range (0 , 5):

    clf = GridSearchCV( SVC(), param_grid={
        'gamma' : [1, 2, 3, 4, 5],
        'C' : [1, 2, 3, 4, 5]
    
    }, cv = RepeatedKFold())

    clf.fit(sc.transform(x_train), y_train)

    average.append(clf.best_params_)

print(np.mean(average))
1 Answers

clf.best_params_ returns a dict so you can't directly take the mean of it. Instead, you need to take the mean of the individual values. For example:

average_gamma = np.mean([v['gamma'] for v in average])
average_C = np.mean([v['C'] for v in average])
Related