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

    https://github.com/apache/spark/pull/11053#discussion_r52957982
  
    --- Diff: 
examples/src/main/java/org/apache/spark/examples/ml/JavaEstimatorTransformerParamExample.java
 ---
    @@ -0,0 +1,118 @@
    +/*
    + * 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.examples.ml;
    +
    +//$example on$
    +import java.util.Arrays;
    +
    +import org.apache.spark.SparkConf;
    +import org.apache.spark.SparkContext;
    +import org.apache.spark.ml.classification.LogisticRegression;
    +import org.apache.spark.ml.classification.LogisticRegressionModel;
    +import org.apache.spark.ml.param.ParamMap;
    +import org.apache.spark.mllib.linalg.Vectors;
    +import org.apache.spark.mllib.regression.LabeledPoint;
    +import org.apache.spark.sql.DataFrame;
    +import org.apache.spark.sql.Row;
    +import org.apache.spark.sql.SQLContext;
    +
    +//$example off$
    +
    +/**
    + * Java example for Estimator, Transformer, and Param.
    + */
    +public class JavaEstimatorTransformerParamExample {
    +  public static void main(String[] args) {
    +    SparkConf conf = new SparkConf()
    +      .setAppName("JavaEstimatorTransformerParamExample");
    +    SparkContext sc = new SparkContext(conf);
    +    SQLContext sqlContext = new SQLContext(sc);
    +
    +    // $example on$
    +    // Prepare training data.
    +    // We use LabeledPoint, which is a JavaBean. Spark SQL can convert 
RDDs of
    +    // JavaBeans
    +    // into DataFrames, where it uses the bean metadata to infer the 
schema.
    +    DataFrame training = sqlContext.createDataFrame(Arrays.asList(
    +      new LabeledPoint(1.0, Vectors.dense(0.0, 1.1, 0.1)), new 
LabeledPoint(
    +        0.0, Vectors.dense(2.0, 1.0, -1.0)),
    +      new LabeledPoint(0.0, Vectors.dense(2.0, 1.3, 1.0)), new 
LabeledPoint(
    +        1.0, Vectors.dense(0.0, 1.2, -0.5))), LabeledPoint.class);
    +
    +    // Create a LogisticRegression instance. This instance is an Estimator.
    +    LogisticRegression lr = new LogisticRegression();
    +    // Print out the parameters, documentation, and any default values.
    +    System.out.println("LogisticRegression parameters:\n" + 
lr.explainParams()
    +      + "\n");
    +
    +    // We may set parameters using setter methods.
    +    lr.setMaxIter(10).setRegParam(0.01);
    +
    +    // Learn a LogisticRegression model. This uses the parameters stored 
in lr.
    +    LogisticRegressionModel model1 = lr.fit(training);
    +    // 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.
    +    System.out.println("Model 1 was fit using parameters: "
    +      + model1.parent().extractParamMap());
    --- End diff --
    
    merge into the previous line


---
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