Skip to content

Instantly share code, notes, and snippets.

@jasonyandell
Forked from jyandell1/gist:2886363
Created June 7, 2012 17:45
Show Gist options
  • Save jasonyandell/2890301 to your computer and use it in GitHub Desktop.
Save jasonyandell/2890301 to your computer and use it in GitHub Desktop.
"Real" stats terms (e.g. μ, σ) in F#??
// from http://blog.codebeside.org/post/2011/10/27/F-as-a-OctaveMatlab-replacement-for-Machine-Learning.aspx
let featureNormalize (X: #Matrix<float>) =
let μ =
X.ColumnEnumerator()
|> Seq.map (fun (j, col) -> col.Mean())
|> DenseVector.ofSeq
let σ =
X.ColumnEnumerator()
|> Seq.map (fun (j, col) -> col.StandardDeviation())
|> DenseVector.ofSeq
let X =
X |> Matrix.mapRows (fun i row -> (row - μ) ./ σ)
(X, μ, σ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment