[英]How to properly use feature transformation functions in Sparklyr
假设我想在数据集的每一列上使用ft_max_abs_scaler
。 这是文档中的内容:
sc <- spark_connect(master = "local")
iris_tbl <- sdf_copy_to(sc, iris, name = "iris_tbl", overwrite = TRUE)
features <- c("Sepal_Length", "Sepal_Width", "Petal_Length", "Petal_Width")
iris_tbl <- iris_tbl %>%
ft_vector_assembler(input_col = features,
output_col = "features_temp") %>%
ft_max_abs_scaler(input_col = "features_temp",
output_col = "features")
请注意, ft_vector_assembler
创建一个新列features_temp
和ft_max_abs_scaler
创建另一个新列features
。 现在假设我想将向量分解为单独的列,我必须这样做:
iris_tbl <- iris_tbl %>% sdf_separate_column("features", into = features)
# result in error because column name cannot be the same
由于没有删除列的好方法,我想知道是否有更好的方法来使用 Sparklyr 进行特征转换而无需不断创建新列。
iris_tbl <- iris_tbl %>%
ft_vector_assembler(input_cols = c("Sepal_Length", "Sepal_Width", "Petal_Length", "Petal_Width"), output_col = "features")
iris_tbl <- iris_tbl %>%
sdf_separate_column("features", into = "new")
iris_tbl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.