我正在尝试制作一个股票预测算法,并且几乎完成了-我只需要实现线性SVC算法。因此,我已经清理了数据,并且想使用train_test_split库拆分数据,以便可以在其上拟合预测模型。但是,当我尝试拆分数据时,出现此错误:
ValueError: Found input variables with inconsistent numbers of samples: [24, 2]
我非常细致,并验证了我所有的特征都相同的长度-以[[Feature1] [Feature2] [Feature3] [Feature4]]的格式,并且我的Y与数据的长度相同长度。
我正在使用时间轴2010/01/01-2010/01/10使其更具可读性。不幸的是,在查看了多个线程和一些文档之后,我无法弄清楚为什么我的拆分无法正常工作。如果您对发生的事情有了解,请告诉我。
预测变量类:
#I want to use Linear SVC
#Sci Kit Learn
class Predictor:
def __init__(self, stock):
from sklearn.svm import LinearSVC as lsvc
from sklearn.model_selection import train_test_split as tts
features = []
for i in stock.features:
inner = []
for ii in i.featureData:
inner.append(ii)
features.append(inner)
y = stock.two_list
clf = lsvc(random_state=0, tol=1e-5)
xTrain, xTest, yTrain, yTest = tts(features, y)
#clf.fit(xTrain, yTrain)
#>>> X_train, X_test, y_train, y_test = train_test_split(
#... X, y, test_size=0.33, random_state=42)
#print(clf.score(xTest, yTest))