用法:
class dask_ml.preprocessing.Categorizer(categories: Optional[dict] = None, columns: Optional[pandas.core.indexes.base.Index] = None)
將 DataFrame 的列轉換為分類 dtype。
對於虛擬、one-hot 或分類編碼,這是一個有用的預處理步驟。
- categories:映射,可選
將列名映射到
pandas.api.types.CategoricalDtype
實例的字典。或者,列名到(categories, ordered)
元組的映射。- columns:順序,可選
用於限製分類的列名序列。指定
categories
時忽略此參數。
- columns_:pandas.Index
已分類的列。當
categories
為 None 時很有用,我們檢測分類和對象列- categories_:dict
將列名映射到 dtypes 的字典。對於 pandas>=0.21.0,這些值是
pandas.api.types.CategoricalDtype
的實例。對於較舊的 pandas,這些值是(categories, ordered)
的元組。
參數:
屬性:
注意:
此轉換器僅適用於
dask.DataFrame
和pandas.DataFrame
。默認情況下,所有object-type 列都轉換為分類。類別集將是列中存在的值,並且類別將是無序的。通過dtypes
來控製此行為。所有其他列都包含在未觸及的轉換輸出中。
對於
dask.DataFrame
,任何未知的分類都將變為已知。例子:
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": ['a', 'a', 'b']}) >>> ce = Categorizer() >>> ce.fit_transform(df).dtypes A int64 B category dtype: object
>>> ce.categories_ {'B': CategoricalDtype(categories=['a', 'b'], ordered=False)}
使用 CategoricalDtypes 指定類別:
>>> from pandas.api.types import CategoricalDtype >>> ce = Categorizer(categories={"B": CategoricalDtype(['a', 'b', 'c'])}) >>> ce.fit_transform(df).B.dtype CategoricalDtype(categories=['a', 'b', 'c'], ordered=False)
相關用法
- Python dask_ml.preprocessing.MinMaxScaler用法及代碼示例
- Python dask_ml.preprocessing.OrdinalEncoder用法及代碼示例
- Python dask_ml.preprocessing.LabelEncoder用法及代碼示例
- 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.Categorizer。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。