Closed zhanglixuan0720 closed 4 years ago
The functions coded by myself in above code are as follow. def modifys(vector, num): vector = np.zeros(vector.shape) for i in range(len(vector)): if vector[i] <= num: vector[i] = 2 else: vector[i] = 0 return vector_
def equal(v1, v2): if len(v1) != len(v2): print("the length between v1 and v2 is not equal") return count = 0 for i in range(len(v1)): if v1[i] == v2[i]: count += 1 return count/len(v1)
Hello @zhanglixuan0720 Did you find the solution? I have the same issue too. Thanks!
Hello @zhanglixuan0720 Did you find the solution? I have the same issue too. Thanks!
Yes, I closed the issue after finding the solution. I found that the issue was caused by the data I provided to the trainer but not the algorithm itself. For mnist data set, the normalization operation may help you have a normal prediction result. The normalization operation will adjust the data to the interval [0,1].
I attempt to train mnist_784 using the Python interface,but it predicts the constant class when I using kernel 'rbf'. My codes are as follow.
from thundersvm import * import matplotlib.pyplot as plt import common as cn import numpy as np import pandas as pd from sklearn.datasets import fetch_mldata import scipy.sparse as sp
mnist = fetch_openml('mnist_784',)
mnist = pd.read_csv('/home/zhanglixuan/thundersvm/python/mnist_784.csv') mnist = mnist.values train_data, train_label, test_data, test_label = mnist[:60000, : 784], mnist[:60000:, 784:],\ mnist[60000:, :784], mnist[60000:, 784:] train_label = cn.modify_s(train_label, 5) test_label = cn.modify_s(test_label, 5)
clf = SVC(verbose=True, gamma=1, C=50, kernel='rbf', coef0=1., degree=5) clf.fit(train_data, train_label) predict = clf.predict(test_data)
acc = clf.score(test_data, test_label)
print(min(predict)) print(min(train_label))
clf.save_to_file('./model')
print("test score is ", cn.equal(predict, test_label))