用法:
class dask_ml.feature_extraction.text.FeatureHasher(n_features=1048576, *, input_type='dict', dtype=<class 'numpy.float64'>, alternate_sign=True)
實現特征散列,也就是散列技巧。
此類將符號特征名稱(字符串)序列轉換為 scipy.sparse 矩陣,使用哈希函數計算與名稱對應的矩陣列。使用的散列函數是有符號的 32 位版本的 Murmurhash3。
使用字節串類型的特征名稱as-is。 Unicode 字符串首先轉換為 UTF-8,但沒有進行 Unicode 規範化。特征值必須是(有限的)數字。
此類是 DictVectorizer 和 CountVectorizer 的low-memory 替代品,用於large-scale(在線)學習和內存緊張的情況,例如在嵌入式設備上運行預測代碼時。
在用戶指南中閱讀更多信息。
- n_features:整數,默認=2**20
輸出矩陣中的特征(列)數。少量特征可能會導致哈希衝突,但大量特征會導致線性學習器中的係數維度較大。
- input_type:str,默認='dict'
從 {‘dict’, ‘pair’, ‘string’} 中選擇一個字符串。或者“dict”(默認)接受字典超過(feature_name,值); “pair” 接受成對的 (feature_name, value);或 “string” 接受單個字符串。 feature_name 應該是一個字符串,而 value 應該是一個數字。在“string” 的情況下,隱含值為 1。 feature_name 被散列以找到該函數的適當列。該值的符號可能會在輸出中翻轉(但請參見下麵的non_negative)。
- dtype:numpy dtype,默認=np.float64
特征值的類型。作為 dtype 參數傳遞給 scipy.sparse 矩陣構造函數。不要將其設置為 bool、np.boolean 或任何無符號整數類型。
- alternate_sign:布爾,默認=真
當為 True 時,將交替符號添加到特征中,以近似保存散列空間中的內積,即使對於小的 n_features 也是如此。這種方法類似於稀疏隨機投影。
參數:
例子:
>>> from sklearn.feature_extraction import FeatureHasher >>> h = FeatureHasher(n_features=10) >>> D = [{'dog': 1, 'cat':2, 'elephant':4},{'dog': 2, 'run': 5}] >>> f = h.transform(D) >>> f.toarray() array([[ 0., 0., -4., -1., 0., 0., 0., 0., 0., 2.], [ 0., 0., 0., -2., -5., 0., 0., 0., 0., 0.]])
相關用法
- Python dask_ml.feature_extraction.text.CountVectorizer用法及代碼示例
- Python dask_ml.feature_extraction.text.HashingVectorizer用法及代碼示例
- Python dask_ml.wrappers.ParallelPostFit用法及代碼示例
- Python dask_ml.preprocessing.MinMaxScaler用法及代碼示例
- Python dask_ml.preprocessing.Categorizer用法及代碼示例
- Python dask_ml.linear_model.LinearRegression用法及代碼示例
- Python dask_ml.wrappers.Incremental用法及代碼示例
- Python dask_ml.metrics.mean_squared_log_error用法及代碼示例
- Python dask_ml.model_selection.GridSearchCV用法及代碼示例
- Python dask_ml.preprocessing.OrdinalEncoder用法及代碼示例
- Python dask_ml.preprocessing.LabelEncoder用法及代碼示例
- Python dask_ml.ensemble.BlockwiseVotingClassifier用法及代碼示例
- Python dask_ml.model_selection.train_test_split用法及代碼示例
- Python dask_ml.decomposition.PCA用法及代碼示例
- Python dask_ml.preprocessing.PolynomialFeatures用法及代碼示例
- Python dask_ml.linear_model.LogisticRegression用法及代碼示例
- Python dask_ml.xgboost.train用法及代碼示例
- Python dask_ml.linear_model.PoissonRegression用法及代碼示例
- Python dask_ml.preprocessing.StandardScaler用法及代碼示例
- Python dask_ml.preprocessing.QuantileTransformer用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 dask_ml.feature_extraction.text.FeatureHasher。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。