sklearn

sklearn

 

#划分训练集和测试集
#from sklearn import train_test_split   #py2
from sklearn import sklearn.model_selection  #py3
train_X,test_X,train_y,test_y = train_test_split(X,y,test_size=1/3,random_state=3)

 

from sklearn import cross_val_score 

 

#将n个类别编码为0~n-1之间的整数(包含0和n-1)
from sklearn import preprocessing  
label =preprocessing.LabelEncoder()  
label.fit(["A","A","B","C","E"])  

print('类别属性:%s'% label.classes_)  
print('类别编码:%s' % label.transform(["B", "A", "A"]))  
print('将编码转化为类别:%s' % label.inverse_transform([2, 2, 1])) 

 

posted @ 2019-10-20 18:36  熊猫blue  阅读(146)  评论(0编辑  收藏  举报