scikit-learn-contrib/category_encoders — dự án mã nguồn mở — đang có 2.5k sao GitHub. A library of sklearn compatible categorical variable encoders
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
All of the encoders are fully compatible sklearn transformers, so they can be used in pipelines or in your existing
scripts. Supported input formats include numpy arrays and pandas dataframes. If the cols parameter isn't passed, all
columns with object or pandas categorical data type will be encoded. Please see the docs for transformer-specific
configuration options.
Examples
There are two types of encoders: unsupervised and supervised. An unsupervised example:
from category_encoders import *
import pandas as pd
# prepare some data with categorical features
X = pd.DataFrame({
'gender': ['male', 'female', 'female', 'male', 'female'],
'country': ['US', 'UK', 'US', 'CA', 'UK'],
'age': [25, 32, 47, 51, 38],
})
# use binary encoding to encode two categorical features
enc = BinaryEncoder(cols=['gender', 'country']).fit(X)
# transform the dataset
numeric_dataset = enc.transform(X)
And a supervised example:
from category_encoders import *
import pandas as pd
# prepare some training and test data with categorical features and a target
X_train = pd.DataFrame({
'gender': ['male', 'female', 'female', 'male'],
'country': ['US', 'UK', 'US', 'CA'],
})
y_train = pd.Series([1, 0, 1, 0])
X_test = pd.DataFrame({
'gender': ['female', 'male'],
'country': ['UK', 'US'],
})
# use target encoding to encode two categorical features
enc = TargetEncoder(cols=['gender', 'country'])
# transform the datasets
training_numeric_dataset = enc.fit_transform(X_train, y_train)
testing_numeric_dataset = enc.transform(X_test)
For the transformation of the training data with the supervised methods, you should use fit_transform() method instead of fit().transform(), because these two methods do not have to generate the same result. The difference can be observed with LeaveOneOut encoder, which performs a nested cross-validation for the training data in fit_transform() method (to decrease over-fitting of the downstream model) but uses all the training data for scoring with transform() method (to get as accurate estimates as possible).
Furthermore, you may benefit from following wrappers:
PolynomialWrapper, which extends supervised encoders to support polynomial targets
NestedCVWrapper, which helps to prevent overfitting
Additional examples and benchmarks can be found in the examples directory.
Contributing
Category encoders is under active development, if you'd like to be involved, we'd love to have you. Check out the CONTRIBUTING.md file
or open an issue on the github project to get started.
References
Kilian Weinberger; Anirban Dasgupta; John Langford; Alex Smola; Josh Attenberg (2009). Feature Hashing for Large Scale Multitask Learning. Proc. ICML.
Contrast Coding Systems for categorical variables. UCLA: Statistical Consulting Group. From https://stats.idre.ucla.edu/r/library/r-library-contrast-coding-systems-for-categorical-variables/.
Gregory Carey (2003). Coding Categorical Variables. From http://psych.colorado.edu/~carey/Courses/PSYC5741/handouts/Coding%20Categorical%20Variables%202006-03-03.pdf
Owen Zhang - Leave One Out Encoding. From https://datascience.stackexchange.com/questions/10839/what-is-difference-between-one-hot-encoding-and-leave-one-out-encoding
Beyond One-Hot: an exploration of categorical variables. From https://mcginniscommawill.com/posts/2015-11-29-beyond-one-hot-an-exploration-of-categorical-variables/
BaseN Encoding and Grid Search in categorical variables. From https://mcginniscommawill.com/posts/2016-12-18-basen-encoding-grid-search-category-encoders/
Daniele Miccii-Barreca (2001). A Preprocessing Scheme for High-Cardinality Categorical Attributes in Classification and Prediction Problems. SIGKDD Explor. Newsl. 3, 1. From http://dx.doi.org/10.1145/507533.507538
Weight of Evidence (WOE) and Information Value Explained. From https://www.listendata.com/2015/03/weight-of-evidence-woe-and-information.html
Empirical Bayes for multiple sample sizes. From http://chris-said.io/2017/05/03/empirical-bayes-for-multiple-sample-sizes/
Simple Count or Frequency Encoding. From https://www.datacamp.com/community/tutorials/encoding-methodologies
Transforming categorical features to numerical features. From https://tech.yandex.com/catboost/doc/dg/concepts/algorithm-main-stages_cat-to-numberic-docpage/
Andrew Gelman and Jennifer Hill (2006). Data Analysis Using Regression and Multilevel/Hierarchical Models. From https://faculty.psau.edu.sa/filedownload/doc-12-pdf-a1997d0d31f84d13c1cdc44ac39a8f2c-original.pdf
Carlos Mougan, David Masip, Jordi Nin and Oriol Pujol (2021). Quantile Encoder: Tackling High Cardinality Categorical Features in Regression Problems. Modeling Decisions for Artificial Intelligence, 2021. Springer International Publishing https://link.springer.com/chapter/10.1007%2F978-3-030-85529-1_14
Gray Encoding. From https://en.wikipedia.org/wiki/Gray_code
Jacob Buckman, Aurko Roy, Colin Raffel, Ian Goodfellow: Thermometer Encoding: One Hot Way To Resist Adversarial Examples. From https://openreview.net/forum?id=S18Su--CW
Fairness implications of encoding protected categorical attributes. Carlos Mougan, Jose Alvarez, Salvatore Ruggieri, and Steffen Staab. In Proceedings of the 2023 AAAI/ACM Conference on AI, Ethics, and Society, AIES ’21, https://arxiv.org/abs/2201.11358
Đọc thêm về scikit-learn-contrib/category_encoders ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/scikit-learn-contrib/category_encoders là nguồn chính thức.
scikit-learn-contrib/category_encoders có bao nhiêu sao?
scikit-learn-contrib/category_encoders có 2.5k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/scikit-learn-contrib/category_encoders. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
scikit-learn-contrib/category_encoders có phải mã nguồn mở không?
Có — scikit-learn-contrib/category_encoders phát hành theo license BSD-3-Clause, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/scikit-learn-contrib/category_encoders.
scikit-learn-contrib/category_encoders có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho scikit-learn-contrib/category_encoders. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
scikit-learn-contrib/category_encoders có trang demo không?
Dự án có trang chủ ở http://contrib.scikit-learn.org/category_encoders/. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
scikit-learn-contrib/category_encoders còn đang phát triển không?
Commit gần nhất trên scikit-learn-contrib/category_encoders là 19 ngày trước (theo timestamp GitHub). Repo có 411 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về category_encoders?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về category_encoders.