简体   繁体   中英

How can i train multiple times an SVM classifier from sklearn in Python?

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)

?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM