apache-spark - 如何确定逻辑回归spark中的标签和特征?

标签 apache-spark machine-learning

我正在使用spark mlib,并使用Logistic回归模型进行分类。我点击了这个链接: https://spark.apache.org/docs/2.1.0/ml-classification-regression.html#logistic-regression

 import org.apache.spark.ml.classification.LogisticRegression;
import org.apache.spark.ml.classification.LogisticRegressionModel;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

// Load training data
Dataset<Row> training = spark.read().format("libsvm")
  .load("data/mllib/sample_libsvm_data.txt");

LogisticRegression lr = new LogisticRegression()
  .setMaxIter(10)
  .setRegParam(0.3)
  .setElasticNetParam(0.8);

// Fit the model
LogisticRegressionModel lrModel = lr.fit(training);

// Print the coefficients and intercept for logistic regression
System.out.println("Coefficients: "
  + lrModel.coefficients() + " Intercept: " + lrModel.intercept());

// We can also use the multinomial family for binary classification
LogisticRegression mlr = new LogisticRegression()
        .setMaxIter(10)
        .setRegParam(0.3)
        .setElasticNetParam(0.8)
        .setFamily("multinomial");

// Fit the model
LogisticRegressionModel mlrModel = mlr.fit(training);

如果我将 .csv 作为输入,我不确定该模型如何识别标签和特征?谁能解释一下吗?

最佳答案

因为你从at数据加载libsvm,它由标签index1:value1 index2:value2......组成 如果使用.csv,显然必须指定参数。

关于apache-spark - 如何确定逻辑回归spark中的标签和特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43652725/

相关文章:

sql - Spark scala : SELECT in a foreach loop returns java. lang.NullPointerException

python - Scikit学习: Applying Mean Shift on a multi-dimensional dataset

python - 感知器学习算法需要大量迭代才能收敛?

scala - 如何解压 Spark DataSet 中的多个键

machine-learning - 能够切换数据集的随机森林算法

python - 使用 Keras 编程多输入神经网络架构

android-studio - 如何在 Android Studio 中使用 onnxruntime 和 .ort 模型

apache-spark - 有什么方法可以将 Spark 的 Dataset.show() 方法的输出作为字符串获取吗?

apache-spark - 更改 spark _temporary 目录路径

java - 如何将 Kafka 数据源中的值转换为给定的模式?