Clustering

Binder

Summary: this tutorial demonstrates several clustering methods in FSharp.Stats and how to visualize the results with Plotly.NET.

Table of contents

For demonstration of several clustering methods, the classic iris data set is used, which consists of 150 records, each of which contains four measurements and a species identifier. Since the species identifier occur several times (Iris-virginica, Iris-versicolor, and Iris-setosa), the first step is to generate unique labels:

  • The data is shuffled and an index is appended to the data label, such that each label is unique.
open FSharp.Stats

let fromFileWithSep (separator:char) (filePath) =     
    // The function is implemented using a sequence expression
    seq {   let sr = System.IO.File.OpenText(filePath)
            while not sr.EndOfStream do 
                let line = sr.ReadLine() 
                let words = line.Split separator//[|',';' ';'\t'|] 
                yield words }

                
let lables,data =
    fromFileWithSep ',' (__SOURCE_DIRECTORY__ + "/data/irisData.csv")
    |> Seq.skip 1
    |> Seq.map (fun arr -> arr.[4], [| float arr.[0]; float arr.[1]; float arr.[2]; float arr.[3]; |])
    |> Seq.toArray
    |> Array.shuffleFisherYates
    |> Array.mapi (fun i (lable,data) -> sprintf "%s_%i" lable i, data)
    |> Array.unzip
   

let's first take a look at the dataset with Plotly.NET:

open Plotly.NET

let colnames = ["Sepal length";"Sepal width";"Petal length";"Petal width"]

let colorscaleValue = 
    StyleParam.Colorscale.Electric //Custom [(0.0,"#3D9970");(1.0,"#001f3f")]
    
let dataChart = 
    Chart.Heatmap(data,ColNames=colnames,RowNames=(lables |> Seq.mapi (fun i s -> sprintf "%s%i" s i )),Colorscale=colorscaleValue,Showscale=true)
    |> Chart.withMarginSize(Left=250.)
    |> Chart.withTitle "raw iris data"

Iterative Clustering

k-means clustering

In k-means clustering a cluster number has to be specified prior to clustering the data. K centroids are randomly chosen. After all data points are assigned to their nearest centroid, the algorithm iteratively approaches a centroid position configuration, that minimizes the dispersion of every of the k clusters. For cluster number determination see below (Determining the optimal number of clusters).

open FSharp.Stats.ML
open FSharp.Stats.ML.Unsupervised
open FSharp.Stats.ML.Unsupervised.HierarchicalClustering

// Kmeans clustering

// For random cluster inititalization use randomInitFactory:
let rnd = new System.Random()
let randomInitFactory : IterativeClustering.CentroidsFactory<float []> = 
    IterativeClustering.randomCentroids<float []> rnd

//let cvmaxFactory : IterativeClustering.CentroidsFactory<float []> = 
//    IterativeClustering.intitCVMAX
  
let kmeansResult = 
    IterativeClustering.kmeans <| DistanceMetrics.euclidean <| randomInitFactory 
    <| data <| 4

let clusteredIrisData =
    Array.zip lables data
    |> Array.sortBy (fun (l,dataPoint) -> fst (kmeansResult.Classifier dataPoint)) 
    |> Array.unzip
    |> fun (labels,d) -> 
        Chart.Heatmap(d,ColNames=colnames,RowNames=labels,Colorscale=colorscaleValue,Showscale=true)
        |> Chart.withMarginSize(Left=250.)
        |> Chart.withTitle "clustered iris data (k-means clustering)"
// To get the best kMeans clustering result in terms of the average squared distance of each point
// to its centroid, perform the clustering b times and minimize the dispersion.
let getBestkMeansClustering data k bootstraps =
    [1..bootstraps]
    |> List.mapi (fun i x -> 
        IterativeClustering.kmeans <| DistanceMetrics.euclidean <| randomInitFactory <| data <| k
        )
    |> List.minBy (fun clusteringResult -> IterativeClustering.DispersionOfClusterResult clusteringResult)

Density based clustering

DBSCAN

//four dimensional clustering with sepal length, petal length, sepal width and petal width
let t = DbScan.compute DistanceMetrics.Array.euclideanNaN 5 1.0 data

//extract petal length and petal width
let petLpetW      = data |> Array.map (fun x -> [|x.[2];x.[3]|])

//extract petal width, petal length and sepal length  
let petWpetLsepL = data |> Array.map (fun x -> [|x.[3];x.[2];x.[0]|])

let axis title = Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)

//to create a chart with two dimensional data use the following function
let dbscanPlot =  

    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)

    if (petLpetW |> Seq.head |> Seq.length) <> 2 then failwithf "create2dChart only can handle 2 coordinates"
    
    let result = DbScan.compute DistanceMetrics.Array.euclidean 20 0.5 petLpetW
    
    let chartCluster = 
        if result.Clusterlist |> Seq.length > 0 then      
            result.Clusterlist
            |> Seq.mapi (fun i l ->
                l
                |> Seq.map (fun x -> x.[0],x.[1])
                |> Seq.distinct //more efficient visualization; no difference in plot but in point numbers
                |> Chart.Point
                |> Chart.withTraceName (sprintf "Cluster %i" i))
            |> Chart.Combine
        else Chart.Point []

    let chartNoise = 
        if result.Noisepoints |> Seq.length > 0 then 
            result.Noisepoints
            |> Seq.map (fun x -> x.[0],x.[1])  
            |> Seq.distinct //more efficient visualization; no difference in plot but in point numbers
            |> Chart.Point
            |> Chart.withTraceName "Noise"
        else Chart.Point []

    let chartname = 
        let noiseCount    = result.Noisepoints |> Seq.length
        let clusterCount  = result.Clusterlist |> Seq.length
        let clPtsCount    = result.Clusterlist |> Seq.sumBy Seq.length
        sprintf "eps:%.1f minPts:%i pts:%i cluster:%i noisePts:%i" 
            0.5 20 (noiseCount + clPtsCount) clusterCount noiseCount 

    [chartNoise;chartCluster]
    |> Chart.Combine
    |> Chart.withTitle chartname
    |> Chart.withX_Axis (axis "Petal width") 
    |> Chart.withY_Axis (axis "Petal length")
    
