導入特徵提取化中的字典向量化orm
from sklearn.feature_extraction import DictVectorizer it
dv = DictVectorizer ()io
x_train = dv.fit_transform(x_train)form
x_test = dv.fit_transform(x_test)test
此處的fit是找到當前字典中的鍵import
舉個例子:transform
若是x_test不fit,那x_test只能轉化x_train中的鍵,它不能轉化本身有可是x_train中沒有的鍵。im
固然若是兩者鍵名徹底相同,x_test能夠直接transform,兩者結果無區別。字典