python-3.x - TabNetRegressor 不适用于重塑的数据
问题描述
我正在使用 tabnet 的 PyTorch 实现,但无法弄清楚为什么我仍然会收到此错误。我将数据导入数据框,我使用这个函数来获取我的 X,然后是我的训练测试拆分
def get_X_y(df):
''' This function takes in a dataframe and splits it into the X and y variables
'''
X = df.drop(['is_goal'], axis=1)
y = df.is_goal
return X,y
X,y = get_X_y(df)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=101)
然后我用它来重塑我的 y_train
y_train.values.reshape(-1,1)
然后创建模型的一个实例并尝试拟合它
reg = TabNetRegressor()
reg.fit(X_train, y_train)
我得到这个错误
ValueError: Targets should be 2D : (n_samples, n_regression) but y_train.shape=(639912,) given.
Use reshape(-1, 1) for single regression.
我理解为什么我需要重塑它,因为这很常见,但我不明白为什么它仍然给我这个错误。我已经在笔记本中重新启动了内核,所以我也不认为这是持久性内存问题。
解决方案
您必须重新分配它:
y_train = y_train.values.reshape(-1,1)
否则,它不会改变。
推荐阅读
- r - R shinydashboard 必须关闭 childfull menuItem 才能使 sidebarItemExpanded 工作
- android - 如何使 EditText 不可点击并隐藏键盘但使用 XML 显示光标
- java - 使用 ModelMapper 防止循环引用 - 列表
- spring-boot - 有没有办法在 spring-kafka 中配置自定义 RecordMessageConverter?
- python - 在我的 PYQT5 的 QTableWidget 中,使用 QHeaderView 类,我在其中设置了一个复选框:如何使用该复选框来确定我选择了哪一行?
- algorithm - 快速排序算法在最后两个元素上给出错误的输出
- python - python数组将numpy引用转换为非numpy
- class - 你如何在课堂上收集特殊物品?
- flutter - 颤振布局错误“底部的无限像素溢出的 RenderFlex”
- javascript - 从 JSON 文件中获取特定键/值对的数组