Reputation: 1260
I was wandering if it possible to train the SVM classifier from sklearn in Python many times inside a for loop. I have in mind something like the following:
for i in range(0,10):
data = np.load(somedata)
labels = np.load(somelabels)
C = SVC()
C.fit(data, labels)
joblib.dump(C, 'somefolderpath/Model.pkl')
I want my model to be trained for each one of the 10 data and their labels. Is that possible in that way or do i have to append all the data and labels into two corresponding arrays containing the whole data and labels from my 10 items?
EDITED: If i want to train a separate classifier for each subject. Then how would the above syntax look like? Is my edit correct? And when i want to load the specific trained classifier for my specific subject, can i do:
C = joblib.load('somefolderpath/Model.pkl')
idx = C.predict(data)
?
Upvotes: 3
Views: 5999
Reputation: 28758
Calling fit
on any scikit-learn estimator will forget all the previously seen data. So if you want to make predictions using all of your data (all ten patients), you need to concatenate it first.
In particular, if each somelabels
contains only a single label, the code doesn't make sense and might even error because only one class is present.
Upvotes: 8