opencv 名称'X'未定义[如何修复]

fxnxkyjh  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(160)

我试图执行代码,但问题显示为“Name 'X' is not defined”“如果没有,我如何定义它以使代码运行。

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)


todo_check([
    (X_train.shape == (413, 29), 'X_train does not have the correct shape (413, 29)'),
    (X_test.shape == (104, 29), 'X_test does not have the correct shape (104, 29)'),
    (y_train.shape == (413,), 'y_train does not have the correct shape (413,)'),
    (y_test.shape == (104,), 'y_test does not have the correct shape (104,)'),
    (np.all(np.isclose(X_train.values[-5:, -4], np.array([17.7, 18.2, 21.8, 23.8, 20.1]),rtol=.01)), 'X_train does not contain the correct values! Make sure you used `X` when splitting!'),
    (np.all(np.isclose(y_test.values[-5:], np.array([1.25561604, 1.8531681 , 1.15373159, 4.01259206, 3.56558124]),rtol=.01)), 'y_test does not have the correct values! Make sure you used `y` when splitting!')
])

`
我希望代码能够完整地构造并找出X未定义的原因以及如何编译它

8yparm6h

8yparm6h1#

您正在使用train_test_split函数:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)

训练测试拆分(Xy....
但是你从来没有定义过X(或者y)。
您需要为函数提供数据。

  • X是什么?
  • y是什么?

一旦定义了这些变量,错误就会消失。

相关问题