将特征重要性向量压缩到列名数组时出现Scala java.io toArray错误
尝试将功能重要性向量从lightGBM将特征重要性向量压缩到列名数组时出现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)
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
。嗨,这很有效!谢谢