diff options
Diffstat (limited to 'examples/src/main/python/ml/max_abs_scaler_example.py')
-rw-r--r-- | examples/src/main/python/ml/max_abs_scaler_example.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/examples/src/main/python/ml/max_abs_scaler_example.py b/examples/src/main/python/ml/max_abs_scaler_example.py index ab91198b08..45eda3cdad 100644 --- a/examples/src/main/python/ml/max_abs_scaler_example.py +++ b/examples/src/main/python/ml/max_abs_scaler_example.py @@ -19,6 +19,7 @@ from __future__ import print_function # $example on$ from pyspark.ml.feature import MaxAbsScaler +from pyspark.ml.linalg import Vectors # $example off$ from pyspark.sql import SparkSession @@ -29,7 +30,11 @@ if __name__ == "__main__": .getOrCreate() # $example on$ - dataFrame = spark.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt") + dataFrame = spark.createDataFrame([ + (0, Vectors.dense([1.0, 0.1, -8.0]),), + (1, Vectors.dense([2.0, 1.0, -4.0]),), + (2, Vectors.dense([4.0, 10.0, 8.0]),) + ], ["id", "features"]) scaler = MaxAbsScaler(inputCol="features", outputCol="scaledFeatures") @@ -38,7 +43,8 @@ if __name__ == "__main__": # rescale each feature to range [-1, 1]. scaledData = scalerModel.transform(dataFrame) - scaledData.show() + + scaledData.select("features", "scaledFeatures").show() # $example off$ spark.stop() |