Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2819#discussion_r19432437
  
    --- Diff: docs/mllib-feature-extraction.md ---
    @@ -223,6 +279,29 @@ val data1 = data.map(x => (x.label, 
scaler1.transform(x.features)))
     val data2 = data.map(x => (x.label, 
scaler2.transform(Vectors.dense(x.features.toArray))))
     {% endhighlight %}
     </div>
    +
    +<div data-lang="python">
    +{% highlight python %}
    +from pyspark.mllib.util import MLUtils
    +from pyspark.mllib.linalg import Vectors
    +from pyspark.mllib.feature import StandardScaler
    +
    +data = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_libsvm_data.txt")
    +label = data.map(lambda x: x.label)
    +features = data.map(lambda x: x.features)
    +
    +scaler1 = StandardScaler().fit(features)
    +scaler2 = StandardScaler(withMean=True, withStd=True).fit(features)
    +
    +# data1 will be unit variance.
    +data1 = label.zip(scaler1.transform(features))
    +
    +# Without converting the features into dense vectors, transformation with 
zero mean will raise
    +# exception on sparse vector.
    +# data2 will be unit variance and zero mean.
    +data2 = label.zip(scaler1.transform(features.map(lambda x: 
Vectors.dense(x.toArray()))))
    --- End diff --
    
    fixed, thx!


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to