【发布时间】:2020-09-21 05:56:05
【问题描述】:
我正在使用 SVM 来预测一个特定一维数据的未来值。数据包含 54 个月的销售值,其月份索引从 1 到 54。第一个问题是我认为 SVM 可以进行预测,但我不确定。据我所知,SVM 可以进行分类,但回归呢?谁能告诉我为什么 SVM 可以做回归?
在我的问题中,我尝试将 X 设置为月份索引,将 y 设置为每个月的值。我不太确定我是否做得对,因为没有标签(或者我已经厌倦了使用该值的标签)并且功能只是月份索引。
我尝试用from sklearn import svm 拟合它,得到的结果是训练集的准确率为 100%,测试集的准确率为 0。不知道哪里错了。
代码如下:
import pandas as pd
import numpy as np
df = pd.read_csv('11.csv', header=None, names = ['a', 'b', 'c'])
X = df['b'].values.reshape(-1,1)
y = df['c'].values.reshape(-1,1)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
from sklearn import svm
clf = svm.SVC(C=0.8, kernel='rbf', gamma=20, decision_function_shape='ovr')
clf.fit(X_train, y_train.ravel())
print("training result:",clf.score(X_train, y_train))
print("testing result:",clf.score(X_test,y_test))
数据集看起来像这样 X = [1, 2, 3, 4,...,53, 54] 和 y = [90, 18, 65, 150.... 289],一维数据集。
【问题讨论】:
标签: python machine-learning scikit-learn time-series svm