numpy - Why is LIBSVM in Python asking me for floating values? -
i'm implementing svm classification problem using libsvm in python. have numpy array of consisting of 1.0 , -1.0 called train_labels , corresponding features in numpy array called train_data. since libsvm not accept numpy arrays, convert them lists using code below.
train_labels = train_labels.tolist() train_data = train_data.tolist()
however, when put them on svm_problem as:
prob = svm_problem(train_labels,train_data)
i'm getting error
file "c:\anaconda\lib\site-packages\svm.py", line 109, in __init__ i, yi in enumerate(y): self.y[i] = yi typeerror: float required
i've tried converting them float using train_labels = train_labels.astype(np.float)
before converting list i'm still getting same error.
using tolist() method converting numpy array lists before putting them on libsvm commands working when i've tried them in console.
does know why i'm getting error? , how can solve it?
guys! after more idling in code, i've found what's wrong.
the line train_labels = train_labels.tolist()
converting array list of lists 1 element in sublist. think because train_labels n x 1 array start (it read csv file).
so need reshape first before converting list. , works.
train_labels = train_labels.reshape(n_train).tolist()
i hope it's ok still ask question here starting use libsvm in future.
thanks!
Comments
Post a Comment