我想在由特征p1,p2,p3组成的数据集上训练svm。 p1是向量,p2和p3是我要训练的整数。 例如p1 = [1,2,3],p2 = 4,p3 = 5 X = [p1,p2,p3],但p1本身是一个向量,所以X = [[1,2,3],4, 5]和Y输出命名标签 但是X不能以这种形式输入
clf.fit(X,Y)它给出了下面的形式错误:意思是X不能采用这种形式array = np.array(array,dtype = dtype,order = order,copy = copy)ValueError:设置一个数组元素序列。
I want to train svm on data set consisting of features p1, p2 , p3 . p1 is vector , p2 and p3 are integers on which i want to train . For e.g p1=[1,2,3], p2=4 , p3=5 X=[p1 , p2 , p3],but p1 itself is a vector, so X=[ [ 1 , 2 , 3 ], 4 , 5 ] and Y is output named label but X can't take input in this form
clf.fit(X,Y) It gives error of form below: meaning X cannot take in this form array = np.array(array, dtype=dtype, order=order, copy=copy) ValueError: setting an array element with a sequence.
最满意答案
你基本上有两个选择:
将数据转换为常规格式并运行典型的SVM内核,在您的情况下,如果p1始终为3元素,则只展平表示,因此[[1,2,3],4,5]变为[1,2,3,4, 5]你很高兴去。
实现自己的自定义内核函数,分别处理每个部分,因为两个内核的总和仍然是内核,你可以定义K(x,y)= K([p1,p2,p3],[q1,q2, q3]):= K1(p1,q1)+ K2([p2,p3],[q2,q3])。 现在K1和K2都处理常规向量,因此您可以以任意方式定义它们,并将它们的和用作“关节”核函数。 这种方法更复杂,但您可以自由地定义处理复杂数据的方式。
You basically have two options:
Convert your data to regular format and run typical SVM kernel, in your case if p1 is always 3-element, just flatten representation thus [[1,2,3],4,5] becomes [1,2,3,4,5] and you are good to go.
Implement your own custom kernel function, that treats each part separately, since sum of two kernels is still a kernel, you can for example define K(x, y) = K([p1, p2, p3], [q1, q2, q3]) := K1(p1, q1) + K2([p2,p3], [q2,q3]). Now both K1 and K2 work on regular vectors, so you can define them in arbitrary manner and just use their sum as your "joint" kernel function. This approach is more complex, but gives you much freedom in how you define the way of dealing with your complex data.
更多推荐
发布评论