R-如何使用ft_elementwise_product



我正在尝试使用函数 ft_elementwise_product,该函数应该制作elementwise产品,但是我可以,这是一个链接,解释了该函数应如何工作:

http://rstudio.github.io/sparklyr/reference/ft_elementwise_product.html

有此示例:

library(sparklyr)
library(dplyr)
sc <- spark_connect(master = "local")
iris2 = copy_to(sc, iris, "iris2", overwrite = TRUE)

我想将sepal_length乘以sepal_width,所以我尝试了:

ft_elementwise_product(iris2, Sepal_Length, Sepal_Width, Sepal_Width) 
# object 'Sepal_Length' not found
ft_elementwise_product(iris2, "Sepal_Length", Sepal_Width, Sepal_Width) 
# object 'Sepal_Width' not found
ft_elementwise_product(iris2, "Sepal_Length", "Sepal_Width", Sepal_Width) 
# Error in object %||% default : object 'Sepal_Width' not found
ft_elementwise_product(iris2, "Sepal_Length", "Sepal_Width", "Sepal_Width")
# Error: java.lang.Exception: No matched method found for class org.apache.spark.ml.feature.ElementwiseProduct.setScalingVec
ft_elementwise_product(iris2, "Sepal_Length", "Sepal_Width", "Sepal_Length")
# Error: java.lang.Exception: No matched method found for class org.apache.spark.ml.feature.ElementwiseProduct.setScalingVec
ft_elementwise_product(iris2, "Sepal_Length", "result", "Sepal_Length")
# Error: java.lang.Exception: No matched method found for class org.apache.spark.ml.feature.ElementwiseProduct.setScalingVec
iris2 = mutate(iris2, result = 0)
ft_elementwise_product(iris2, "Sepal_Length", "result", "Sepal_Length")
# Error: java.lang.Exception: No matched method found for class org.apache.spark.ml.feature.ElementwiseProduct.setScalingVec

我想将sepal_length乘以sepal_width

在这种情况下,您尚未用于ElementwiseProduct。只需使用Standart乘法:

iris2 %>% mutate(product = Sepal_Length * Sepal_Width)

如何使用ft_elementwise_product

ElementWise产品是与Pipelines一起使用的ML Transformer。它用于将Vector列乘以本地缩放Vectors。使用当前主(0.7.0-9105),可以使用如下所示:

iris2 %>%  
  # Create Vector column which can be used as an input
  ft_vector_assembler(input.col=colnames(.)[-5], output.col="features") %>% 
  # Transform assembled vector with vector [-1, 1, -1, 1]
  ft_elementwise_product(
    input.col="features", output.col="scaled_features",
    scaling_vec=c(-1, 1, -1, 1))

相关内容

  • 没有找到相关文章

最新更新