Reputation: 24613
I am trying following simple example:
from sklearn import datasets, svm
iris = datasets.load_iris()
clf = svm.SVC(random_state=0)
For fitting, should I use following statement:
clf = clf.fit(iris.data, iris.target)
Or just:
clf.fit(iris.data, iris.target)
Both above formats have been used in different places, so I am confused.
The first method clf = clf(X,y).fit()
seems to be the official version (see here).
I have tried and found that both seem to work, but I may be missing some point here.
Upvotes: 1
Views: 471
Reputation: 5324
They both perform the same. The fit()
function modifies the states of the estimator and returns it. It is used so that you can write a one-liner such as:
clf = svm.SVC(random_state=0).fit(iris.data, iris.target)
Upvotes: 1