Python:方法 .as_matrix 将在未来版本中删除.使用 .values 代替 [英] Python: Method .as_matrix will be removed in a future version. Use .values instead
问题描述
我有以下代码
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屋!