当前位置: 首页>>代码示例>>Java>>正文


Java LinearRegressionModel类代码示例

本文整理汇总了Java中org.apache.spark.ml.regression.LinearRegressionModel的典型用法代码示例。如果您正苦于以下问题:Java LinearRegressionModel类的具体用法?Java LinearRegressionModel怎么用?Java LinearRegressionModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LinearRegressionModel类属于org.apache.spark.ml.regression包,在下文中一共展示了LinearRegressionModel类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LinearRegressionModelConverter

import org.apache.spark.ml.regression.LinearRegressionModel; //导入依赖的package包/类
public LinearRegressionModelConverter(LinearRegressionModel model){
	super(model);
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:4,代码来源:LinearRegressionModelConverter.java

示例2: encodeModel

import org.apache.spark.ml.regression.LinearRegressionModel; //导入依赖的package包/类
@Override
public RegressionModel encodeModel(Schema schema){
	LinearRegressionModel model = getTransformer();

	return RegressionModelUtil.createRegression(schema.getFeatures(), VectorUtil.toList(model.coefficients()), model.intercept(), null, schema);
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:7,代码来源:LinearRegressionModelConverter.java

示例3: start

import org.apache.spark.ml.regression.LinearRegressionModel; //导入依赖的package包/类
private void start() {
    SparkSession spark = SparkSession.builder().appName("Simple prediction from Text File").master("local").getOrCreate();

    spark.udf().register("vectorBuilder", new VectorBuilder(), new VectorUDT());

    String filename = "data/tuple-data-file.csv";
    StructType schema = new StructType(
            new StructField[] { new StructField("_c0", DataTypes.DoubleType, false, Metadata.empty()),
                    new StructField("_c1", DataTypes.DoubleType, false, Metadata.empty()),
                    new StructField("features", new VectorUDT(), true, Metadata.empty()), });

    Dataset<Row> df = spark.read().format("csv").schema(schema).option("header", "false")
            .load(filename);
    df = df.withColumn("valuefeatures", df.col("_c0")).drop("_c0");
    df = df.withColumn("label", df.col("_c1")).drop("_c1");
    df.printSchema();

    df = df.withColumn("features", callUDF("vectorBuilder", df.col("valuefeatures")));
    df.printSchema();
    df.show();

    LinearRegression lr = new LinearRegression().setMaxIter(20);// .setRegParam(1).setElasticNetParam(1);

    // Fit the model to the data.
    LinearRegressionModel model = lr.fit(df);

    // Given a dataset, predict each point's label, and show the results.
    model.transform(df).show();

    LinearRegressionTrainingSummary trainingSummary = model.summary();
    System.out.println("numIterations: " + trainingSummary.totalIterations());
    System.out.println("objectiveHistory: " + Vectors.dense(trainingSummary.objectiveHistory()));
    trainingSummary.residuals().show();
    System.out.println("RMSE: " + trainingSummary.rootMeanSquaredError());
    System.out.println("r2: " + trainingSummary.r2());

    double intercept = model.intercept();
    System.out.println("Interesection: " + intercept);
    double regParam = model.getRegParam();
    System.out.println("Regression parameter: " + regParam);
    double tol = model.getTol();
    System.out.println("Tol: " + tol);
    Double feature = 7.0;
    Vector features = Vectors.dense(feature);
    double p = model.predict(features);

    System.out.println("Prediction for feature " + feature + " is " + p);
    System.out.println(8 * regParam + intercept);
}
 
开发者ID:jgperrin,项目名称:net.jgp.labs.spark,代码行数:50,代码来源:SimplePredictionFromTextFile.java


注:本文中的org.apache.spark.ml.regression.LinearRegressionModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。