from sklearn.cross_validation import train_test_split
/Users/zjx/anaconda3/lib/python3.6/site-packages/sklearn/cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
“This module will be removed in 0.20.”, DeprecationWarning)
翻译:该模块在0.18版本中被弃用,支持所有重构的类和函数都被移动到的model_selection模块。 另请注意,新的CV迭代器的接口与本模块的接口不同。 此模块将在0.20中删除。
解决办法:将“from sklearn.cross_validation import train_test_split” 改为“from sklearn.model_selection import train_test_split”
>>> import numpy as np
>>> from sklearn.model_selection import train_test_split
>>> X, y = np.arange(10).reshape((5, 2)), range(5)
>>> X
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> list(y)
[0, 1, 2, 3, 4]
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, test_size=0.33, random_state=42)
...
>>> X_train
array([[4, 5],
[0, 1],
[6, 7]])
>>> y_train
[2, 0, 3]
>>> X_test
array([[2, 3],
[8, 9]])
>>> y_test
[1, 4]
>>> train_test_split(y, shuffle=False)
[[0, 1, 2], [3, 4]]
Parameters: | *arrays : sequence of indexables with same length / shape[0]
test_size : float, int, None, optional
train_size : float, int, or None, default None
random_state : int, RandomState instance or None, optional (default=None)
shuffle : boolean, optional (default=True)
stratify : array-like or None (default is None)
|
---|---|
Returns: | splitting : list, length=2 * len(arrays)
|
参考文章:
http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html