I have the following code
train_X, test_X, train_y, test_y = train_test_split(X.as_matrix(), y.as_matrix(), test_size=0.25)
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 will be removed in a future version. Use .values instead.
"""Entry point for launching an IPython kernel.
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)
But I get the following error:
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' object is not callable
How do I solve this?
It should be:
train_X, test_X, train_y, test_y = train_test_split(X.values, y.values, test_size=0.25)
See this.
According to Panda 0.25.1 documentation, they recommend more using DataFrame.to_numpy() than DataFrame.values()
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.values.html#pandas.DataFrame.values
So I'd like to suggest to update it like below:
train_X, test_X, train_y, test_y = train_test_split(X.to_numpy(), y.to_numpy(), test_size=0.25)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With