Python 如何将多列作为特征传递给Spark中的Logistic回归分类器?

Python 如何将多列作为特征传递给Spark中的Logistic回归分类器?,python,apache-spark,machine-learning,pyspark,logistic-regression,Python,Apache Spark,Machine Learning,Pyspark,Logistic Regression,我试图用一个简单的数据集运行逻辑回归,以理解pyspark的语法。 我的数据看起来有11列,其中前10列是特征,最后一列(第11列)是标签。 我想将这10列作为特征传递,第11列作为标签传递。 但是我只知道使用featuresCol=“col\u header\u name” 我已经使用pandas从csv文件中读取了数据,但我已经将其转换为RDD。 代码如下: from pyspark.ml.classification import LogisticRegression from pyspa

我试图用一个简单的数据集运行逻辑回归,以理解pyspark的语法。 我的数据看起来有11列,其中前10列是特征,最后一列(第11列)是标签。 我想将这10列作为特征传递,第11列作为标签传递。 但是我只知道使用
featuresCol=“col\u header\u name”
我已经使用pandas从csv文件中读取了数据,但我已经将其转换为RDD。 代码如下:

from pyspark.ml.classification import LogisticRegression
from pyspark.sql import SQLContext
from pyspark import SparkContext
import pandas as pd
data = pd.read_csv('abc.csv')
sc = SparkContext("local", "App Name")
sql = SQLContext(sc)
spDF = sql.createDataFrame(data)
tri=LogisticRegression(maxIter=10,regParam=0.01,featuresCol="single_column",labelCol="label")
lr_model = tri.fit(spDF)
如果我使用
featuresCol=[list\u of\u header\u names]
我会得到错误。 我使用了sk learn,它的语法非常简单,比如:

reg=LogisticRegression()
reg=reg.fit(Dataframe_of_features,Label_array)

您需要使用向量汇编器将所有列合并到一个特征数组中

from pyspark.ml.linalg import Vectors
from pyspark.ml.feature import VectorAssembler
assembler = VectorAssembler(inputCols=[list_of_header_names],outputCol="features")
spDF = assembler.transform(spDF)
然后可以将所有变量的组合数组作为逻辑回归的输入传递给逻辑回归

tri=LogisticRegression(maxIter=10,
                       regParam=0.01,
                       featuresCol="features",
                       labelCol="label")
lr_model = tri.fit(spDF)

有哪些错误?
TypeError:为参数“featuresCol”提供的参数值无效。无法转换为字符串类型,这有一定意义,因为根据语法,
featuresCol=“name\u of_column”
是一个字符串。当您有
featuresCol=“single\u column”
时,这真的是错误吗?它可以工作,谢谢!还有一件事。什么是MaxIter,RegParam和ElasticNetParam?MaxIter是最大迭代次数,RegParam是正则化参数。Elastic Net Param指定损失函数是L1还是L2。谢谢,但我知道完整的形式!我想知道他们的目的。