當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。