如何声明我的给定列中DataFrame包含分类信息?
我有一个DataFrame从数据库加载的 Spark SQL 。其中的许多列DataFrame都有分类信息,但它们被编码为 Longs(为了隐私)。
我希望能够告诉 spark-ml,即使此列是数值,但信息实际上是分类的。类别的索引可能有一些漏洞,这是可以接受的。(例如,一列可能具有值 [1, 0, 0 ,4])
我知道存在 ,StringIndexer但我更愿意避免编码和解码的麻烦,特别是因为我有许多具有这种行为的列。
我会寻找类似于以下内容的东西
train = load_from_database()
categorical_cols = ["CategoricalColOfLongs1",
"CategoricalColOfLongs2"]
numeric_cols = ["NumericColOfLongs1"]
## This is what I am looking for
## this step detects the min and max value of both columns
## and adds metadata to indicate this as a categorical column
## with (1 + max - min) categories
categorizer = ColumnCategorizer(columns = categorical_cols,
autoDetectMinMax = True) …Run Code Online (Sandbox Code Playgroud)