//to create a chart with three dimensional data use the following function
let create3dChart (dfu:array<'a> -> array<'a> -> float) (minPts:int) (eps:float) (input:seq<#seq<'a>>) =   
    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)
    
    if (input |> Seq.head |> Seq.length) <> 3 then failwithf "create3dChart only can handle 3 coordinates"
    
    let result = DbScan.compute dfu minPts eps input
    
    let chartCluster = 
        if result.Clusterlist |> Seq.length > 0 then 
            result.Clusterlist
            |> Seq.mapi (fun i l ->
                l
                |> Seq.map (fun x -> x.[0],x.[1],x.[2])
                |> Seq.distinct //faster visualization; no difference in plot but in point number
                |> fun x -> Chart.Scatter3d (x,StyleParam.Mode.Markers)
                |> Chart.withTraceName (sprintf "Cluster_%i" i))
            |> Chart.Combine
        else  Chart.Scatter3d ([],StyleParam.Mode.Markers)

    let chartNoise =
        if result.Noisepoints |> Seq.length > 0 then 
            result.Noisepoints
            |> Seq.map (fun x -> x.[0],x.[1],x.[2])  
            |> Seq.distinct //faster visualization; no difference in plot but in point number
            |> fun x -> Chart.Scatter3d (x,StyleParam.Mode.Markers)
            |> Chart.withTraceName "Noise"
        else Chart.Scatter3d ([],StyleParam.Mode.Markers)

    let chartname = 
        let noiseCount    = result.Noisepoints |> Seq.length
        let clusterCount  = result.Clusterlist |> Seq.length
        let clPtsCount    = result.Clusterlist |> Seq.sumBy Seq.length
        sprintf "eps:%.1f minPts:%i n:%i Cluster:%i NoisePts:%i" 
            eps minPts (noiseCount + clPtsCount) clusterCount noiseCount 

    [chartNoise;chartCluster]
    |> Chart.Combine
    |> Chart.withTitle chartname
    |> Chart.withX_Axis (axis "Petal width")
    |> Chart.withY_Axis (axis "Petal length")
    |> Chart.withZ_Axis (axis "Sepal length")
        
//for faster computation you can use the squaredEuclidean distance and set your eps to its square
let clusteredChart3D = create3dChart DistanceMetrics.Array.euclideanNaNSquared 20 (0.7**2.) petWpetLsepL 

Hierarchical clustering

Hierarchical clustering results in a tree structure, that has a single cluster (node) on its root and recursively splits up into clusters of elements that are more similar to each other than to elements of other clusters. For generating multiple cluster results with different number of clusters, the clustering has to performed only once. Subsequently a threshold can be determined which will result in the desired number of clusters.

open FSharp.Stats.ML.Unsupervised.HierarchicalClustering

// calculates the clustering and reports a single root cluster (node), 
// that may recursively contains further nodes
let clusterResultH = 
    HierarchicalClustering.generate DistanceMetrics.euclideanNaNSquared Linker.wardLwLinker data

// If a desired cluster number is specified, the following function cuts the cluster according
// to the depth, that results in the respective number of clusters (here 3). Only leaves are reported.
let threeClustersH = HierarchicalClustering.cutHClust 3 clusterResultH
    

Every cluster leaf contains its raw values and an index that indicates the position of the respective data point in the raw data. The index can be retrieved from leaves by HierarchicalClustering.getClusterId.

let inspectThreeClusters =
    threeClustersH
    |> List.map (fun cluster -> 
        cluster
        |> List.map (fun leaf -> 
            lables.[HierarchicalClustering.getClusterId leaf]
            )
        )
    |> fun clusteredLabels -> 
        sprintf "Detailed information for %i clusters is given:" clusteredLabels.Length,clusteredLabels
    
("Detailed information for 3 clusters is given:",
 [["Iris-versicolor_32"; "Iris-versicolor_54"; "Iris-versicolor_70";
   "Iris-virginica_41"; "Iris-virginica_106"; "Iris-versicolor_142";
   "Iris-virginica_123"; "Iris-versicolor_48"; "Iris-versicolor_72";
   "Iris-versicolor_69"; "Iris-versicolor_92"; "Iris-versicolor_52";
   "Iris-versicolor_139"; "Iris-versicolor_89"; "Iris-versicolor_76";
   "Iris-versicolor_63"; "Iris-versicolor_78"; "Iris-versicolor_5";
   "Iris-versicolor_51"; "Iris-versicolor_121"; "Iris-versicolor_27";
   "Iris-versicolor_71"; "Iris-versicolor_128"; "Iris-virginica_77";
   "Iris-versicolor_145"; "Iris-versicolor_18"; "Iris-virginica_37";
   "Iris-virginica_122"; "Iris-virginica_90"; "Iris-virginica_141";
   "Iris-versicolor_31"; "Iris-versicolor_47"; "Iris-virginica_130";
   "Iris-virginica_39"; "Iris-virginica_143"; "Iris-virginica_144";
   "Iris-virginica_101"; "Iris-virginica_28"; "Iris-versicolor_112";
   "Iris-versicolor_135"; "Iris-versicolor_98"; "Iris-versicolor_99";
   "Iris-versicolor_75"; "Iris-versicolor_100"; "Iris-versicolor_93";
   "Iris-versicolor_20"; "Iris-versicolor_59"; "Iris-virginica_83";
   "Iris-versicolor_0"; "Iris-versicolor_9"; "Iris-versicolor_114";
   "Iris-versicolor_44"; "Iris-versicolor_107"; "Iris-versicolor_111";
   "Iris-versicolor_2"; "Iris-versicolor_55"; "Iris-versicolor_33";
   "Iris-versicolor_103"; "Iris-versicolor_49"; "Iris-versicolor_95";
   "Iris-versicolor_17"; "Iris-versicolor_86"; "Iris-versicolor_147";
   "Iris-versicolor_53"];
  ["Iris-virginica_19"; "Iris-virginica_126"; "Iris-virginica_64";
   "Iris-virginica_119"; "Iris-virginica_7"; "Iris-virginica_105";
   "Iris-virginica_134"; "Iris-virginica_97"; "Iris-virginica_149";
   "Iris-virginica_115"; "Iris-virginica_15"; "Iris-virginica_109";
   "Iris-virginica_108"; "Iris-virginica_117"; "Iris-virginica_34";
   "Iris-virginica_35"; "Iris-virginica_82"; "Iris-virginica_87";
   "Iris-versicolor_79"; "Iris-virginica_96"; "Iris-virginica_131";
   "Iris-virginica_16"; "Iris-virginica_40"; "Iris-virginica_66";
   "Iris-virginica_85"; "Iris-virginica_120"; "Iris-virginica_132";
   "Iris-virginica_21"; "Iris-virginica_80"; "Iris-virginica_8";
   "Iris-virginica_73"; "Iris-virginica_14"; "Iris-virginica_113";
   "Iris-virginica_30"; "Iris-virginica_68"; "Iris-virginica_125"];
  ["Iris-setosa_38"; "Iris-setosa_42"; "Iris-setosa_36"; "Iris-setosa_67";
   "Iris-setosa_1"; "Iris-setosa_62"; "Iris-setosa_129"; "Iris-setosa_148";
   "Iris-setosa_24"; "Iris-setosa_81"; "Iris-setosa_146"; "Iris-setosa_45";
   "Iris-setosa_124"; "Iris-setosa_137"; "Iris-setosa_104"; "Iris-setosa_46";
   "Iris-setosa_74"; "Iris-setosa_3"; "Iris-setosa_136"; "Iris-setosa_50";
   "Iris-setosa_57"; "Iris-setosa_23"; "Iris-setosa_43"; "Iris-setosa_60";
   "Iris-setosa_26"; "Iris-setosa_94"; "Iris-setosa_10"; "Iris-setosa_29";
   "Iris-setosa_88"; "Iris-setosa_91"; "Iris-setosa_25"; "Iris-setosa_118";
   "Iris-setosa_102"; "Iris-setosa_22"; "Iris-setosa_84"; "Iris-setosa_116";
   "Iris-setosa_127"; "Iris-setosa_133"; "Iris-setosa_4"; "Iris-setosa_140";
   "Iris-setosa_110"; "Iris-setosa_58"; "Iris-setosa_13"; "Iris-setosa_61";
   "Iris-setosa_138"; "Iris-setosa_6"; "Iris-setosa_11"; "Iris-setosa_56";
   "Iris-setosa_65"; "Iris-setosa_12"]])
    
    
