简体   繁体   English

尝试在 jupyter notebook 中拆分数据时出错

[英]Error when trying to split the data in jupyter notebook

Code:代码:

import glob
import pandas as pd
from sklearn.model_selection import train_test_split 

files = glob.glob("filepath/*.csv",)
df = [pd.read_csv(f, header=None, sep=";") for f in files]

data = pd.concat(df,ignore_index=True)

X_train, X_test, y_train, y_test = train_test_split(data, test_size=0.33, random_state=42)

Error: ValueError: not enough values to unpack (expected 4, got 2)错误:ValueError:没有足够的值来解包(预期为 4,得到 2)

As per scikit-doc The number of return list will be 2 * len(arrays) .根据scikit-doc返回列表的数量将为2 * len(arrays) Since you are only giving it a single "array" which is data , train_test_split will split your dataframe in 2, X_train, X_test .由于您只给它一个“数组”,即datatrain_test_split会将您的数据帧拆分为 2, X_train, X_test

X_train, X_test = train_test_split(data, test_size=0.33, random_state=42)

If your dataframe contains the X and Y data, you can do如果您的数据框包含 X 和 Y 数据,则可以执行

X_train, X_test, y_train, y_test = train_test_split(data['X'], data['Y'], test_size=0.33, random_state=42)

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

相关问题 尝试启动 Jupyter 笔记本时出现 DLL 错误 - DLL Error when trying to launch Jupyter notebook 尝试在 Colab 中拟合模型时出错,但在 Jupyter 笔记本中工作正常 - Error when trying to fit the model in Colab but works fine in Jupyter notebook 尝试运行我的 Jupyter Notebook 时出现错误 13 - Error 13 When trying to run my Jupyter Notebook 尝试在 jupyter notebook 上运行 sql 命令时出错 - Error when Trying to run an sql command on jupyter notebook 尝试在Jupyter Notebook中显示本地图像时出现语法错误 - Syntax error when trying to display a local image in jupyter notebook 尝试启动 Jupyter Notebook (Python) 时出现运行时错误 - Runtime Error when trying to launch Jupyter Notebook (Python) 尝试运行 jupyter notebook 时模块“attr”中的错误 - error in module 'attr' when trying to run jupyter notebook 在 jupyter notebook 中可视化开普勒 gl 中的数据时出错 - Error when visualizing data in kepler gl in jupyter notebook 尝试运行 next(iter(train_data_loader)) 时遇到 Broken Pipe 错误。 我在本地 jupyter notebook 中运行代码 - Facing Broken Pipe error when trying to run the next(iter(train_data_loader)). I'm running the code in local jupyter notebook 尝试运行 jupyter notebook 时导入错误 - Import error while trying to run jupyter notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM