基于sciki的支持向量机训练中的输入形状错误

2024-05-29 04:35:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我对scikit和ML有点陌生,我正在尝试为一对所有分类训练一个支持向量机分类器。我使用以下代码。

g=list()
for i in range(0,120):
    g.append(1)
for i in range(120,240):
    g.append(2)

u=set(g)
numclasses=len(u)

lin_clf = svm.LinearSVC()
lin_clf.fit(features,u)

特点是72900*120阵列。我从一个不同的python代码中获取特性并在这里调用它。它抛出以下警告和错误。

/usr/lib/python2.7/dist-packages/scipy/misc/pilutil.py:279: 
DeprecationWarning: fromstring() is deprecated. Please call frombytes() instead.
image = Image.fromstring(mode, shape, strdata)

错误

ValueError: bad input shape ()

如果需要特征提取的代码,请发表评论。提前谢谢你。


Tags: 代码infor错误分类rangescikit向量
1条回答
网友
1楼 · 发布于 2024-05-29 04:35:05

哪一行代码抛出了错误?是不是lin_clf.fit(features,u)

根据LinearSVC的documentation,参数fit(X,y)

X : {array-like, sparse matrix}, shape = [n_samples, n_features]

Training vector, where n_samples in the number of samples and n_features is the number of features.

y : array-like, shape = [n_samples]

Target vector relative to X

但是,代码中的u是一个python set。它应该是一个长度为72900的numpy数组。

相关问题 更多 >

    热门问题