问题1:试了几组不同的数据,效果都差不多,都是正弦的趋势,并没有很符合原数据的趋势,这是什么原因啊?
代码如下:
from sklearn import svm
import matplotlib.pyplot as plt
import numpy as np
X = [[300], [301], [302], [303], [304], [305], [306], [307], [308], [309], [310], [311], [312], [313], [314], [315], [316], [317], [318], [319],[320],[321], [322], [323], [324], [325], [326], [327], [328], [329], [331], [332], [333], [334], [335], [336], [337], [338], [339], [340], [341], [342], [343], [344], [345], [346], [347], [348], [349], [350], [351], [352], [353], [354], [355], [356], [357], [358], [359], [360]]
y = [1681, 1680, 1678, 1675, 1672, 1670, 1670, 1668, 1666, 1665, 1664, 1664, 1663, 1664, 1666, 1666, 1667, 1669, 1671, 1672, 1673, 1675, 1677, 1679, 1680, 1680, 1684, 1687, 1691, 1693, 1700, 1703, 1706, 1709, 1711, 1712, 1717, 1720, 1722, 1724, 1726, 1729, 1731, 1733, 1736, 1738, 1740, 1741, 1742, 1744, 1746, 1748, 1750, 1751, 1753, 1754, 1756, 1757, 1758, 1759]
regr = svm.SVR()
regr.fit(X, y)
x2=np.random.uniform(300,360,size=100)
x3=x2.reshape(-1,1)
y1 = regr.predict(x3)
print(y1)
plt.title('SVR')
plt.scatter(x3,y1,marker='.')
plt.plot(X,y,marker='o',color='k')
print(x3)
x4=[[330]]
y3=regr.predict(x4)
print('y_predict=', y3)
error=abs(y3-1697)/1697
print('error=', error)
plt.xlabel('A')
plt.ylabel('B')
plt.show()
效果如下:

问题2:我的原始数据里的y其实并不是1000多而是1点多,但是我用原始的1点多进行训练,预测出来的都是一条水平线,乘一千倍后训练才得到了上图的预测(蓝点),这个我也不知道是什么原因。
.
以上两个问题求指点,非常感谢!