以vertica
为例https://www.vertica.com/docs/11.0.x/HTML/Content/Authoring/AnalyzingData/MachineLearning/DataPreparation/EncodingCategoricalColumns.htm?tocpath=Analyzing%20Data%7CMachine%20Learning%20for%20Predictive%20Analytics%7CData%20Preparation%7C_____3
它使用来自kaggle
、的泰坦尼克号数据
ONE_HOT_ENCODER_FIT
函数覆盖分类数据并创建一个表示分类数据的新表示的模型
SELECT one_hot_encoder_fit('public.titanic_encoder','titanic_training','sex, embarkation_point' USING PARAMETERS exclude_columns='', output_view='', extra_levels='{}');
==================
varchar_categories
==================
category_name |category_level|category_level_index
-----------------+--------------+--------------------
embarkation_point| C | 0
embarkation_point| Q | 1
embarkation_point| S | 2 <- note S is 2
embarkation_point| | 3
sex | female | 0
sex | male | 1 <-- note male is 1
那么,在titanic_training
数据上应用这样的模型titanic_encoder
时,为什么要添加embarkation_point_2
?输出应该只包含分类值(比如S
(及其编码值吗?为什么我看到值0
和1
而不是2
(S
的编码值是什么?类似于sex
M
和sex_1
1
dbadmin@2e4e746b3e6c(*)=> select * from titanic_training limit 1;
passenger_id | survived | pclass | name | sex | age | sibling_and_spouse_count | parent_and_child_count | ticket | fare | cabin | embarkation_point
--------------+----------+--------+-------------------------+------+-----+--------------------------+------------------------+-----------+------+-------+-------------------
1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22 | 1 | 0 | A/5 21171 | 7.25 | | S <-- note S
(1 row)
dbadmin@2e4e746b3e6c(*)=> SELECT APPLY_ONE_HOT_ENCODER(* USING PARAMETERS model_name='titanic_encoder') from titanic_training limit 1;
passenger_id | survived | pclass | name | sex | sex_1 | age | sibling_and_spouse_count | parent_and_child_count | ticket | fare | cabin | embarkation_point | embarkation_point_1 | embarkation_point_2 (<-- why this is here)?
--------------+----------+--------+-------------------------+------+-------+-----+--------------------------+------------------------+-----------+------+-------+-------------------+---------------------+---------------------
1 | 0 | 3 | Braund, Mr. Owen Harris | male <- note male| 1 <- note encoded value of male | 22 | 1 | 0 | A/5 21171 | 7.25 | | S <- note S | 0 <- why this is here | 1 <-- why this is here. Where is 2?
(1 row)
为什么没有embarkation_point_3
?
您的输出有很多原因。首先,阅读APPLY_ONE_HOT_ENCODER的文档:https://www.vertica.com/docs/11.0.x/HTML/Content/Authoring/SQLReferenceManual/Functions/MachineLearning/APPLY_ONE_HOT_ENCODER.htm?tocpath=SQL%20Reference%20Manual%7CSQL%20Functions%7CMachine%20Learning%20Functions%7CTransformation%20Functions%7C_____5
有两个参数可以让你实现目标:
- drop_first:设置为false以获取所有列。其中一个是因为相关性的目的而被删除的。你可以阅读这篇文章:https://inmachineswetrust.com/posts/drop-first-columns/有优点也有缺点
- column_name:将其设置为值,但要小心。如果你有特殊字符的类别,你可能会遇到一些困难
Badr