Skip to content

Commit 1aede7c

Browse files
committed
Patch examples
1 parent 9299dd4 commit 1aede7c

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

examples/src/main/python/ml/estimator_transformer_param_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
Estimator Transformer Param Example.
2020
"""
2121
# $example on$
22+
from typing import Any, Dict
23+
from pyspark.ml.param import Param
2224
from pyspark.ml.linalg import Vectors
2325
from pyspark.ml.classification import LogisticRegression
2426
# $example off$
@@ -54,7 +56,7 @@
5456
print(model1.extractParamMap())
5557

5658
# We may alternatively specify parameters using a Python dictionary as a paramMap
57-
paramMap = {lr.maxIter: 20}
59+
paramMap: Dict[Param, Any] = {lr.maxIter: 20}
5860
paramMap[lr.maxIter] = 30 # Specify 1 Param, overwriting the original maxIter.
5961
paramMap.update({lr.regParam: 0.1, lr.threshold: 0.55}) # Specify multiple Params.
6062

examples/src/main/python/ml/fm_classifier_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121
# $example on$
2222
from pyspark.ml import Pipeline
23-
from pyspark.ml.classification import FMClassifier
23+
from pyspark.ml.classification import FMClassifier, FMClassificationModel
2424
from pyspark.ml.feature import MinMaxScaler, StringIndexer
2525
from pyspark.ml.evaluation import MulticlassClassificationEvaluator
2626
# $example off$
@@ -66,7 +66,7 @@
6666
accuracy = evaluator.evaluate(predictions)
6767
print("Test set accuracy = %g" % accuracy)
6868

69-
fmModel = model.stages[2]
69+
fmModel: FMClassificationModel = model.stages[2] # type: ignore[assignment]
7070
print("Factors: " + str(fmModel.factors))
7171
print("Linear: " + str(fmModel.linear))
7272
print("Intercept: " + str(fmModel.intercept))

examples/src/main/python/ml/fm_regressor_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121
# $example on$
2222
from pyspark.ml import Pipeline
23-
from pyspark.ml.regression import FMRegressor
23+
from pyspark.ml.regression import FMRegressor, FMRegressionModel
2424
from pyspark.ml.feature import MinMaxScaler
2525
from pyspark.ml.evaluation import RegressionEvaluator
2626
# $example off$
@@ -63,7 +63,7 @@
6363
rmse = evaluator.evaluate(predictions)
6464
print("Root Mean Squared Error (RMSE) on test data = %g" % rmse)
6565

66-
fmModel = model.stages[1]
66+
fmModel: FMRegressionModel = model.stages[1] # type: ignore[assignment]
6767
print("Factors: " + str(fmModel.factors))
6868
print("Linear: " + str(fmModel.linear))
6969
print("Intercept: " + str(fmModel.intercept))

examples/src/main/python/ml/logistic_regression_summary_example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
bin/spark-submit examples/src/main/python/ml/logistic_regression_summary_example.py
2222
"""
2323
# $example on$
24-
from pyspark.ml.classification import LogisticRegression
24+
from pyspark.ml.classification import LogisticRegression, BinaryLogisticRegressionTrainingSummary
2525
# $example off$
2626
from pyspark.sql import SparkSession
2727

@@ -42,7 +42,9 @@
4242
# $example on$
4343
# Extract the summary from the returned LogisticRegressionModel instance trained
4444
# in the earlier example
45-
trainingSummary = lrModel.summary
45+
trainingSummary: BinaryLogisticRegressionTrainingSummary = (
46+
lrModel.summary
47+
) # type: ignore[assignment]
4648

4749
# Obtain the objective per iteration
4850
objectiveHistory = trainingSummary.objectiveHistory

examples/src/main/python/ml/pipeline_example.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@
6262
prediction = model.transform(test)
6363
selected = prediction.select("id", "text", "probability", "prediction")
6464
for row in selected.collect():
65-
rid, text, prob, prediction = row
66-
print("(%d, %s) --> prob=%s, prediction=%f" % (rid, text, str(prob), prediction))
65+
rid, text, prob, prediction = row # type: ignore[no-redef]
66+
print(
67+
"(%d, %s) --> prob=%s, prediction=%f" % (
68+
rid, text, str(prob), prediction # type: ignore
69+
)
70+
)
6771
# $example off$
6872

6973
spark.stop()

examples/src/main/python/sql/arrow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333

3434
def dataframe_with_arrow_example(spark):
35-
import numpy as np
36-
import pandas as pd
35+
import numpy as np # type: ignore[import]
36+
import pandas as pd # type: ignore[import]
3737

3838
# Enable Arrow-based columnar data transfers
3939
spark.conf.set("spark.sql.execution.arrow.pyspark.enabled", "true")

0 commit comments

Comments
 (0)