Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.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
将特征重要性向量压缩到列名数组时出现Scala java.io toArray错误_Java_Scala_Apache Spark_Java Io_Lightgbm - Fatal编程技术网

将特征重要性向量压缩到列名数组时出现Scala java.io toArray错误

将特征重要性向量压缩到列名数组时出现Scala java.io toArray错误,java,scala,apache-spark,java-io,lightgbm,Java,Scala,Apache Spark,Java Io,Lightgbm,尝试将功能重要性向量从lightGBMgetfeatureImportances压缩到列名数组时,我遇到了以下错误: import com.microsoft.ml.spark.LightGBMClassificationModel 导入org.apache.spark.ml.classification.RandomForestClassificationModel def getFeatureImportances(inputContainer:PipelineModelContainer)

尝试将功能重要性向量从lightGBM
getfeatureImportances
压缩到列名数组时,我遇到了以下错误:

import com.microsoft.ml.spark.LightGBMClassificationModel
导入org.apache.spark.ml.classification.RandomForestClassificationModel
def getFeatureImportances(inputContainer:PipelineModelContainer):(字符串,字符串)={
val transformer=inputContainer.pipelineModel.stages.last
val featureImportancesVector=inputContainer.params匹配{
案例参数(numTrees、treeDepth、featureTransformer)=>
transformer.asInstanceOf[RandomForestClassificationModel]。功能重要性
案例灯光MPA参数(树顶、numLeaves、迭代、featureTransformer)=>
transformer.asInstanceOf[LightGBMClassificationModel].getFeatureImportances(“拆分”)
}
val colNames=inputContainer.featureColNames
val sortedFeatures=(colNames zip featureImportancesVector.toArray).sortWith(u.\u 2>u.\u 2).zipWithIndex
}
我在代码的最后一行遇到此错误:

value toArray is not a member of java.io.Serializable

似乎无法将light GBM功能的重要性转换为数组。如果这只是分类器特性的重要性,那么这段代码可以很好地工作。我还可以做什么?

匹配
块的两个分支中, 一,, 另一个

这两种类型的通用超级类型是
java.io.Serializable
, 因此Scala推断了变量
featureImportancesVector
的类型。
toArray
在该类型中不可用, 尽管这种方法在两种情况下都存在

要解决此问题很容易,请按照注释中的建议,将
.toArray
移动到
功能重要性

因此,两个分支的类型以及变量的类型在
匹配
块的两个分支中变为
数组[Double]
, 一,, 另一个

这两种类型的通用超级类型是
java.io.Serializable
, 因此Scala推断了变量
featureImportancesVector
的类型。
toArray
在该类型中不可用, 尽管这种方法在两种情况下都存在

要解决此问题很容易,请按照注释中的建议,将
.toArray
移动到
功能重要性

因此,两个分支的类型,以及变量的类型,都变成了
Array[Double]

您不能将
.toArray
调用从
zip
参数移动到
transformer.asInstanceOf[RandomForestClassificationModel].featureImportances
表达式吗?这样,如果我正确理解了源代码,featureImportancesVector应该变成
Array[Double]
而不是
Serializable
。嗨,这很有效!感谢您将
.toArray
调用从
zip
参数移动到
transformer.asInstanceOf[RandomForestClassificationModel]。featureImportances
表达式?这样,如果我正确理解了源代码,featureImportancesVector应该变成
Array[Double]
而不是
Serializable
。嗨,这很有效!谢谢