Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sklearn set_params takes exactly 1 argument?

I'm trying to use SkLearn Bayes classification.

 gnb = GaussianNB()  gnb.set_params('sigma__0.2')  gnb.fit(np.transpose([xn, yn]), y) 

But I get:

set_params() takes exactly 1 argument (2 given) 

now I try to use this code:

gnb = GaussianNB() arr = np.zeros((len(labs),len(y))) arr.fill(sigma) gnb.set_params(sigma_ = arr) 

And get:

ValueError: Invalid parameter sigma_ for estimator GaussianNB 

Is it wrong parameter name or value?

like image 203
Leonid Avatar asked Nov 25 '14 09:11

Leonid


People also ask

What is Set_params?

set_params(**params)[source] Set the parameters of this estimator. The method works on simple estimators as well as on nested objects (such as Pipeline ). The latter have parameters of the form <component>__<parameter> so that it's possible to update each component of a nested object.

What does fit () method do for Scikit learn objects?

The fit() method takes the training data as arguments, which can be one array in the case of unsupervised learning, or two arrays in the case of supervised learning.

What are two parameters passed in fit method?

fit method takes two parameters, the list of points and another list of just y coordinates. X are your data samples, where each row is a datapoint (one sample, a N-dimensional feature vector). y are the datapoint labels, one per datapoint.

What is estimator in Sklearn?

Fitting data: the main API implemented by scikit-learn is that of the estimator . An estimator is any object that learns from data; it may be a classification, regression or clustering algorithm or a transformer that extracts/filters useful features from raw data.


1 Answers

I just stumbled upon this, so here is a solution for multiple arguments from a dictionary:

from sklearn import svm params_svm = {"kernel":"rbf", "C":0.1, "gamma":0.1, "class_weight":"auto"} clf = svm.SVC() clf.set_params(**params_svm) 
like image 66
Kam Sen Avatar answered Oct 01 '22 10:10

Kam Sen