// To recursevely flatten the cluster tree into leaves only, use flattenHClust.
// A leaf list is reported, that does not contain any cluster membership, 
// but is sorted by the clustering result.
let hLeaves = 
    clusterResultH
    |> HierarchicalClustering.flattenHClust
    
// takes the sorted cluster result and reports a tuple of lable and data value.
let dataSortedByClustering =    
    hLeaves
    |> Seq.choose (fun c -> 
        let lable  = lables.[HierarchicalClustering.getClusterId c]
        let values = HierarchicalClustering.tryGetLeafValue c
        match values with
        | None -> None
        | Some x -> Some (lable,x)
        )

let hierClusteredDataHeatmap = 
    let (hlable,hdata) =
        dataSortedByClustering
        |> Seq.unzip
    Chart.Heatmap(hdata,ColNames=colnames,RowNames=hlable,Colorscale=colorscaleValue,Showscale=true)
    |> Chart.withMarginSize(Left=250.)
    |> Chart.withTitle "Clustered iris data (hierarchical clustering)"

Determining the optimal number of clusters

Rule of thumb

The rule of thumb is a very crude cluster number estimation only based on the number of data points.

Reference: 'Review on Determining of Cluster in K-means Clustering'; Kodinariya et al; January 2013

//optimal k for iris data set by using rule-of-thumb
let ruleOfThumb = ClusterNumber.kRuleOfThumb data
8.660254038

Elbow criterion

The elbow criterion is a visual method to determine the optimal cluster number. The cluster dispersion is measured as the sum of all average (squared) euclidean distance of each point to its associated centroid. The point at which the dispersion drops drastically and further increase in k does not lead to a strong decrease in dispersion is the optimal k.

Reference: 'Review on Determining of Cluster in K-means Clustering'; Kodinariya et al; January 2013

open IterativeClustering
open DistanceMetrics

let kElbow = 10

let iterations = 10 

let dispersionOfK = 
    [|1..kElbow|]
    |> Array.map (fun k -> 
        let (dispersion,std) = 
            [|1..iterations|]
            |> Array.map (fun i -> 
                kmeans euclideanNaNSquared (randomCentroids rnd) data k
                |> DispersionOfClusterResult)
            |> fun dispersions -> 
                Seq.mean dispersions, Seq.stDev dispersions
        k,dispersion,std
        )

let elbowChart = 

    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)

    Chart.Line (dispersionOfK |> Array.map (fun (k,dispersion,std) -> k,dispersion))
    |> Chart.withYErrorStyle (dispersionOfK |> Array.map (fun (k,dispersion,std) -> std))
    |> Chart.withX_Axis (axis "k")
    |> Chart.withY_Axis (axis "dispersion")
    |> Chart.withTitle "Iris data set dispersion"

AIC

Reference

The Akaike information criterion (AIC) balances the information gain (with raising k) against parameter necessity (number of k). The k that minimizes the AIC is assumed to be the optimal one.

let aicBootstraps = 10

//optimal k for iris data set by using aic
let (aicK,aicMeans,aicStd) =
    //perform 10 iterations and take the mean and standard deviation of the aic
    let aic = 
        [|1..aicBootstraps|]
        |> Array.map (fun b -> ClusterNumber.calcAIC 10 (kmeans euclideanNaNSquared (randomCentroids rnd) data) 15)
    aic
    |> Array.map (fun iteration -> Array.map snd iteration)
    |> JaggedArray.transpose
    |> Array.mapi (fun i aics -> 
        i+1,Seq.mean aics,Seq.stDev aics)
    |> Array.unzip3

let aicChart = 
    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)
    
    Chart.Line (aicK,aicMeans)
    |> Chart.withX_Axis (axis "k")
    |> Chart.withY_Axis (axis "AIC")
    |> Chart.withYErrorStyle aicStd

Silhouette coefficient

The silhouette index ranges from -1 to 1, where -1 indicates a misclassified point, and 1 indicates a perfect fit. It can be calculated for every point by comparing the mean intra cluster distance with the nearest mean inter cluster distance. The mean of all indices can be visualized, where a maximal value indicates the optimal k.

Reference: 'Review on Determining of Cluster in K-means Clustering'; Kodinariya et al; January 2013

// The following example expects the raw data to be clustered by k means clustering.
// If you already have clustered data use the 'silhouetteIndex' function instead.

let silhouetteData = 
    System.IO.File.ReadAllLines(__SOURCE_DIRECTORY__ + "/data/silhouetteIndexData.txt")
    |> Array.map (fun x -> 
        let tmp = x.Split '\t'
        [|float tmp.[0]; float tmp.[1]|])

let sI = 
    ML.Unsupervised.ClusterNumber.silhouetteIndexKMeans 
        50              // number of bootstraps 
        (kmeans euclideanNaNSquared (randomCentroids rnd) silhouetteData) 
        silhouetteData  // input data
        15              // maximal number of allowed k

let rawDataChart =
    silhouetteData 
    |> Array.map (fun x -> x.[0],x.[1])
    |> Chart.Point

let silhouetteIndicesChart =
    Chart.Line (sI |> Array.map (fun x -> x.ClusterNumber,x.SilhouetteIndex))
    |> Chart.withYErrorStyle (sI |> Array.map (fun x -> x.SilhouetteIndexStDev))

