如何规范化deedle框架中的数据?
我尝试过这种方法,但一种方法不起作用
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
Run Code Online (Sandbox Code Playgroud)
该frame - series超载期待您减去series从的所有列frame,即该帧的行键和一系列对齐的行键.
对于您的用例,您需要对齐列键 - 没有单个操作符,但您可以使用以下mapRows函数执行此操作:
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
Run Code Online (Sandbox Code Playgroud)
我也改变了你的意思x,keys.[0..3]因为否则你会试图规范化类型的列string,但是失败了.