spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hhbyyh <...@git.apache.org>
Subject [GitHub] spark pull request #17324: [SPARK-19969] [ML] Imputer doc and example
Date Mon, 27 Mar 2017 17:46:21 GMT
Github user hhbyyh commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17324#discussion_r108234190
  
    --- Diff: examples/src/main/java/org/apache/spark/examples/ml/JavaImputerExample.java
---
    @@ -0,0 +1,72 @@
    +/*
    + * 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 java.util.List;
    +
    +import org.apache.spark.ml.feature.Imputer;
    +import org.apache.spark.ml.feature.ImputerModel;
    +import org.apache.spark.sql.Dataset;
    +import org.apache.spark.sql.Row;
    +import org.apache.spark.sql.RowFactory;
    +import org.apache.spark.sql.SparkSession;
    +import org.apache.spark.sql.types.*;
    +// $example off$
    +
    +import static org.apache.spark.sql.types.DataTypes.*;
    +
    +/**
    + * An example demonstrating Imputer.
    + * Run with:
    + *   bin/run-example ml.JavaImputerExample
    + */
    +public class JavaImputerExample {
    +  public static void main(String[] args) {
    +    SparkSession spark = SparkSession
    +      .builder()
    +      .appName("JavaImputerExample")
    +      .getOrCreate();
    +
    +    // $example on$
    +    List<Row> data = Arrays.asList(
    +      RowFactory.create(1.0, Double.NaN),
    +      RowFactory.create(2.0, Double.NaN),
    +      RowFactory.create(Double.NaN, 3.0),
    +      RowFactory.create(4.0, 4.0),
    +      RowFactory.create(5.0, 5.0)
    +    );
    +    StructType schema = new StructType(new StructField[]{
    +      createStructField("a", DoubleType, false),
    +      createStructField("b", DoubleType, false)
    +    });
    +    Dataset<Row> df = spark.createDataFrame(data, schema);
    +
    +    Imputer imputerModel = new Imputer()
    +      .setStrategy("mean")
    --- End diff --
    
    For the example code, can we keep it to introduce the primary API or important paramters?


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