使用GridSearchCV和OneClassSVM时,`NU`值有错误

问题描述 投票:0回答:1

我正在使用GridSearchCV查找适合我的模型OneClassSVM的最佳参数。我已经阅读了文档,其中nu值应介于0和1之间。在我的代码中,我总是会出错:

ValueError: nu <= 0 or nu > 1

我在做什么错?

import pandas as pd
from sklearn.svm import OneClassSVM

from sklearn.model_selection import GridSearchCV

import numpy as np

df = pd.read_csv('pitanja.csv')
#print(df)

x = df.iloc[:,:-1]

tuned_svm = {'cache_size':[70,80,90], 'coef0':[0.25,0.5,0.75], 'gamma':['auto'],
             'kernel':['poly','rbf','linear','sigmoid', 'precomputed'], 'random_state':[None],
             'shrinking':[True,False], 'tol':[0.05,0.1,0.2], 'verbose':[True],
             'nu':[0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24,0,25,0.26,0.27]}

def scorer_f(estimator, X):   #your own scorer
      return np.mean(estimator.score_samples(X))

out_cls = GridSearchCV(OneClassSVM(), tuned_svm, scorer_f)          

r = df

model = out_cls .fit(x)
prediction = model.predict(x)

print(model.best_params_)
python scikit-learn outliers
1个回答
1
投票

发现错误:

'nu':[0.1、0.11、0.12、0.13、0.14、0.15、0.16、0.17、0.18、0.19、0.2、0.21、0.22、0.23、0.24,0,25,0.26、0.27]] >

如果您厌倦了手动输入这些值,建议使用'nu':[0.1, np.linspace(0.11,0.27,17)]

© www.soinside.com 2019 - 2024. All rights reserved.