Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/src/main/python/ml/fm_classifier_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""
# $example on$
from pyspark.ml import Pipeline
from pyspark.ml.classification import FMClassifier
from pyspark.ml.classification import FMClassificationModel, FMClassifier
from pyspark.ml.evaluation import MulticlassClassificationEvaluator
from pyspark.ml.feature import MinMaxScaler, StringIndexer

Expand Down Expand Up @@ -65,12 +65,13 @@
evaluator = MulticlassClassificationEvaluator(
labelCol="indexedLabel", predictionCol="prediction", metricName="accuracy")
accuracy = evaluator.evaluate(predictions)
print("Test set accuracy = %g" % accuracy)
print(f"Test set accuracy = {accuracy:g}")

fmModel = model.stages[2]
print("Factors: " + str(fmModel.factors)) # type: ignore
print("Linear: " + str(fmModel.linear)) # type: ignore
print("Intercept: " + str(fmModel.intercept)) # type: ignore
assert isinstance(fmModel, FMClassificationModel)
print(f"Factors: {fmModel.factors}")
print(f"Linear: {fmModel.linear}")
print(f"Intercept: {fmModel.intercept}")
# $example off$

spark.stop()
11 changes: 6 additions & 5 deletions examples/src/main/python/ml/fm_regressor_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pyspark.ml import Pipeline
from pyspark.ml.evaluation import RegressionEvaluator
from pyspark.ml.feature import MinMaxScaler
from pyspark.ml.regression import FMRegressor
from pyspark.ml.regression import FMRegressionModel, FMRegressor

# $example off$
from pyspark.sql import SparkSession
Expand Down Expand Up @@ -62,12 +62,13 @@
evaluator = RegressionEvaluator(
labelCol="label", predictionCol="prediction", metricName="rmse")
rmse = evaluator.evaluate(predictions)
print("Root Mean Squared Error (RMSE) on test data = %g" % rmse)
print(f"Root Mean Squared Error (RMSE) on test data = {rmse:g}")

fmModel = model.stages[1]
print("Factors: " + str(fmModel.factors)) # type: ignore
print("Linear: " + str(fmModel.linear)) # type: ignore
print("Intercept: " + str(fmModel.intercept)) # type: ignore
assert isinstance(fmModel, FMRegressionModel)
print(f"Factors: {fmModel.factors}")
print(f"Linear: {fmModel.linear}")
print(f"Intercept: {fmModel.intercept}")
# $example off$

spark.stop()