【发布时间】:2019-04-08 10:22:07
【问题描述】:
我有一个 Excel 文件,它在每一列中存储一个序列(从顶部单元格到底部单元格读取),并且序列的趋势与上一列相似。所以我想预测这个数据集中第 n 列的序列。
我的数据集样本:
看到每一列都有一组值/序列,当我们向右移动时它们会有所进展,所以我想预测例如Z 列中的值。
到目前为止,这是我的代码:
import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
# Read the Excel file in rows
df = pd.read_excel(open('vec_sol2.xlsx', 'rb'),
header=None, sheet_name='Sheet1')
print(type(df))
length = len(df.columns)
# Get the sequence for each row
x_train, x_test, y_train, y_test = train_test_split(
np.reshape(range(0, length - 1), (-1, 1)), df, test_size=0.25, random_state=0)
print("y_train shape: ", y_train.shape)
pred_model = LogisticRegression()
pred_model.fit(x_train, y_train)
print(pred_model)
我会尽量解释逻辑:
-
x_train和x_test将只是与序列关联的索引/列号。 -
y_train是一个序列数组。 - 总共有 51 列,因此将其拆分为 25% 为测试数据会产生 37 个训练序列和 13 个测试序列。
我在调试时设法得到了每个 var 的形状,它们是:
-
x_train: (37, 1) -
x_test: (13, 1) -
y_train: (37, 51) -
y_test: (13, 51)
但是现在,运行程序给了我这个错误:
ValueError: bad input shape (37, 51)
我的错误是什么?
【问题讨论】:
标签: python pandas scikit-learn prediction valueerror