当我尝试在python中实现一个简单的svm回归模型时,我能够预测整数值,但浮动值的预测不起作用。
代码:
from sklearn import svm
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
import numpy as np
data = np.genfromtxt("a.csv", dtype=None, delimiter=',')
print data
X=data[:,0:1]
y=data[:,1]
clf =svm.SVC()
clf.fit(X, y)
m=clf.predict([1.2])
print m
错误:
Traceback (most recent call last):
File "svm3.py", line 10, in <module>
clf.fit(X, y)
File "/home/narayan/.local/lib/python2.7/site-packages/sklearn/svm/base.py", line 151, in fit
y = self._validate_targets(y)
File "/home/narayan/.local/lib/python2.7/site-packages/sklearn/svm/base.py", line 515, in _validate_targets
check_classification_targets(y)
File "/home/narayan/.local/lib/python2.7/site-packages/sklearn/utils/multiclass.py", line 173, in check_classification_targets
raise ValueError("Unknown label type: %r" % y)
ValueError: Unknown label type: array([ 3.6, 6.6, 9.9])
CSV文件数据:
[[ 1.2 3.6]
[ 2.2 6.6]
[ 3.3 9.9]]
答案 0 :(得分:0)
以下是sklearn for SVR的代码
$id = $_POST['id'];
看看这块代码是否适合你。