MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / __init__

Method __init__

numpy_ml/preprocessing/general.py:276–299  ·  view source on GitHub ↗

Convert a collection of features to a fixed-dimensional matrix using the hashing trick. Notes ----- Uses the md5 hash. Parameters ---------- n_dim : int The dimensionality of each example in the output feature matrix.

(self, n_dim=256, sparse=True)

Source from the content-addressed store, hash-verified

274
275class FeatureHasher:
276 def __init__(self, n_dim=256, sparse=True):
277 """
278 Convert a collection of features to a fixed-dimensional matrix using
279 the hashing trick.
280
281 Notes
282 -----
283 Uses the md5 hash.
284
285 Parameters
286 ----------
287 n_dim : int
288 The dimensionality of each example in the output feature matrix.
289 Small numbers of features are likely to cause hash collisions, but
290 large numbers will cause larger overall parameter dimensions for
291 any (linear) learning agent. Default is 256.
292 sparse : bool
293 Whether the resulting feature matrix should be a sparse
294 :py:class:`csr_matrix <scipy.sparse.csr_matrix>` or dense
295 :py:class:`ndarray <numpy.ndarray>`. Default is True.
296 """
297 self.n_dim = n_dim
298 self.hash = hashlib.md5
299 self.sparse = sparse and _SCIPY
300
301 def encode(self, examples):
302 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected