Python:方法 .as_matrix 将在未来版本中删除.使用 .values 代替 [英] Python: Method .as_matrix will be removed in a future version. Use .values instead

查看:127
本文介绍了Python:方法 .as_matrix 将在未来版本中删除.使用 .values 代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

train_X, test_X, train_y, test_y = train_test_split(X.as_matrix(), y.as_matrix(), test_size=0.25)

其中 X 是一个 DataFrame 而 y 是一个系列.调用上面的函数时,我收到以下警告:

where X is a DataFrame and y is a series. When calling the function above, I get the following warning:

/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: Method .as_matrix 将在未来版本中删除.改用 .values.

/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.

"""启动 IPython 内核的入口点.

"""Entry point for launching an IPython kernel.

然后我尝试使用警告中提到的 .values 进行更改:

Then I tried to change using .values as mentioned in the warning:

train_X, test_X, train_y, test_y = train_test_split(X.values(), y.values(), test_size=0.25)

但我收到以下错误:

TypeError Traceback(最近一次调用最后一次)在 ()----> 1 train_X, test_X, train_y, test_y = train_test_split(X.values(), y.values(), test_size=0.25)

TypeError Traceback (most recent call last) in () ----> 1 train_X, test_X, train_y, test_y = train_test_split(X.values(), y.values(), test_size=0.25)

TypeError: 'numpy.ndarray' 对象不可调用

TypeError: 'numpy.ndarray' object is not callable

我该如何解决这个问题?

How do I solve this?

推荐答案

应该是:

train_X, test_X, train_y, test_y = train_test_split(X.values, y.values, test_size=0.25)

参见这个.

这篇关于Python:方法 .as_matrix 将在未来版本中删除.使用 .values 代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