AI Terms Dictionary

A comprehensive multilingual AI terminology dictionary

Definition

Feature hashing, also known as the hashing trick, allows machine learning models to handle large, sparse feature spaces without maintaining an explicit mapping between features and indices. By applying a hash function to each feature, it deterministically assigns them to a fixed number of buckets. This reduces memory usage and eliminates the need for preprocessing steps like vocabulary building, making it highly efficient for text classification and recommendation systems with massive input dimensions.

Summary

A technique that maps high-dimensional sparse features to a fixed-size vector using a hash function.

Key Concepts

Use Cases

Code Example

1
2
3
4
5
6
7
8
from sklearn.feature_extraction import FeatureHasher
import numpy as np

# Example: Hashing text features
hasher = FeatureHasher(n_features=10, input_type='string')
docs = ['hello world', 'hello python', 'world python']
hashed = hasher.transform(docs)
print(hashed.toarray())