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)
| 274 | |
| 275 | class 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 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected