# How to tune the hyperparameters for oneclass SVM while doing unsupervised learning?

For my task, I am doing unsupervised learning and I am trying to find the best possible value of the parameters gamma and nu in OneClassSVM.

I did the following:

nus = [0.001, 0.01, 0.1, 1]
gammas = [0.001, 0.01, 0.1, 1]
tuned_parameters = {'kernel' : ['rbf'], 'gamma' : gammas, 'nu': nus}
tuned_ocsvm = OneClassSVM()
clf = GridSearchCV(tuned_ocsvm, tuned_parameters, cv=10)
clf.predict(maximum.values[:,[1]])


and I am getting, the following error:

NotFittedError: This GridSearchCV instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.


The above error makes sense since the instance wasn't fitted which led me to to do this:

nus = [0.001, 0.01, 0.1, 1]
gammas = [0.001, 0.01, 0.1, 1]
scores = ['recall']
tuned_parameters = {'kernel' : ['rbf'], 'gamma' : gammas, 'nu': nus}
tuned_ocsvm = OneClassSVM()
clf = GridSearchCV(tuned_ocsvm, tuned_parameters, cv=10, scoring = scores, refit = False)
clf.fit(maximum.values[:,[1]])


and this gave the following error:

TypeError: __call__() missing 1 required positional argument: 'y_true'


But I don't have the 'true' values available since I am doing unsupervised learning.

Is there any other way the best parameters can be found for the same?

• What unsupervised problem are you trying to tackle? Clustering? Outlier prediction? Density estimation? – Rickyfox Apr 11 at 18:52
• @Rickyfox: Both clustering and outliers – Junkrat Apr 11 at 21:17