Tech Tips

  1. Uncategorized
  2. 73 view

[Scala]Data scaling with linear interpolation

What I want to do

I’ll try to transform data with studying Scala. I’ll do scaling data with Linear Interpolation to make data range from 0 to 1.
linearinterpol
Here is Linear Interpolation’s expression.
Calculate rate of maximum differential value with data differential value.

Source code

import scala.util.Random

object LinearInterpolation {
    def main(args: Array[String]) {
        // Make random array
        def randomArray(size:Int, max_val:Int)={
            val rand = new Random
            for (a <- 0 to size) yield rand.nextInt(max_val)
        }
        val data = randomArray(20, 100).toList
        println("values:")
        println(data)

        // Find max and min value
        val max_val = data.reduceLeft{ (a,b) => a max b }
        val min_val = data.reduceLeft{ (a,b) => a min b }
        println("max : " + max_val)
        println("min : " + min_val)

        // Do Linear Interpolation to change the range of values
        val after = data.map(x => (x - min_val).toFloat / (max_val - min_val).toFloat)
        println("after :")
        println(after)
    }
}

Uncategorized recent post

  1. Run Amazon FreeRTOS on M5Stack Core2 for AWS …

  2. Udacity Self-Driving Car Engineer Nanodegree …

  3. Install sbt 1.0.0 and run sample template

  4. Visualization of Neural Network and its Train…

  5. [Machine Learning]Created docker image includ…

関連記事

PAGE TOP