Title: Loading Features From Dictionaries
Slug: loading_features_from_dictionaries
Summary: Loading Features From Dictionaries
Date: 2016-11-01 12:00
Category: Machine Learning
Tags: Preprocessing Structured Data
Authors: Chris Albon
In [1]:
from sklearn.feature_extraction import DictVectorizer
In [2]:
staff = [{'name': 'Steve Miller', 'age': 33.},
{'name': 'Lyndon Jones', 'age': 12.},
{'name': 'Baxter Morth', 'age': 18.}]
In [3]:
# Create an object for our dictionary vectorizer
vec = DictVectorizer()
In [4]:
# Fit then transform the staff dictionary with vec, then output an array
vec.fit_transform(staff).toarray()
Out[4]:
In [5]:
# Get Feature Names
vec.get_feature_names()
Out[5]: