如何在多种类型的功能上训练svm(how to train svm on multiple type features)

编程入门 行业动态 更新时间:2024-10-25 09:39:58
如何在多种类型的功能上训练svm(how to train svm on multiple type features)

我想在由特征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.

更多推荐

本文发布于:2023-04-29 09:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多种   类型   功能   如何在   svm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!