用法:
class dask_ml.preprocessing.LabelEncoder(use_categorical: bool = True)
使用 0 和 n_classes-1 之間的值對標簽進行編碼。
注意
這與分類數據的scikit-learn 版本不同。當傳遞一個分類
y
時,此實現將使用分類信息進行標簽編碼和轉換。你會收到不同的答案您的類別不是單調遞增的
您有未觀察到的類別
指定
use_categorical=False
以恢複 scikit-learn 行為。- use_categorical:布爾值,默認為真
當
y
是具有分類 dtype 的 dask 或 pandas 係列時是否使用分類 dtype 信息。
- classes_:形狀數組 (n_class,)
保存每個類的標簽。
- dtype_:可選的分類類型
對於 Categorical
y
,dtype 存儲在這裏。
參數:
屬性:
例子:
LabelEncoder
可用於標準化標簽。>>> from dask_ml import preprocessing >>> le = preprocessing.LabelEncoder() >>> le.fit([1, 2, 2, 6]) LabelEncoder() >>> le.classes_ array([1, 2, 6]) >>> le.transform([1, 1, 2, 6]) array([0, 0, 1, 2]...) >>> le.inverse_transform([0, 0, 1, 2]) array([1, 1, 2, 6])
它還可以用於將非數字標簽(隻要它們是可散列的和可比較的)轉換為數字標簽。
>>> le = preprocessing.LabelEncoder() >>> le.fit(["paris", "paris", "tokyo", "amsterdam"]) LabelEncoder() >>> list(le.classes_) ['amsterdam', 'paris', 'tokyo'] >>> le.transform(["tokyo", "tokyo", "paris"]) array([2, 2, 1]...) >>> list(le.inverse_transform([2, 2, 1])) ['tokyo', 'tokyo', 'paris']
使用 Dask 時,我們強烈建議盡可能使用分類 dask 係列。這避免了對值的(可能昂貴的)掃描,並啟用了更快的
transform
算法。>>> import dask.dataframe as dd >>> import pandas as pd >>> data = dd.from_pandas(pd.Series(['a', 'a', 'b'], dtype='category'), ... npartitions=2) >>> le.fit_transform(data) dask.array<values, shape=(nan,), dtype=int8, chunksize=(nan,)> >>> le.fit_transform(data).compute() array([0, 0, 1], dtype=int8)
相關用法
- Python dask_ml.preprocessing.MinMaxScaler用法及代碼示例
- Python dask_ml.preprocessing.Categorizer用法及代碼示例
- Python dask_ml.preprocessing.OrdinalEncoder用法及代碼示例
- Python dask_ml.preprocessing.PolynomialFeatures用法及代碼示例
- Python dask_ml.preprocessing.StandardScaler用法及代碼示例
- Python dask_ml.preprocessing.QuantileTransformer用法及代碼示例
- Python dask_ml.preprocessing.RobustScaler用法及代碼示例
- Python dask_ml.preprocessing.BlockTransformer用法及代碼示例
- Python dask_ml.preprocessing.DummyEncoder用法及代碼示例
- Python dask_ml.wrappers.ParallelPostFit用法及代碼示例
- Python dask_ml.feature_extraction.text.CountVectorizer用法及代碼示例
- 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.feature_extraction.text.FeatureHasher用法及代碼示例
- Python dask_ml.ensemble.BlockwiseVotingClassifier用法及代碼示例
- Python dask_ml.model_selection.train_test_split用法及代碼示例
- Python dask_ml.decomposition.PCA用法及代碼示例
- Python dask_ml.feature_extraction.text.HashingVectorizer用法及代碼示例
注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 dask_ml.preprocessing.LabelEncoder。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。