Closed oscarcastrolopez closed 5 years ago
Yes, it is the correct way. After load_from_file, you needn't to fit again for mysvm. You can directly use mysvm to do prediction.
mysvm = SVC()
mysvm.load_from_file('mymodel.txt')
mysvm.predict(your_data)
Hello
I have tried to load one pre-trained linear svm but getting the same initial model parameter even after loading my pre-trained model. Can anyone help me to solve this?
svm_model = SVC() print(svm_model)
SVC(C=1.0, cache_size=None, class_weight=None, coef0=0.0, decison_function_shape='ovo', degree=3, gamma='auto', kernel='rbf', max_iter=-1, max_mem_size=-1, n_jobs=-1, probability=False, random_state=None, shrinking=False, tol=0.001, verbose=False)
svm_model.load_from_file(input_svm_model_file) print(svm_model)
SVC(C=1.0, cache_size=None, class_weight=None, coef0=0.0, decison_function_shape='ovo', degree=3, gamma='auto', kernel='rbf', max_iter=-1, max_mem_size=-1, n_jobs=-1, probability=False, random_state=None, shrinking=False, tol=0.001, verbose=False)
Thanks
Hi, @soumitrasamanta
When you load the model, the parameters inside the model actually have been changed but we forgot to change the scikit parameters that you print. Now we have fixed the bug. You can try again. Thanks.
Hi @GODqinbin,
Thanks for your quick help and clarification. I have tried with the current version with the python example and the model perfectly works. Though it's a minor maybe you forgot to change the "C" parameter in scikit. I checked with this:
from thundersvmScikit import from sklearn.datasets import
x,y = load_svmlight_file("../dataset/test_dataset.txt") clf = SVC(verbose=False, kernel='linear', C=0.01) clf.fit(x,y) clf.save_to_file('best_trained_model') print(clf)
SVC(C=0.01, cache_size=None, class_weight={}, coef0=0.0, decison_function_shape='ovo', degree=3, gamma='auto', kernel='linear', max_iter=-1, max_mem_size=-1, n_jobs=-1, probability=False, random_state=None, shrinking=False, tol=0.001, verbose=False)
pretrained_clf = SVC() print(pretrained_clf)
SVC(C=1.0, cache_size=None, class_weight=None, coef0=0.0, decison_function_shape='ovo', degree=3, gamma='auto', kernel='rbf', max_iter=-1, max_mem_size=-1, n_jobs=-1, probability=False, random_state=None, shrinking=False, tol=0.001, verbose=False)
pretrained_clf.load_from_file('best_trained_model') print(pretrained_clf)
SVC(C=1.0, cache_size=None, class_weight=None, coef0=0.0, decison_function_shape='ovo', degree=3, gamma='auto', kernel='linear', max_iter=-1, max_mem_size=-1, n_jobs=-1, probability=0, random_state=None, shrinking=False, tol=0.001, verbose=False)
Thanks
Hi @soumitrasamanta ,
Like LIBSVM, we didn't save the "C" parameter in the model file, which seems useless in the prediction. So the "C" parameter you print is the default value. You can open the model file and see the information that we stored. Thanks.
Hello
Using the python wrapper, suppose I have a saved a SVC model trained with the GPU with the mysvm.save_to_file('mymodel.txt') function.
How can i load it after? I've already tried with the following code, but nothing happens: mysvm = SVC() mysvm.load_from_file('mymodel.txt')
Is this the correct way to do it?
Thanks