python - AttributeError:“cupy.core.core.ndarray”对象没有属性“iloc”
问题描述
我正在尝试将数据拆分为训练和验证数据,为此我train_test_split
从cuml.preprocessing.model_selection
模块中使用。
但出现错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-317-4e11838456ea> in <module>
----> 1 X_train, X_test, y_train, y_test = train_test_split(train_dfIF,train_y, test_size=0.20, random_state=42)
/opt/conda/lib/python3.7/site-packages/cuml/preprocessing/model_selection.py in train_test_split(X, y, test_size, train_size, shuffle, random_state, seed, stratify)
454 X_train = X.iloc[0:train_size]
455 if y is not None:
--> 456 y_train = y.iloc[0:train_size]
457
458 if hasattr(X, "__cuda_array_interface__") or \
AttributeError: 'cupy.core.core.ndarray' object has no attribute 'iloc'
虽然我没有使用 iloc。
这是代码:
from cuml.preprocessing.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(train_dfIF,train_y, test_size=0.20, random_state=42)
这train_dfIF
是一个 cudf DataFrame 并且train_y
是 cupy 数组。
解决方案
y
如果您的X
参数是数据框,则不能(当前)将数组传递给参数。我建议传递两个数据帧或两个数组,而不是一个一个。
from cuml.preprocessing.model_selection import train_test_split
import cudf
import cupy as cp
df = cudf.DataFrame({
"a":range(5),
"b":range(5)
})
y = cudf.Series(range(5))
# train_test_split(df, y.values, test_size=0.20, random_state=42) # fail
X_train, X_test, y_train, y_test = train_test_split(df, y, test_size=0.20, random_state=42) # succeed
X_train, X_test, y_train, y_test = train_test_split(df.values, y.values, test_size=0.20, random_state=42) # succeed
推荐阅读
- java - 无法使用 Apache log4j2/slf4j 发送错误邮件
- python - 如何获得价值
- 使用scrapy spider python
- java - 计算我 dp 错误的高度
- android - Kotlin / Native 将 android 日志导入 android 共享代码模块时遇到问题
- c++ - C++ 使用裸指针,而不是智能指针
- sql - STRING_AGG with line break
- node.js - 如何使用节点连接 ftps 并上传文件
- python-3.x - 在数据框中查找节点的更简单方法
- sorting - 在快速排序程序集中执行递归调用的问题
- c# - C# - 如何在线临时流式传输文件以访问 URL