forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-7578] [ML] [DOC] User guide for spark.ml Normalizer, IDF, Stan…
…dardScaler Added user guide sections with code examples. Also added small Java unit tests to test Java example in guide. CC: mengxr Author: Joseph K. Bradley <joseph@databricks.com> Closes apache#6127 from jkbradley/feature-guide-2 and squashes the following commits: cd47f4b [Joseph K. Bradley] Updated based on code review f16bcec [Joseph K. Bradley] Fixed merge issues and update Python examples print calls for Python 3 0a862f9 [Joseph K. Bradley] Added Normalizer, StandardScaler to ml-features doc, plus small Java unit tests a21c2d6 [Joseph K. Bradley] Updated ml-features.md with IDF
- Loading branch information
1 parent
60c484b
commit 65af990
Showing
4 changed files
with
351 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
mllib/src/test/java/org/apache/spark/ml/feature/JavaNormalizerSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.ml.feature; | ||
|
||
import java.util.List; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.spark.mllib.linalg.Vectors; | ||
import org.apache.spark.sql.DataFrame; | ||
import org.apache.spark.sql.SQLContext; | ||
|
||
public class JavaNormalizerSuite { | ||
private transient JavaSparkContext jsc; | ||
private transient SQLContext jsql; | ||
|
||
@Before | ||
public void setUp() { | ||
jsc = new JavaSparkContext("local", "JavaNormalizerSuite"); | ||
jsql = new SQLContext(jsc); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
jsc.stop(); | ||
jsc = null; | ||
} | ||
|
||
@Test | ||
public void normalizer() { | ||
// The tests are to check Java compatibility. | ||
List<VectorIndexerSuite.FeatureData> points = Lists.newArrayList( | ||
new VectorIndexerSuite.FeatureData(Vectors.dense(0.0, -2.0)), | ||
new VectorIndexerSuite.FeatureData(Vectors.dense(1.0, 3.0)), | ||
new VectorIndexerSuite.FeatureData(Vectors.dense(1.0, 4.0)) | ||
); | ||
DataFrame dataFrame = jsql.createDataFrame(jsc.parallelize(points, 2), | ||
VectorIndexerSuite.FeatureData.class); | ||
Normalizer normalizer = new Normalizer() | ||
.setInputCol("features") | ||
.setOutputCol("normFeatures"); | ||
|
||
// Normalize each Vector using $L^2$ norm. | ||
DataFrame l2NormData = normalizer.transform(dataFrame, normalizer.p().w(2)); | ||
l2NormData.count(); | ||
|
||
// Normalize each Vector using $L^\infty$ norm. | ||
DataFrame lInfNormData = | ||
normalizer.transform(dataFrame, normalizer.p().w(Double.POSITIVE_INFINITY)); | ||
lInfNormData.count(); | ||
} | ||
} |
Oops, something went wrong.