def trainSVM(kernel, labels): #need to add an id number as the first column of the list svmKernel = column_stack((arange(1, len(kernel.tolist()) + 1), kernel)) prob = svm_problem(labels.tolist(), svmKernel.tolist(), isKernel=True) param = svm_parameter('-t 4') model = svm_train(prob, param) return model
def test_generator(self): with assert_warns(FutureWarning): column_stack((np.arange(3) for _ in range(2)))
def test_column_stack_and_vstack(self): a=array([4.,2.]) b=array([2.,8.]) numpy.testing.assert_array_equal(column_stack((a[:,newaxis],b[:newaxis])), array([[4.,2.],[2.,8.]])) numpy.testing.assert_array_equal(vstack((a[:,newaxis],b[:,newaxis])), array([[4.],[2.],[2.],[8.]]))
def predictSVM(model, testKernel): svmTestKernel = column_stack(([0] * len(testKernel), testKernel)) #svm_predict returns 3 things - we want the first one, hense the [0] at the end of the following line predictedLabels = svm_predict([0] * len(svmTestKernel), svmTestKernel.tolist(), model)[0] return predictedLabels