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)
這會(huì)將數(shù)據(jù)分為培訓(xùn)投入
評(píng)估數(shù)據(jù)的輸入
培訓(xùn)數(shù)據(jù)輸出
評(píng)估數(shù)據(jù)的輸出
分別。您還可以添加關(guān)鍵字參數(shù):test_size=0.25,以改變用于培訓(xùn)和測(cè)試的數(shù)據(jù)百分比
要拆分單個(gè)數(shù)據(jù)集,可以使用如下調(diào)用來(lái)獲取40%的測(cè)試數(shù)據(jù):
^{pr2}$
總結(jié)
以上是生活随笔為你收集整理的python partition函数_在Python中相当于R的createDataPartition的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python2默认编码_解决Python
- 下一篇: python写一个自动登录脚本_Pyth