提前感谢您的回复,本论坛的答案在我的研究中非常宝贵。我是学生学习F#,用于语言范例的研究项目,并试图利用http://trelford.com/blog/post/specialk.aspx中的一个神话般的例子,以便使用简单的k-means算法。我收到一个错误我不知道如何修复,并希望得到一些指导。很多Oblaged,以下是代码和错误:在行上获得缺少资格错误。`Petal Width
|])行
//代码来自http://trelford.com/blog/post/specialk.aspx
open System
open FSharp
type Iris = CsvProvider<irisDataFile>
let iris = Iris.Load(irisDataFile)
let irisData = iris.Data |> Seq.toArray
//
///// classifcations
let y = irisData |> Array.map (fun row -> row.Class)
/// feature vectors
let X = irisData |> Array.map (fun row ->
[|row.``Sepal Length``
row.``Sepal Width``
row.``Petal Length``
row.``Petal Width`|])
//Computing k-means centroids:
let K = 3 // The Iris dataset is known to only have 3 clusters
let seed =
[|X.[0]; X.[1]; X.[2]|] // pick bad centroids on purpose
let centroidResults =
KMeans.computeCentroids seed X |> Seq.take iterationLimit
(* K-Means Algorithm *)
/// Group all the vectors by the nearest center.
let classify centroids vectors =
vectors |> Array.groupBy (fun v -> centroids |> Array.minBy (distance v))
/// Repeatedly classify the vectors, starting with the seed centroids
let computeCentroids seed vectors =
seed |> Seq.iterate (fun centers -> classify centers vectors |> Array.map (snd >> average))
答案 0 :(得分:3)
看起来你在这里错过了一个回答:
row.``Petal Width`|])
应该是:
row.``Petal Width``|])