let combinedSilhouette =

    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)

    [
    rawDataChart |> Chart.withX_Axis (axis "") |> Chart.withY_Axis (axis "") |> Chart.withTraceName "raw data"
    silhouetteIndicesChart |> Chart.withX_Axis (axis "k") |> Chart.withY_Axis (axis "silhouette index") |> Chart.withTraceName "silhouette"
    ]
    |> Chart.Stack (2,0.1)

GapStatistics

Reference: 'Estimating the number of clusters in a data set via the gap statistic'; J. R. Statist. Soc. B (2001); Tibshirani, Walther, and Hastie

Gap statistics allows to determine the optimal cluster number by comparing the cluster dispersion (intra-cluster variation) of a reference dataset to the original data cluster dispersion. For each k both dispersions are calculated, while for the reference dataset multiple iterations are performed for each k. The difference of the log(dispersionOriginal) and the log(dispersionReference) is called 'gap'. The maximal gap points to the optimal cluster number.

Two ways to generate a reference data set are implemented.

  • a uniform coverage within the range of the original data set
  • a PCA based point coverage, that considers the density/shape of the original data
let gapStatisticsData = 
    System.IO.File.ReadAllLines(__SOURCE_DIRECTORY__ + "/data/gapStatisticsData.txt")
    |> Array.map (fun x ->
        let tmp = x.Split '\t'
        tmp |> Array.map float)

let gapDataChart = 
    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)
    
    [
    gapStatisticsData|> Array.map (fun x -> x.[0],x.[1]) |> Chart.Point |> Chart.withTraceName "original" |> Chart.withX_Axis (axisRange "" (-4.,10.)) |> Chart.withY_Axis (axisRange "" (-2.5,9.))
    (GapStatistics.PointGenerators.generateUniformPoints rnd gapStatisticsData) |> Array.map (fun x -> x.[0],x.[1]) |> Chart.Point |> Chart.withTraceName "uniform" |> Chart.withX_Axis (axisRange "" (-4.,10.)) |> Chart.withY_Axis (axisRange "" (-2.5,9.))
    (GapStatistics.PointGenerators.generateUniformPointsPCA rnd gapStatisticsData) |> Array.map (fun x -> x.[0],x.[1]) |> Chart.Point |> Chart.withTraceName "uniform PCA" |> Chart.withX_Axis (axisRange "" (-4.,10.)) |> Chart.withY_Axis (axisRange "" (-2.5,9.))
    ]
    |> Chart.Stack 3
    |> Chart.withSize(800.,400.)
    

The log(dispersionReference) should decrease with rising k, but - if clusters are present in the data - should be greater than the log(dispersionOriginal).

open GapStatistics

//create gap statistics
let gaps =
    GapStatistics.calculate
        (PointGenerators.generateUniformPointsPCA rnd)      //uniform point distribution
        100// no gain above 500                                //number of bootstraps samples 
        ClusterDispersionMetric.logDispersionKMeansInitRandom //dispersion metric of clustering algorithm
        10                                                     //maximal number of allowed clusters
        gapStatisticsData                                      //float [] [] data of coordinates

//number of clusters        
let k        = gaps |> Array.map (fun x -> x.ClusterIndex)
//log(dispersion) of the original data (with rising k)
let disp     = gaps |> Array.map (fun x -> x.Dispersion)
//log(dispersion) of the reference data (with rising k)
let dispRef = gaps |> Array.map (fun x -> x.ReferenceDispersion)
//log(dispersionRef) - log(dispersionOriginal)
let gap      = gaps |> Array.map (fun x -> x.Gaps)
//standard deviation of reference data set dispersion
let std      = gaps |> Array.map (fun x -> x.RefDispersionStDev)

let gapStatisticsChart =

    let axis title= Axis.LinearAxis.init(Title=title,Mirror=StyleParam.Mirror.All,Ticks=StyleParam.TickOptions.Inside,Showline=true,Showgrid=true)
    let axisRange title range= Axis.LinearAxis.init(Title=title,Range=StyleParam.Range.MinMax(range),Mirror=StyleParam.Mirror.All,Showgrid=false,Ticks=StyleParam.TickOptions.Inside,Showline=true)
    
    let dispersions =
        [
        Chart.Line (k,disp)    |> Chart.withTraceName "disp"
        Chart.Line (k,dispRef)|> Chart.withTraceName "dispRef" |> Chart.withYErrorStyle(std)
        ]
        |> Chart.Combine 
        |> Chart.withX_Axis (axisRange "" (0.,11.)) 
        |> Chart.withY_Axis (axis "log(disp)")
    let gaps = 
        Chart.Line (k,gap)|> Chart.withTraceName "gaps"
        |> Chart.withX_Axis (axisRange "k" (0.,11.)) 
        |> Chart.withY_Axis (axis "gaps")
    [dispersions; gaps]
    |> Chart.Stack 1

The maximal gap points to the optimal cluster number with the following condition:

  • kopt = smallest k such that Gap(k)>= Gap(k+1)-sk+1
  • where sk = std * sqrt(1+1/bootstraps)
//calculate s(k) out of std(k) and the number of performed iterations for the refernce data set
let sK   = std |> Array.map (fun sd -> sd * sqrt(1. + 1./500.)) //bootstraps = 500 

let gapChart =

    Chart.Line (k,gap)
    |> Chart.withYErrorStyle(sK)
    |> Chart.withX_Axis (axisRange "k" (0.,11.)) 
    |> Chart.withY_Axis (axisRange "gap" (-0.5,2.)) 
    
//choose kOpt = smallest k such that Gap(k)>= Gap(k+1)-sk+1, where sk = sdk * sqrt(1+1/bootstraps)
let kOpt = 
    Array.init (gap.Length - 2) (fun i -> gap.[i] >= gap.[i+1] - sK.[i+1])
    |> Array.findIndex id
    |> fun x -> sprintf "The optimal cluster number is: %i" (x + 1)
    
"The optimal cluster number is: 2"
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
namespace FSharp.Stats
val fromFileWithSep : separator:char -> filePath:string -> seq<string []>
val separator : char
Multiple items
val char : value:'T -> char (requires member op_Explicit)

--------------------
type char = System.Char
val filePath : string
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
val sr : System.IO.StreamReader
namespace System
namespace System.IO
type File =
  static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
  static member AppendAllLinesAsync : path:string * contents:IEnumerable<string> * ?cancellationToken:CancellationToken -> Task + 1 overload
  static member AppendAllText : path:string * contents:string -> unit + 1 overload
  static member AppendAllTextAsync : path:string * contents:string * ?cancellationToken:CancellationToken -> Task + 1 overload
  static member AppendText : path:string -> StreamWriter
  static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
  static member Create : path:string -> FileStream + 2 overloads
  static member CreateText : path:string -> StreamWriter
  static member Decrypt : path:string -> unit
  static member Delete : path:string -> unit
  ...
System.IO.File.OpenText(path: string) : System.IO.StreamReader
val not : value:bool -> bool
property System.IO.StreamReader.EndOfStream: bool with get
val line : string
System.IO.StreamReader.ReadLine() : string
val words : string []
System.String.Split([<System.ParamArray>] separator: char []) : string []
System.String.Split(separator: string [], options: System.StringSplitOptions) : string []
System.String.Split(separator: string,?options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], count: int) : string []
System.String.Split(separator: char,?options: System.StringSplitOptions) : string []
System.String.Split(separator: string [], count: int, options: System.StringSplitOptions) : string []
System.String.Split(separator: string, count: int,?options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], count: int, options: System.StringSplitOptions) : string []
System.String.Split(separator: char, count: int,?options: System.StringSplitOptions) : string []
val lables : string []
val data : float [] []
Multiple items
module Seq

from FSharp.Stats

--------------------
module Seq

from Microsoft.FSharp.Collections
val skip : count:int -> source:seq<'T> -> seq<'T>
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>
val arr : string []
Multiple items
val float : value:'T -> float (requires member op_Explicit)

--------------------
type float = System.Double

--------------------
type float<'Measure> = float
val toArray : source:seq<'T> -> 'T []
Multiple items
module Array

from FSharp.Stats

--------------------
module Array

from Microsoft.FSharp.Collections
val shuffleFisherYates : arr:'b [] -> 'b []
val mapi : mapping:(int -> 'T -> 'U) -> array:'T [] -> 'U []
val i : int
val lable : string
val data : float []
val sprintf : format:Printf.StringFormat<'T> -> 'T
val unzip : array:('T1 * 'T2) [] -> 'T1 [] * 'T2 []
namespace Plotly
namespace Plotly.NET
val colnames : string list
val colorscaleValue : StyleParam.Colorscale
module StyleParam

from Plotly.NET
type Colorscale =
  | Custom of seq<float * string>
  | RdBu
  | Earth
  | Blackbody
  | YIOrRd
  | YIGnBu
  | Bluered
  | Portland
  | Electric
  | Jet
  ...
    static member convert : (Colorscale -> obj)
union case StyleParam.Colorscale.Electric: StyleParam.Colorscale
val dataChart : GenericChart.GenericChart
type Chart =
  static member Area : xy:seq<#IConvertible * #IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:'a2 -> GenericChart
  static member Area : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:'a2 -> GenericChart
  static member Bar : keysvalues:seq<#IConvertible * #IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart
  static member Bar : keys:seq<#IConvertible> * values:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:'a2 * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart
  static member BoxPlot : xy:seq<'a0 * 'a1> * ?Name:string * ?Showlegend:bool * ?Color:string * ?Fillcolor:'a2 * ?Opacity:float * ?Whiskerwidth:'a3 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a4 * ?Pointpos:'a5 * ?Orientation:Orientation * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'a6 * ?Offsetgroup:'a7 * ?Notched:bool * ?NotchWidth:float * ?QuartileMethod:QuartileMethod -> GenericChart
  static member BoxPlot : ?x:'a0 * ?y:'a1 * ?Name:string * ?Showlegend:bool * ?Color:string * ?Fillcolor:'a2 * ?Opacity:float * ?Whiskerwidth:'a3 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a4 * ?Pointpos:'a5 * ?Orientation:Orientation * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'a6 * ?Offsetgroup:'a7 * ?Notched:bool * ?NotchWidth:float * ?QuartileMethod:QuartileMethod -> GenericChart
  static member Bubble : xysizes:seq<#IConvertible * #IConvertible * #IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:Orientation * ?GroupNorm:GroupNorm * ?UseWebGL:bool -> GenericChart
  static member Bubble : x:seq<#IConvertible> * y:seq<#IConvertible> * sizes:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:Orientation * ?GroupNorm:GroupNorm * ?UseWebGL:bool -> GenericChart
  static member Candlestick : stockTimeSeries:seq<DateTime * StockData> * ?Increasing:Line * ?Decreasing:Line * ?WhiskerWidth:float * ?Line:Line * ?XCalendar:Calendar -> GenericChart
  static member Candlestick : open:seq<#IConvertible> * high:seq<#IConvertible> * low:seq<#IConvertible> * close:seq<#IConvertible> * x:seq<#IConvertible> * ?Increasing:Line * ?Decreasing:Line * ?WhiskerWidth:float * ?Line:Line * ?XCalendar:Calendar -> GenericChart
  ...
static member Chart.Heatmap : data:seq<#seq<'b>> * ?ColNames:seq<#System.IConvertible> * ?RowNames:seq<#System.IConvertible> * ?Name:string * ?Showlegend:bool * ?Opacity:float * ?Colorscale:StyleParam.Colorscale * ?Showscale:'e * ?Xgap:'f * ?Ygap:'g * ?zSmooth:StyleParam.SmoothAlg * ?Colorbar:'h -> GenericChart.GenericChart (requires 'b :> System.IConvertible)
Multiple items
module Seq

from Plotly.NET

--------------------
module Seq

from FSharp.Stats

--------------------
module Seq

from Microsoft.FSharp.Collections
val mapi : mapping:(int -> 'T -> 'U) -> source:seq<'T> -> seq<'U>
val s : string
static member Chart.withMarginSize : ?Left:'a * ?Right:'b * ?Top:'c * ?Bottom:'d * ?Pad:'e * ?Autoexpand:'f -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withTitle : title:string * ?Titlefont:Font -> (GenericChart.GenericChart -> GenericChart.GenericChart)
module GenericChart

from Plotly.NET
val toChartHTML : gChart:GenericChart.GenericChart -> string
namespace FSharp.Stats.ML
namespace FSharp.Stats.ML.Unsupervised
module HierarchicalClustering

from FSharp.Stats.ML.Unsupervised
val rnd : System.Random
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit + 1 overload
  member NextDouble : unit -> float

--------------------
System.Random() : System.Random
System.Random(Seed: int) : System.Random
val randomInitFactory : IterativeClustering.CentroidsFactory<float []>
module IterativeClustering

from FSharp.Stats.ML.Unsupervised
type CentroidsFactory<'a> = 'a array -> int -> 'a array
val randomCentroids : rng:System.Random -> sample:'a array -> k:int -> 'a []
val kmeansResult : IterativeClustering.KClusteringResult<float []>
val kmeans : dist:DistanceMetrics.Distance<float []> -> factory:IterativeClustering.CentroidsFactory<float []> -> dataset:float [] array -> k:int -> IterativeClustering.KClusteringResult<float []>
module DistanceMetrics

from FSharp.Stats.ML
val euclidean : s1:seq<'a> -> s2:seq<'a> -> 'c (requires member ( - ) and member get_Zero and member ( + ) and member Sqrt and member ( * ))
val clusteredIrisData : GenericChart.GenericChart
val zip : array1:'T1 [] -> array2:'T2 [] -> ('T1 * 'T2) []
val sortBy : projection:('T -> 'Key) -> array:'T [] -> 'T [] (requires comparison)
val l : string
val dataPoint : float []
val fst : tuple:('T1 * 'T2) -> 'T1
IterativeClustering.KClusteringResult.Classifier: float [] -> int * float []
val labels : string []
val d : float [] []
val getBestkMeansClustering : data:float [] array -> k:int -> bootstraps:int -> IterativeClustering.KClusteringResult<float []>
val data : float [] array
val k : int
val bootstraps : int
Multiple items
module List

from FSharp.Stats

--------------------
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
    interface IReadOnlyList<'T>
    interface IReadOnlyCollection<'T>
    interface IEnumerable
    interface IEnumerable<'T>
    member GetReverseIndex : rank:int * offset:int -> int
    member GetSlice : startIndex:int option * endIndex:int option -> 'T list
    member Head : 'T
    member IsEmpty : bool
    member Item : index:int -> 'T with get
    member Length : int
    ...
val mapi : mapping:(int -> 'T -> 'U) -> list:'T list -> 'U list
val x : int
val minBy : projection:('T -> 'U) -> list:'T list -> 'T (requires comparison)
val clusteringResult : IterativeClustering.KClusteringResult<float []>
val DispersionOfClusterResult : kmeansResult:IterativeClustering.KClusteringResult<'a> -> float
val t : DbScan.DbscanResult<float array>
module DbScan

from FSharp.Stats.ML.Unsupervised
val compute : dfu:('a array -> 'a array -> float) -> minPts:int -> eps:float -> input:seq<#seq<'a>> -> DbScan.DbscanResult<'a array>
module Array

from FSharp.Stats.ML.DistanceMetrics
val euclideanNaN : a1:float array -> a2:float array -> float
val petLpetW : float [] []
val map : mapping:('T -> 'U) -> array:'T [] -> 'U []
val x : float []
val petWpetLsepL : float [] []
val axis : title:string -> Axis.LinearAxis
val title : string
module Axis

from Plotly.NET
Multiple items
type LinearAxis =
  inherit DynamicObj
  new : unit -> LinearAxis
  static member init : ?AxisType:AxisType * ?Title:string * ?Titlefont:Font * ?Autorange:AutoRange * ?Rangemode:RangeMode * ?Range:Range * ?RangeSlider:RangeSlider * ?Fixedrange:'a * ?Tickmode:TickMode * ?nTicks:'b * ?Tick0:'c * ?dTick:'d * ?Tickvals:'e * ?Ticktext:'f * ?Ticks:TickOptions * ?Mirror:Mirror * ?Ticklen:'g * ?Tickwidth:'h * ?Tickcolor:'i * ?Showticklabels:'j * ?Tickfont:Font * ?Tickangle:'k * ?Tickprefix:'l * ?Showtickprefix:ShowTickOption * ?Ticksuffix:'m * ?Showticksuffix:ShowTickOption * ?Showexponent:ShowExponent * ?Exponentformat:ExponentFormat * ?Tickformat:'n * ?Hoverformat:'o * ?Showline:bool * ?Linecolor:'p * ?Linewidth:'q * ?Showgrid:bool * ?Gridcolor:'r * ?Gridwidth:'s * ?Zeroline:bool * ?Zerolinecolor:'t * ?Zerolinewidth:'a1 * ?Anchor:AxisAnchorId * ?Side:Side * ?Overlaying:AxisAnchorId * ?Domain:Range * ?Position:float * ?IsSubplotObj:'a2 * ?Tickvalssrc:'a3 * ?Ticktextsrc:'a4 * ?Showspikes:'a5 * ?Spikesides:'a6 * ?Spikethickness:'a7 * ?Spikecolor:'a8 * ?Showbackground:'a9 * ?Backgroundcolor:'a10 * ?Showaxeslabels:'a11 -> LinearAxis
  static member style : ?AxisType:AxisType * ?Title:string * ?Titlefont:Font * ?Autorange:AutoRange * ?Rangemode:RangeMode * ?Range:Range * ?RangeSlider:RangeSlider * ?Fixedrange:'a * ?Tickmode:TickMode * ?nTicks:'b * ?Tick0:'c * ?dTick:'d * ?Tickvals:'e * ?Ticktext:'f * ?Ticks:TickOptions * ?Mirror:Mirror * ?Ticklen:'g * ?Tickwidth:'h * ?Tickcolor:'i * ?Showticklabels:'j * ?Tickfont:Font * ?Tickangle:'k * ?Tickprefix:'l * ?Showtickprefix:ShowTickOption * ?Ticksuffix:'m * ?Showticksuffix:ShowTickOption * ?Showexponent:ShowExponent * ?Exponentformat:ExponentFormat * ?Tickformat:'n * ?Hoverformat:'o * ?Showline:bool * ?Linecolor:'p * ?Linewidth:'q * ?Showgrid:bool * ?Gridcolor:'r * ?Gridwidth:'s * ?Zeroline:bool * ?Zerolinecolor:'t * ?Zerolinewidth:'a1 * ?Anchor:AxisAnchorId * ?Side:Side * ?Overlaying:AxisAnchorId * ?Domain:Range * ?Position:float * ?IsSubplotObj:'a2 * ?Tickvalssrc:'a3 * ?Ticktextsrc:'a4 * ?Showspikes:'a5 * ?Spikesides:'a6 * ?Spikethickness:'a7 * ?Spikecolor:'a8 * ?Showbackground:'a9 * ?Backgroundcolor:'a10 * ?Showaxeslabels:'a11 -> (LinearAxis -> LinearAxis)

--------------------
new : unit -> Axis.LinearAxis
static member Axis.LinearAxis.init : ?AxisType:StyleParam.AxisType * ?Title:string * ?Titlefont:Font * ?Autorange:StyleParam.AutoRange * ?Rangemode:StyleParam.RangeMode * ?Range:StyleParam.Range * ?RangeSlider:RangeSlider * ?Fixedrange:'a * ?Tickmode:StyleParam.TickMode * ?nTicks:'b * ?Tick0:'c * ?dTick:'d * ?Tickvals:'e * ?Ticktext:'f * ?Ticks:StyleParam.TickOptions * ?Mirror:StyleParam.Mirror * ?Ticklen:'g * ?Tickwidth:'h * ?Tickcolor:'i * ?Showticklabels:'j * ?Tickfont:Font * ?Tickangle:'k * ?Tickprefix:'l * ?Showtickprefix:StyleParam.ShowTickOption * ?Ticksuffix:'m * ?Showticksuffix:StyleParam.ShowTickOption * ?Showexponent:StyleParam.ShowExponent * ?Exponentformat:StyleParam.ExponentFormat * ?Tickformat:'n * ?Hoverformat:'o * ?Showline:bool * ?Linecolor:'p * ?Linewidth:'q * ?Showgrid:bool * ?Gridcolor:'r * ?Gridwidth:'s * ?Zeroline:bool * ?Zerolinecolor:'t * ?Zerolinewidth:'a1 * ?Anchor:StyleParam.AxisAnchorId * ?Side:StyleParam.Side * ?Overlaying:StyleParam.AxisAnchorId * ?Domain:StyleParam.Range * ?Position:float * ?IsSubplotObj:'a2 * ?Tickvalssrc:'a3 * ?Ticktextsrc:'a4 * ?Showspikes:'a5 * ?Spikesides:'a6 * ?Spikethickness:'a7 * ?Spikecolor:'a8 * ?Showbackground:'a9 * ?Backgroundcolor:'a10 * ?Showaxeslabels:'a11 -> Axis.LinearAxis
type Mirror =
  | True
  | Ticks
  | False
  | All
  | AllTicks
    static member convert : (Mirror -> obj)
    static member toString : (Mirror -> string)
union case StyleParam.Mirror.All: StyleParam.Mirror
type TickOptions =
  | Outside
  | Inside
  | Empty
    static member convert : (TickOptions -> obj)
    static member toString : (TickOptions -> string)
union case StyleParam.TickOptions.Inside: StyleParam.TickOptions
val axisRange : title:string -> float * float -> Axis.LinearAxis
val range : float * float
type Range =
  | MinMax of float * float
  | Values of float array
    static member convert : (Range -> obj)
union case StyleParam.Range.MinMax: float * float -> StyleParam.Range
val dbscanPlot : GenericChart.GenericChart
val axis : (string -> Axis.LinearAxis)
val axisRange : (string -> float * float -> Axis.LinearAxis)
val head : source:seq<'T> -> 'T
val length : source:seq<'T> -> int
val failwithf : format:Printf.StringFormat<'T,'Result> -> 'T
val result : DbScan.DbscanResult<float array>
val euclidean : a1:'a array -> a2:'a array -> float (requires member get_Zero and member ( - ) and member ( + ) and member op_Explicit and member ( * ))
val chartCluster : GenericChart.GenericChart
DbScan.DbscanResult.Clusterlist: seq<seq<float array>>
val l : seq<float array>
val x : float array
val distinct : source:seq<'T> -> seq<'T> (requires equality)
static member Chart.Point : xy:seq<#System.IConvertible * #System.IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:StyleParam.Orientation * ?GroupNorm:StyleParam.GroupNorm * ?UseWebGL:bool -> GenericChart.GenericChart
static member Chart.Point : x:seq<#System.IConvertible> * y:seq<#System.IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:StyleParam.Orientation * ?GroupNorm:StyleParam.GroupNorm * ?UseWebGL:bool -> GenericChart.GenericChart
static member Chart.withTraceName : ?Name:string * ?Showlegend:bool * ?Legendgroup:string * ?Visible:StyleParam.Visible -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.Combine : gCharts:seq<GenericChart.GenericChart> -> GenericChart.GenericChart
val chartNoise : GenericChart.GenericChart
DbScan.DbscanResult.Noisepoints: seq<float array>
val chartname : string
val noiseCount : int
val clusterCount : int
val clPtsCount : int
val sumBy : projection:('T -> 'U) -> source:seq<'T> -> 'U (requires member ( + ) and member get_Zero)
static member Chart.withX_Axis : xAxis:Axis.LinearAxis * ?Id:int -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withY_Axis : yAxis:Axis.LinearAxis * ?Id:int -> (GenericChart.GenericChart -> GenericChart.GenericChart)
val create3dChart : dfu:('a array -> 'a array -> float) -> minPts:int -> eps:float -> input:seq<#seq<'a>> -> GenericChart.GenericChart (requires equality and 'a :> System.IConvertible)
val dfu : ('a array -> 'a array -> float) (requires equality and 'a :> System.IConvertible)
type 'T array = 'T []
val minPts : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
val eps : float
val input : seq<#seq<'a0>> (requires equality and 'a0 :> System.IConvertible)
val result : DbScan.DbscanResult<'a array> (requires equality and 'a :> System.IConvertible)
DbScan.DbscanResult.Clusterlist: seq<seq<'a array>>
val l : seq<'a array> (requires equality and 'a :> System.IConvertible)
val x : 'a array (requires equality and 'a :> System.IConvertible)
val x : seq<'a * 'a * 'a> (requires equality and 'a :> System.IConvertible)
static member Chart.Scatter3d : xyz:seq<#System.IConvertible * #System.IConvertible * #System.IConvertible> * mode:StyleParam.Mode * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Dash:StyleParam.DrawingStyle * ?Width:'e -> GenericChart.GenericChart
static member Chart.Scatter3d : x:seq<#System.IConvertible> * y:seq<#System.IConvertible> * z:seq<#System.IConvertible> * mode:StyleParam.Mode * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Dash:StyleParam.DrawingStyle * ?Width:'a3 -> GenericChart.GenericChart
type Mode =
  | None
  | Lines
  | Lines_Markers
  | Lines_Text
  | Lines_Markers_Text
  | Markers
  | Markers_Text
  | Text
    static member convert : (Mode -> obj)
    static member toString : (Mode -> string)
union case StyleParam.Mode.Markers: StyleParam.Mode
DbScan.DbscanResult.Noisepoints: seq<'a array>
static member Chart.withZ_Axis : zAxis:Axis.LinearAxis -> (GenericChart.GenericChart -> GenericChart.GenericChart)
val clusteredChart3D : GenericChart.GenericChart
val euclideanNaNSquared : a1:float array -> a2:float array -> float
val clusterResultH : Cluster<float []>
val generate : distance:DistanceMetrics.Distance<'T> -> linker:Linker.LancWilliamsLinker -> data:seq<'T> -> Cluster<'T>
val euclideanNaNSquared : s1:seq<float> -> s2:seq<float> -> float
module Linker

from FSharp.Stats.ML.Unsupervised.HierarchicalClustering
val wardLwLinker : int * int * int -> dAB:float -> dAC:float -> dBC:float -> float
val threeClustersH : Cluster<float []> list list
val cutHClust : desiredNumber:int -> clusterTree:Cluster<'T> -> Cluster<'T> list list
val inspectThreeClusters : string * string list list
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
val cluster : Cluster<float []> list
val leaf : Cluster<float []>
val getClusterId : c:Cluster<'T> -> int
val clusteredLabels : string list list
property List.Length: int with get
val hLeaves : Cluster<float []> list
val flattenHClust : clusterTree:Cluster<'T> -> Cluster<'T> list
val dataSortedByClustering : seq<string * float []>
val choose : chooser:('T -> 'U option) -> source:seq<'T> -> seq<'U>
val c : Cluster<float []>
val values : float [] option
val tryGetLeafValue : c:Cluster<'T> -> 'T option
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
val hierClusteredDataHeatmap : GenericChart.GenericChart
val hlable : seq<string>
val hdata : seq<float []>
val unzip : input:seq<'a * 'b> -> seq<'a> * seq<'b>
val ruleOfThumb : float
module ClusterNumber

from FSharp.Stats.ML.Unsupervised
val kRuleOfThumb : observations:seq<'a> -> float
val kElbow : int
val iterations : int
val dispersionOfK : (int * float * float) []
Multiple items
module Array

from FSharp.Stats.ML.DistanceMetrics

--------------------
module Array

from FSharp.Stats

--------------------
module Array

from Microsoft.FSharp.Collections
val dispersion : float
val std : float
val kmeans : dist:Distance<float []> -> factory:CentroidsFactory<float []> -> dataset:float [] array -> k:int -> KClusteringResult<float []>
val DispersionOfClusterResult : kmeansResult:KClusteringResult<'a> -> float
val dispersions : float []
val mean : items:seq<'T> -> 'U (requires member ( + ) and member get_Zero and member DivideByInt and member ( / ))
val stDev : items:seq<'T> -> 'U (requires member ( - ) and member get_Zero and member DivideByInt and member ( + ) and member ( * ) and member ( + ) and member ( / ) and member Sqrt)
val elbowChart : GenericChart.GenericChart
static member Chart.Line : xy:seq<#System.IConvertible * #System.IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Dash:'c * ?Width:'d * ?StackGroup:string * ?Orientation:StyleParam.Orientation * ?GroupNorm:StyleParam.GroupNorm * ?UseWebGL:bool -> GenericChart.GenericChart
static member Chart.Line : x:seq<#System.IConvertible> * y:seq<#System.IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:StyleParam.Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<string> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Dash:'c * ?Width:'d * ?StackGroup:string * ?Orientation:StyleParam.Orientation * ?GroupNorm:StyleParam.GroupNorm * ?UseWebGL:bool -> GenericChart.GenericChart
static member Chart.withYErrorStyle : ?Array:'a * ?Arrayminus:'b * ?Symmetric:'c * ?Color:'d * ?Thickness:'e * ?Width:'f -> (GenericChart.GenericChart -> GenericChart.GenericChart)
val aicBootstraps : int
val aicK : int []
val aicMeans : float []
val aicStd : float []
val aic : (int * float) [] []
val b : int
val calcAIC : bootstraps:int -> iClustering:(int -> KClusteringResult<float []>) -> maxK:int -> (int * float) []
val iteration : (int * float) []
val snd : tuple:('T1 * 'T2) -> 'T2
module JaggedArray

from FSharp.Stats
val transpose : arr:'T [] [] -> 'T [] []
val aics : float []
val unzip3 : array:('T1 * 'T2 * 'T3) [] -> 'T1 [] * 'T2 [] * 'T3 []
val aicChart : GenericChart.GenericChart
val silhouetteData : float [] []
System.IO.File.ReadAllLines(path: string) : string []
System.IO.File.ReadAllLines(path: string, encoding: System.Text.Encoding) : string []
val x : string
val tmp : string []
val sI : ClusterNumber.SilhouetteResult []
val silhouetteIndexKMeans : bootstraps:int -> iClustering:(int -> KClusteringResult<float []>) -> data:float [] [] -> maxK:int -> ClusterNumber.SilhouetteResult []
val rawDataChart : GenericChart.GenericChart
val silhouetteIndicesChart : GenericChart.GenericChart
val x : ClusterNumber.SilhouetteResult
ClusterNumber.SilhouetteResult.ClusterNumber: int
ClusterNumber.SilhouetteResult.SilhouetteIndex: float
ClusterNumber.SilhouetteResult.SilhouetteIndexStDev: float
val combinedSilhouette : GenericChart.GenericChart
val gapStatisticsData : float [] []
val gapDataChart : GenericChart.GenericChart
module GapStatistics

from FSharp.Stats.ML.Unsupervised
module PointGenerators

from FSharp.Stats.ML.Unsupervised.GapStatistics
val generateUniformPoints : rnd:System.Random -> data:float [] array -> float [] []
val generateUniformPointsPCA : rnd:System.Random -> data:float [] array -> float [] []
static member Chart.withSize : width:float * height:float -> (GenericChart.GenericChart -> GenericChart.GenericChart)
val gaps : GapStatisticResult []
val calculate : rndPointGenerator:GenericPointGenerator<'a> -> bootstraps:int -> calcDispersion:GenericClusterDispersion<'a> -> maxK:int -> data:'a array -> GapStatisticResult []
module ClusterDispersionMetric

from FSharp.Stats.ML.Unsupervised.GapStatistics
val logDispersionKMeansInitRandom : (float [] array -> int -> float)
val k : int []
val x : GapStatisticResult
GapStatisticResult.ClusterIndex: int
val disp : float []
GapStatisticResult.Dispersion: float
val dispRef : float []
GapStatisticResult.ReferenceDispersion: float
val gap : float []
GapStatisticResult.Gaps: float
val std : float []
GapStatisticResult.RefDispersionStDev: float
val gapStatisticsChart : GenericChart.GenericChart
val dispersions : GenericChart.GenericChart
val gaps : GenericChart.GenericChart
val sK : float []
val sd : float
val sqrt : value:'T -> 'U (requires member Sqrt)
val gapChart : GenericChart.GenericChart
val kOpt : string
val init : count:int -> initializer:(int -> 'T) -> 'T []
property System.Array.Length: int with get
val findIndex : predicate:('T -> bool) -> array:'T [] -> int
val id : x:'T -> 'T