【发布时间】:2021-01-08 17:21:24
【问题描述】:
我对在线 RE one hot encoding 有点困惑。我正在使用get_dummies 方法,但我不清楚是在train_test_split 之前或之后应用一种热编码。例如它是否正确?这是一种流行的方法,但这不会导致数据泄漏吗?
features = pd.get_dummies(features, columns=['country'], dummy_na=True)
X_train, X_test, y_train, y_test = train_test_split(features, y, random_state=0)
例如在我的情况下,火车包含所有国家,但测试集包含除德国以外的所有国家,但使用上述方式将使德国在我的测试集中使用一系列 0 和 1 进行热编码,因此不仅仅是一系列 0,因为它不存在。这对我来说似乎是错误的。
【问题讨论】:
-
请注意DataScienceSE 是解决这类非编程问题的更好地方。
-
我投票结束这个问题,因为它与 help center 中定义的编程无关,而是关于 ML 理论和/或方法 - 请参阅介绍和 注意 在
machine-learningtag info.
标签: python machine-learning scikit-learn categorical-data one-hot-encoding