scala Smile机器学习库中未解析的导入

pw9qyyiw  于 2023-02-12  发布在  Scala
关注(0)|答案(2)|浏览(128)

以下导入未解析。

import smile.data.{Attribute, AttributeDataset, NumericAttribute}

如果这些属性从新的微笑版本3.0.0中删除,你对此有什么想法吗?
我使用的是Scala 2.13.10。
如何将下面的代码翻译成Smile v3.0.0?

import smile.clustering.KMeans
import smile.data.{AttributeDataset, NumericAttribute}
import smile.read
import smile.write

// Load the data into a Smile AttributeDataset
val data: AttributeDataset = read.csv("data.csv", header = true)

// Split the data into two equal parts
val (data1, data2) = data.split(0.5)

// Train a k-means clustering model on the first part of the data
val model1 = KMeans.fit(data1.x(), 3)

// Train another k-means clustering model on the second part of the data
val model2 = KMeans.fit(data2.x(), 3)
pgvzfuti

pgvzfuti1#

smile.data.{Attribute, AttributeDataset, NumericAttribute}一直存在到Smile 1.5.3(Scala 2.10.x-2.12.x)
https://mvnrepository.com/artifact/com.github.haifengl/smile-scala
已在Smile 2.0.0(2019年11月22日)中删除
https://github.com/haifengl/smile/commit/07c5d2507d6ee8bd1dd68202fdbb323dada91a2fStructType似乎取代了Attribute[]
https://github.com/haifengl/smile/releases/tag/v2.0.0

  • 完全重新设计的API。它更精简,更简单,甚至更友好。
oymdgrw7

oymdgrw72#

好的,完成了,chatGPT做到了:)

// Load the data for instance 2
  val data2 = Array(
    Array(5.0, 7.0),
    Array(3.5, 5.0),
    Array(4.5, 5.0),
    Array(3.5, 4.5)
  )

  // Train the KMeans model with 2 clusters for instance 1
  val model1 = KMeans.fit(data2, 2)
  
  // Use the combined model to predict the cluster for new instances
  val prediction = model1.predict(Array(4.0, 5.0))
  println(s"Instance belongs to cluster: $prediction")

相关问题