huaxingao commented on a change in pull request #27570: 
[SPARK-30820][SPARKR][ML] Add FMClassifier to SparkR
URL: https://github.com/apache/spark/pull/27570#discussion_r386517512
 
 

 ##########
 File path: R/pkg/tests/fulltests/test_mllib_classification.R
 ##########
 @@ -488,4 +488,36 @@ test_that("spark.naiveBayes", {
   expect_equal(class(collect(predictions)$clicked[1]), "character")
 })
 
+test_that("spark.fmClassifier", {
+  df <- withColumn(
+    suppressWarnings(createDataFrame(iris)),
+    "Species", otherwise(when(column("Species") == "Setosa", "Setosa"), 
"Not-Setosa")
+  )
+
+  model1 <- spark.fmClassifier(
+    df,  Species ~ .,
+    regParam = 0.01, maxIter = 10, fitLinear = TRUE, factorSize = 3
+  )
+
+  prediction1 <- predict(model1, df)
+  expect_is(prediction1, "SparkDataFrame")
+  expect_equal(summary(model1)$factorSize, 3)
+
+  # Test model save/load
+  if (windows_with_hadoop()) {
+    modelPath <- tempfile(pattern = "spark-fmclassifier", fileext = ".tmp")
+    write.ml(model1, modelPath)
+    model2 <- read.ml(modelPath)
+
+    expect_is(model2, "FMClassificationModel")
+
+    prediction2 <- predict(model2, df)
+    expect_equal(
+      collect(drop(prediction1, c("rawPrediction", "probability"))),
+      collect(drop(prediction2, c("rawPrediction", "probability")))
+    )
 
 Review comment:
   add ```unlink(modelPath)``` to delete the dir 
   
   Also, I prefer to follow what the other tests do for testing model save and 
load: checking if the loaded model has the same fields as the saved model. In 
scala test, we do this for ```FMClassifier```:
   ```
         assert(model.intercept === model2.intercept)
         assert(model.linear.toArray === model2.linear.toArray)
         assert(model.factors.toArray === model2.factors.toArray)
         assert(model.numFeatures === model2.numFeatures)
   ```
   In LinearSVM R test, it does this:
   ```
       coefs <- summary(model)$coefficients
       coefs2 <- summary(model2)$coefficients
       expect_equal(coefs, coefs2)
   ```
   Is it OK we do something similar?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to