machine-learning - 为什么我们在 train_test_split 的两个数组中都包含目标类?
问题描述
X_train, test_df, y_train, y_test = train_test_split(result, y_true, stratify = y_true, test_size = 0.2)
在上面使用 train_test_split 的示例中,result
是数据帧,并且y_true
是从数据帧的目标类列形成的 numpy 数组。
我的问题是,如果我们已经分别给出了“y_true”,为什么我们还要将整个“结果”数据框作为 train_test_split 中的输入参数之一?我的意思是,我们不应该首先从“结果”数据框中排除目标类列吗?
解决方案
Scikit-learn 支持 pandas,但 pandas 不是必需的。对于 numpy 数组,将特征和标签放在同一个数组中并不总是有意义的,因此是train_test_split
函数的当前设计。因此,您需要确保您的result
DataFrame 及其拆分具有您想要的格式。如果y_true
是result
DataFrame 的一部分,您可以(并且应该)选择在函数调用之前或之后将其排除。
推荐阅读
- rest - 无法捕获从另一个函数抛出的异常
- php - 视频上传器,上传后尝试显示视频播放器
- javascript - 是否可以覆盖 JS 中的 window.location.hostname 值
- c# - Unity Android 在图库中保存屏幕截图
- reactjs - useContext 给出未定义的
- node.js - 为什么即使指定的挂载路径不是它自己的,中间件也会被调用?
- r - 按部分字符串匹配分组
- android-management-api - 在 Android Management API Policy 中启用设备的相机应用
- php - 无法在 wamp 中登录 phpmysql 也与会话有关
- android - 在 Android Studio 3.6 中禁用 Gradle 离线模式