spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkbradley <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-8965][Docs] Add ml-guide Python Example...
Date Tue, 11 Aug 2015 01:03:49 GMT
Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8081#discussion_r36703007
  
    --- Diff: docs/ml-guide.md ---
    @@ -355,6 +355,75 @@ jsc.stop();
     {% endhighlight %}
     </div>
     
    +<div data-lang="python">
    +{% highlight python %}
    +from pyspark import SparkContext
    +from pyspark.mllib.regression import LabeledPoint
    +from pyspark.ml.classification import LogisticRegression
    +from pyspark.ml.param import Param, Params
    +from pyspark.sql import Row, SQLContext
    +
    +sc = SparkContext(appName="SimpleParamsExample")
    +sqlContext = SQLContext(sc)
    +
    +# Prepare training data.
    +# We use LabeledPoint.
    +training = sc.parallelize(
    +[LabeledPoint(1.0, [0.0, 1.1,  0.1]),
    +LabeledPoint(0.0, [2.0, 1.0, -1.0]),
    +LabeledPoint(0.0, [2.0, 1.3,  1.0]),
    +LabeledPoint(1.0, [0.0, 1.2, -0.5])])
    +
    +# Create a LogisticRegression instance. This instance is an Estimator.
    +lr = LogisticRegression(maxIter=10, regParam=0.01)
    +# Print out the parameters, documentation, and any default values.
    +print "LogisticRegression parameters:\n" + lr.explainParams() + "\n"
    +
    +# Learn a LogisticRegression model. This uses the parameters stored in lr.
    +model1 = lr.fit(training.toDF())
    +
    +# Since model1 is a Model (i.e., a transformer produced by an Estimator),
    +# we can view the parameters it used during fit().
    +# This prints the parameter (name: value) pairs, where names are unique IDs for this
    +# LogisticRegression instance.
    +print "Model 1 was fit using parameters: "
    +print model1.extractParamMap()
    +
    +# We may alternatively specify parameters using a Python dictionary as a paramMap
    +paramMap = {lr.maxIter: 20}
    +paramMap[lr.maxIter] = 30 # Specify 1 Param, overwriting the original maxIter.
    +paramMap.update({lr.regParam: 0.1, lr.threshold: 0.55}) # Specify multiple Params.
    +
    +# You can combine paramMaps, which are python dictionaries.
    +paramMap2 = { lr.probabilityCol: "myProbability" } # Change output column name
    --- End diff --
    
    python style: remove spaces: ```{lr.probabilityCol: "myProbability"}```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message