AI术语词典

A comprehensive multilingual AI terminology dictionary

Definition

特征哈希,也称为哈希技巧(hashing trick),允许机器学习模型处理大型稀疏特征空间,而无需维护特征与索引之间的显式映射。通过应用哈希函数,模型可以直接将任意特征映射到固定的向量维度中,从而节省内存并简化特征工程流程。

Summary

一种利用哈希函数将高维稀疏特征映射到固定大小向量的技术。

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())