【发布时间】:2019-07-19 08:31:07
【问题描述】:
当尝试按列(分类)进行分层拆分时,它会返回错误。
Country ColumnA ColumnB ColumnC Label
AB 0.2 0.5 0.1 14
CD 0.9 0.2 0.6 60
EF 0.4 0.3 0.8 5
FG 0.6 0.9 0.2 15
这是我的代码:
X = df.loc[:, df.columns != 'Label']
y = df['Label']
# Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0, stratify=df.Country)
from sklearn.linear_model import LinearRegression
lm = LinearRegression()
lm.fit(X_train,y_train)
lm_predictions = lm.predict(X_test)
所以我得到如下错误:
ValueError: could not convert string to float: 'AB'
【问题讨论】:
-
无法重现错误(使用“Country”作为“country_code”)
-
@ChristianSloper 好点,已修复。谢谢
-
@LucaMassaron 你能帮忙吗?谢谢
标签: python machine-learning split scikit-learn linear-regression