November 2017
Intermediate to advanced
374 pages
10h 19m
English
Another option is to use DictVectorizer class. This can be used to directly convert strings to features:
from sklearn.feature_extraction import DictVectorizerdv = DictVectorizer()my_dict = [{'species': iris.target_names[i]} for i in y]dv.fit_transform(my_dict).toarray()[:5]array([[ 1., 0., 0.],
[ 1., 0., 0.],
[ 1., 0., 0.],
[ 1., 0., 0.],
[ 1., 0., 0.]])
Read now
Unlock full access