【问题标题】:train_test_split for multiple targetstrain_test_split 用于多个目标
【发布时间】:2021-05-19 14:03:37
【问题描述】:

我有多目标问题。我有两个目标ylo 和yhi 共享相同的功能x:

x = np.array([[0,1,2],[2,3,4]])
ylo = np.array([10,11])
yhi = np.array([12,13])

有没有办法从sklearn.model_selection.train_test_split 拆分数据以得到x_train、x_test、ylo_train、ylo_test、yhi_train、yhi_test?还是有其他更好的功能?

到目前为止,我必须进行两次拆分:

X_train, X_test, ylo_train, ylo_test = train_test_split(
    X, ylo,test_size=0.19, random_state=1)

_, _, yhi_train, yhi_test = train_test_split(
    X, yhi,test_size=0.19, random_state=1)

【问题讨论】:

    标签: python scikit-learn train-test-split


    【解决方案1】:

    您可以将它们放在一个数据框中,然后在各个列上进行训练

    from sklearn.model_selection import train_test_split
    import pandas as pd
    import numpy as np
    
    X_train, X_test, y_train, y_test = train_test_split(x,
    pd.DataFrame({'ylo':ylo,'yhi':yhi}),test_size=0.19, random_state=1)
    

    【讨论】:

      猜你喜欢
      • 2021-07-08
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 2015-02-16
      • 2023-04-10
      • 2020-07-29
      相关资源
      最近更新 更多