我的线性回归简单预测不会执行



以下是我的试用码:

from sklearn import linear_model
# plt.title("Time-independent variant student performance analysis")
x_train = [5, 9, 33, 25, 4]
y_train = [35, 2, 14 ,9, 7]
x_test = [14, 2, 8, 1, 11]
# create linear regression object
linear = linear_model.LinearRegression()
#train the model using the training sets and check score
linear.fit(x_train, y_train)
linear.score(x_train, y_train)
# predict output
predicted = linear.predict(x_test)

运行时,这是输出:

值错误:发现样本数不一致的数组:[1 5]

重新定义

x_train = [[5],[9],[33],[25],[4]]
y_train = [35,2,14,9,7]
x_test = [[14],[2],[8],[1],[11]]

来自fit(X, y)文档:X:形状[n_samples,n_features]的numpy数组或稀疏矩阵

在您的情况下,每个示例只有一个功能。

相关内容

  • 没有找到相关文章

最新更新