Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deedle normalize frame

Tags:

f#

deedle

How to normalize data in deedle frame ?

I've tried this approach but one doesn't work

 let iris = Frame.ReadCsv("./iris.csv")
 let keys = iris.ColumnKeys |> Seq.toArray
 let x = iris.Columns.[keys.[0..4]]
 let mu = x |> Stats.mean 
 let std = x |> Stats.stdDev
 //Not working becasue couldnt substract series from frame 
 let norm = (x - mu) / std
like image 409
baio Avatar asked Aug 26 '16 21:08

baio


1 Answers

The frame - series overload expects that you are subtracting the series from all columns of the frame, i.e. that the row keys of the frame and the row keys of the series align.

For your use case, you need to align the column keys - there is no single operator for this, but you can do it using the mapRows function:

let x = iris.Columns.[keys.[0..3]]
let mu = x |> Stats.mean 
let std = x |> Stats.stdDev

let norm = 
  x 
  |> Frame.mapRowValues (fun r -> (r.As<float>() - mu) / std)
  |> Frame.ofRows

I also changed your x to be just from keys.[0..3] because otherwise you'd be trying to normalize column of type string, which fails.

like image 59
Tomas Petricek Avatar answered Sep 19 '22 22:09

Tomas Petricek