Пример #1
0
 public double rmse(DDF predictedDDF, boolean implicitPrefs) throws DDFException {
   RDD<Rating> predictions =
       (RDD<Rating>) predictedDDF.getRepresentationHandler().get(RDD.class, Rating.class);
   RDD<Rating> ratings =
       (RDD<Rating>) this.getDDF().getRepresentationHandler().get(RDD.class, Rating.class);
   return new ROCComputer().computeRmse(ratings, predictions, false);
 }
Пример #2
0
  @Override
  public DDF loadFromJDBC(JDBCDataSourceDescriptor dataSource) throws DDFException {
    SparkDDFManager sparkDDFManager = (SparkDDFManager) mDDFManager;
    HiveContext sqlContext = sparkDDFManager.getHiveContext();

    JDBCDataSourceCredentials cred =
        (JDBCDataSourceCredentials) dataSource.getDataSourceCredentials();
    String fullURL = dataSource.getDataSourceUri().getUri().toString();
    if (cred.getUsername() != null && !cred.getUsername().equals("")) {
      fullURL += String.format("?user=%s&password=%s", cred.getUsername(), cred.getPassword());
    }

    Map<String, String> options = new HashMap<String, String>();
    options.put("url", fullURL);
    options.put("dbtable", dataSource.getDbTable());
    DataFrame df = sqlContext.load("jdbc", options);

    DDF ddf =
        sparkDDFManager.newDDF(
            sparkDDFManager,
            df,
            new Class<?>[] {DataFrame.class},
            null,
            SparkUtils.schemaFromDataFrame(df));
    // TODO?
    ddf.getRepresentationHandler().get(RDD.class, Row.class);
    ddf.getMetaDataHandler().setDataSourceDescriptor(dataSource);
    return ddf;
  }
Пример #3
0
  @Override
  /*
   * input expected RDD[double[][]]
   * (non-Javadoc)
   * @see io.ddf.ml.AMLMetricsSupporter#roc(io.ddf.DDF, int)
   */
  public RocMetric roc(DDF predictionDDF, int alpha_length) throws DDFException {

    RDD<LabeledPoint> rddLabeledPoint =
        (RDD<LabeledPoint>)
            predictionDDF.getRepresentationHandler().get(RDD.class, LabeledPoint.class);
    ROCComputer rc = new ROCComputer();

    return (rc.ROC(rddLabeledPoint, alpha_length));
  }