繁体   English   中英

要解包的值太多(预期为2)?

[英]too many values to unpack (expected 2)?

我有要使用的数据框,当我测试/拆分数据时会弹出此错误消息

太多值无法解包(预期2)

我只是将train_test_split的目标列Global设置为y值,其余列设置为X。 不确定从哪里开始解决此问题

X = df[['Year_of_Release', 'Critic_Score', 'Critic_Count',
       'User_Score', 'User_Count', 'Platform_PC', 'Platform_PS3',
       'Platform_PS4', 'Platform_Wii', 'Platform_X360',
       'Platform_XOne', 'Genre_Action', 'Genre_Adventure', 'Genre_Fighting',
       'Genre_Misc', 'Genre_Platform', 'Genre_Puzzle', 'Genre_Racing',
       'Genre_Role-Playing', 'Genre_Shooter', 'Genre_Simulation',
       'Genre_Sports', 'Genre_Strategy', 'Rating_E', 'Rating_E10+', 'Rating_M',
       'Rating_RP', 'Rating_T']]

y = df[['Global']]

print(X.shape)
print(y.shape)

from sklearn.model_selection import train_test_split

X_train, X_test = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state=42)


X_train, X_val = train_test_split(X_train, train_size=0.8, test_size=0.2, random_state=42)

target = 'Global'
y_train = X_train[target]
y_val = X_val[target]
y_test = X_test[target]

X_train = X_train.drop(columns=target)
X_val = X_val.drop(columns=target)
X_test = X_test.drop(columns=target)

X_train.shape, y_train.shape, X_val.shape, y_val.shape, X_test.shape, y_test.shape

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-75-d3fede999d7b> in <module>()
      1 from sklearn.model_selection import train_test_split
      2 
----> 3 X_train, X_test = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state=42)
      4 
      5 

ValueError: too many values to unpack (expected 2)

sklearn的train_test_split返回4个值X_Train和y_train以及X_test y_test。 请参阅此处的官方文档。

另外,您应指定测试尺寸火车尺寸

X = df[['Year_of_Release', 'Critic_Score', 'Critic_Count',
       'User_Score', 'User_Count', 'Platform_PC', 'Platform_PS3',
       'Platform_PS4', 'Platform_Wii', 'Platform_X360',
       'Platform_XOne', 'Genre_Action', 'Genre_Adventure', 'Genre_Fighting',
       'Genre_Misc', 'Genre_Platform', 'Genre_Puzzle', 'Genre_Racing',
       'Genre_Role-Playing', 'Genre_Shooter', 'Genre_Simulation',
       'Genre_Sports', 'Genre_Strategy', 'Rating_E', 'Rating_E10+', 'Rating_M',
       'Rating_RP', 'Rating_T']]

y = df[['Global']]

print(X.shape)
print(y.shape)

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM