提前感谢您的任何回复,这个论坛上的答案对我的研究非常宝贵。我是一名学生,为了语言范式的研究项目而学习 F#,并尝试利用 http://trelford.com/blog/post/specialk.aspx 中的一个精彩示例。为了使用简单的 k 均值算法。我收到一个错误,我不知道如何修复,希望得到一些指导。非常有义务,这里是代码,错误是:在行上缺少资格错误。`花瓣宽度
|])行
//代码来自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))
最佳答案
看起来您在这里缺少一个反勾号:
row.``Petal Width`|])
应该是:
row.``Petal Width``|])
关于visual-studio-2010 - 在行 .`` 花瓣宽度`|]) 行上出现缺少资格错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717536/