Skip to content

Commit

Permalink
[SQL][docs][minor] Define LabeledDocument/Document classes in CV example
Browse files Browse the repository at this point in the history
To easier copy/paste Cross-Validation example code snippet need to define LabeledDocument/Document in it, since they difined in a previous example.
  • Loading branch information
petro-rudenko committed Mar 23, 2015
1 parent 9f3273b commit 1d35383
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/ml-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,11 @@ import org.apache.spark.ml.tuning.{ParamGridBuilder, CrossValidator}
import org.apache.spark.mllib.linalg.Vector
import org.apache.spark.sql.{Row, SQLContext}

// Labeled and unlabeled instance types.
// Spark SQL can infer schema from case classes.
case class LabeledDocument(id: Long, text: String, label: Double)
case class Document(id: Long, text: String)

val conf = new SparkConf().setAppName("CrossValidatorExample")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
Expand Down Expand Up @@ -655,6 +660,36 @@ import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SQLContext;

// Labeled and unlabeled instance types.
// Spark SQL can infer schema from Java Beans.
public class Document implements Serializable {
private Long id;
private String text;

public Document(Long id, String text) {
this.id = id;
this.text = text;
}

public Long getId() { return this.id; }
public void setId(Long id) { this.id = id; }

public String getText() { return this.text; }
public void setText(String text) { this.text = text; }
}

public class LabeledDocument extends Document implements Serializable {
private Double label;

public LabeledDocument(Long id, String text, Double label) {
super(id, text);
this.label = label;
}

public Double getLabel() { return this.label; }
public void setLabel(Double label) { this.label = label; }
}

SparkConf conf = new SparkConf().setAppName("JavaCrossValidatorExample");
JavaSparkContext jsc = new JavaSparkContext(conf);
SQLContext jsql = new SQLContext(jsc);
Expand Down

0 comments on commit 1d35383

Please sign in to comment.