问题描述
X=latest_df[['open','high','low','volume','market']]
y=latest_df['close']
y = np.where(df['close'].shift(-1) > df['close'],1,-1)
X = pd.DataFrame(X)
y = pd.DataFrame(y)
a = X.shape
b = y.shape
随机导入
随机种子(1234)
从 sklearn.model_selection 导入 train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=101)
**X.shape = (9,5)
y.shape = (11623,1)**
解决方法
您遇到该错误是因为您的 X 和 Y 的长度不同(这是 train_test_split 要求的),即 X.shape[0] != Y.shape[0]。
访问 this 以获取参考。