【问题标题】:Logistic Regression逻辑回归
【发布时间】:2020-01-31 08:31:45
【问题描述】:

我的数据从数据集 df 拆分为训练和测试。 我可以将训练和测试拆分为 X_train, Y_train from train 和 X_test, Y_test from test 吗?

示例代码:-

train, test = train_test_split(df, train_size=0.8, stratify=df.y_yes.values, random_state=5)

#Can I do the below splitting?
X_train, Y_train = train_test_split(train, random_state=5)
X_test, Y_test = train_test_split(test, random_state=5)

train.head and test.head

【问题讨论】:

  • Well tr​​ain amd test 已经包含了 x 和 y。只需使用 y 和 rest 的变量名过滤训练和测试,然后就可以了。而且 - 您的问题与逻辑回归无关,yoj 可能想要编辑您的标题。
  • 我不知道为什么我的问题被否决了。我无法弄清楚如何参加培训和测试,预测我的结果并计算 AUC。
  • 谢谢@FatihAkici,我会试试这个。
  • 原因可能是因为它太简单了(答案可以在任何教程中找到)或无法重现或显示不努力。请在您的帖子中分享 train.head() 和 test.head(),以便人们可以更好地帮助您。
  • "我无法弄清楚如何 [...]" - 是的,但你不会问 那个...对您“我可以吗?”问题的答案很简单(现在,这是否有意义,是另一个讨论)

标签: python scikit-learn


【解决方案1】:

我找不到解决办法,所以使用了正则拆分表达式:-

 X = df_clean[['previous', 'emp.var.rate', 'euribor3m', 'nr.employed', 
'pdays_missing', 'poutcome_success' , 'poutcome_nonexistent','pdays_bet_5_15']]
 y = df_clean['y_yes']
 X_train, X_test, Y_train, Y_test = train_test_split(X, y, test_size = 0.2, 
 random_state=5)
 print(X_train.shape)
 print(X_test.shape)
 print(Y_train.shape)
 print(Y_test.shape)

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 2018-01-26
    • 2020-03-22
    • 2016-12-01
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    相关资源
    最近更新 更多