MCPcopy Index your code
hub / github.com/antlr/codebuff / convert_categorical_data

Function convert_categorical_data

python/src/groomlib.py:102–115  ·  view source on GitHub ↗

From a list of feature vectors, convert category data to use multiple binary dummy variables using a DictVectorizer. Return the DictVectorizer and new list of feature vectors. The DictVectorizer must be used to tranform future testing feature vectors for prediction purposes.

(features)

Source from the content-addressed store, hash-verified

100
101
102def convert_categorical_data(features):
103 """
104 From a list of feature vectors, convert category data to use
105 multiple binary dummy variables using a DictVectorizer.
106 Return the DictVectorizer and new list of feature vectors.
107 The DictVectorizer must be used to tranform future testing
108 feature vectors for prediction purposes.
109 """
110 asdict = todict(features)
111 vec = DictVectorizer(sort=False)
112 features_with_dummy_vars = vec.fit_transform(asdict).toarray()
113 print "number new vars", len(vec.get_feature_names())
114 #print vec.get_feature_names()
115 return vec, features_with_dummy_vars
116
117
118def todict(features):

Callers 1

groom.pyFile · 0.90

Calls 1

todictFunction · 0.85

Tested by

no test coverage detected