Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Spark流水线中特征向量列长度的获取_Python_Apache Spark_Pyspark - Fatal编程技术网

Python Spark流水线中特征向量列长度的获取

Python Spark流水线中特征向量列长度的获取,python,apache-spark,pyspark,Python,Apache Spark,Pyspark,我有一个有趣的问题 我正在使用Pipeline对象运行一个ML任务 这就是管道对象的外观 jpsa_mlp.pipeline.getStages() Out[244]: [StringIndexer_479d82259c10308d0587, Tokenizer_4c5ca5ea35544bb835cb, StopWordsRemover_4641b68e77f00c8fbb91, CountVectorizer_468c96c6c714b1000eef, IDF_465eb809477

我有一个有趣的问题

我正在使用Pipeline对象运行一个ML任务

这就是管道对象的外观

jpsa_mlp.pipeline.getStages()
Out[244]:
[StringIndexer_479d82259c10308d0587,
 Tokenizer_4c5ca5ea35544bb835cb,
 StopWordsRemover_4641b68e77f00c8fbb91,
 CountVectorizer_468c96c6c714b1000eef,
 IDF_465eb809477c6c986ef9,
 MultilayerPerceptronClassifier_4a67befe93b015d5bd07]
这个管道对象中的所有估计器和转换器都被编码为类方法的一部分,JPSA是类对象

现在我想提出一种超参数调整的方法。因此,我使用以下方法:

 self.paramGrid = ParamGridBuilder()\
            .addGrid(self.pipeline.getStages()[5].layers, [len(self.pipeline.getStages()[3].vocab),10,3])\
            .addGrid(self.pipeline.getStages()[5].maxIter, [100,300])\
            .build()
问题是对于神经网络分类器,超参数之一基本上是隐藏层大小。MLP分类器的层属性要求输入层、隐藏层和输出层的大小。输入和输出是固定的(基于我们拥有的数据)。所以我想把输入层的大小作为我的特征向量的大小。但是,我不知道特征向量的大小,因为用于创建特征向量的管道对象(Count Vectorizer,IDF)中的估计器尚未适合数据

管道对象将使用Spark的交叉验证程序对象在交叉验证期间拟合数据。然后只有我才能让CountVectorizerModel知道特征向量的大小

如果我实现了Countvectorizer,那么我可以使用countvectorizerModel.vocab获取特征向量的长度,并将其用作mlp的layers属性中输入层值的参数


那么,如何为mlp的层添加超参数(隐藏层和输入层大小)

您可以从数据帧架构元数据中找到该信息

Scala代码:

val length = datasetAfterPipe.schema(datasetAfterPipe.schema.fieldIndex("columnName"))
    .metadata.getMetadata("ml_attr").getLong("num_attrs")