特征转换 - Discrete Cosine Transform (DCT)

优质
小牛编辑
128浏览
2023-12-01

  Discrete Cosine Transform将一个在时间域(time domain)内长度为N的实值序列转换为另外一个
在频率域(frequency domain)内的长度为N的实值序列。下面是程序调用的例子。

  1. import org.apache.spark.ml.feature.DCT
  2. import org.apache.spark.ml.linalg.Vectors
  3. val data = Seq(
  4. Vectors.dense(0.0, 1.0, -2.0, 3.0),
  5. Vectors.dense(-1.0, 2.0, 4.0, -7.0),
  6. Vectors.dense(14.0, -2.0, -5.0, 1.0))
  7. val df = spark.createDataFrame(data.map(Tuple1.apply)).toDF("features")
  8. val dct = new DCT()
  9. .setInputCol("features")
  10. .setOutputCol("featuresDCT")
  11. .setInverse(false)
  12. val dctDf = dct.transform(df)
  13. dctDf.select("featuresDCT").show(3)