Skip to content

Instantly share code, notes, and snippets.

@jyandell1
Created June 7, 2012 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jyandell1/2886363 to your computer and use it in GitHub Desktop.
Save jyandell1/2886363 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