本文主要是介绍[tensorflow] sklearn包中label_binarize和model_selection.train_test_split,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
sklearn文档:
https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.label_binarize.html#sklearn.preprocessing.label_binarize
sklearn.preprocessing.label_binarize
类的顺序被保留:
from sklearn.preprocessing import label_binarize
label_binarize([1, 6], classes=[1, 2, 4, 6])
# 1 4个特征2值化 转换成 [1,0,0,0]
array([[1, 0, 0, 0],[0, 0, 0, 1]])
二元目标转换为列向量:
label_binarize(['yes', 'no', 'no', 'yes'], classes=['no', 'yes'])
array([[1],[0],[0],[1]])
model_selection.train_test_split
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size =.3,random_state=0)
from sklearn import cross_validation ##这个将被弃用,被移动在model_selection模块内
X_train,X_test,y_train,y_test = cross_validation.train_test_split(X,y,test_size=.3,random_state=0)
这篇关于[tensorflow] sklearn包中label_binarize和model_selection.train_test_split的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!