python partition函数_在Python中相当于R的createDataPartition
在scikit learn中,您將獲得工具train_test_splitfrom sklearn.cross_validation import train_test_split
from sklearn import datasets
# Use Age and Weight to predict a value for the food someone chooses
X_train, X_test, y_train, y_test = train_test_split(table['Age', 'Weight'],
table['Food Choice'],
test_size=0.25)
# Another example using the sklearn pre-loaded datasets:
iris = datasets.load_iris()
X_iris, y_iris = iris.data, iris.target
X, y = X_iris[:, :2], y_iris
X_train, X_test, y_train, y_test = train_test_split(X, y)
這會將數據分為培訓投入
評估數據的輸入
培訓數據輸出
評估數據的輸出
分別。您還可以添加關鍵字參數:test_size=0.25,以改變用于培訓和測試的數據百分比
要拆分單個數據集,可以使用如下調用來獲取40%的測試數據:
^{pr2}$
總結
以上是生活随笔為你收集整理的python partition函数_在Python中相当于R的createDataPartition的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python2默认编码_解决Python
- 下一篇: python写一个自动登录脚本_Pyth