harthur / clustering Goto Github PK
View Code? Open in Web Editor NEWK-means and hierarchical clustering
Home Page: http://harthur.github.com/clustering/demos/colors
License: MIT License
K-means and hierarchical clustering
Home Page: http://harthur.github.com/clustering/demos/colors
License: MIT License
As stated, why isn't it passed into the result? This is required for displaying the results in a dendrogram.
I'd love to give more details . movement is always true... (inside the loop it ofcourse false, but then changes to true)...
not sure how to fix it, really problematic.
help is needed.
It might be because of a local minima point. I've added an iterations limit to the while, so while(movement && (iterations < max_iteratoins)){ ... }
this isn't a good solution obviously, but im not familiar with the algorithm
http://blog.endava.com/k-means-clustering-algorithm
" However, in this form, there is a risk to get stuck in a local minima. By local minima I mean the local minima of the cost function:"
function kmeans(points, k, distance, snapshotPeriod, snapshotCb) {}
since kmeans.classify
is provided, can you add kmeans.distance() api for deep use.
Thanks!
var colors = [
[97],
[1],
[53],
[79],
[3],
[351],
[16]
];
var clusters = clusterfck.kmeans(colors, 3);
Result A: [1, 3, 16], [53, 79, 97], [351]
Result B: [1, 3, 16, 53], [79, 97], [351]
I have two features I'd like to add to hcluster, but I thought I'd run them by you before I ran off and built them. They are:
What do you think?
For example the first item is an identification item ( userid ) so that I can know who went in wich cluster.
var colors = [
['a1',20, 20, 80],
['a2',22, 22, 90],
['a3',250, 255, 253],
['a4',0, 30, 70],
['a5',200, 0, 23],
['a6',100, 54, 100],
['a7',255, 13, 8]
];
clusterfck.kmeans(colors, 3);
If I run this it just hungs. Is there a way to ignore the first item, and just consider the rest?
Thanks
I have this code:
val fileName = """file:///home/user/data/csv/sessions_sample.csv"""
val df = spark.read.format("csv").option("header", "true").option("inferSchema", "true").load(fileName)
val input1 = df.select("id", "duration", "ip_dist", "txr1", "txr2", "txr3", "txr4").na.fill(3.0)
val input2 = input1.map(r => (r.getInt(0), Vectors.dense((1 until r.size - 1).map{ i => r.getDouble(i)}.toArray[Double])))
val input3 = input2.toDF("id", "features")
input3.count()
val kmeans = new KMeans().setK(100).setSeed(1L).setFeaturesCol("features").setPredictionCol("prediction")
val model = kmeans.fit(input3)
val model = kmeans.fit(input3.select("features"))
// Make predictions
val predictions = model.transform(input3.select("features"))
val predictions = model.transform(input3)
val evaluator = new ClusteringEvaluator()
// i get error when i run this line
val silhouette = evaluator.evaluate(predictions)
Error:
> java.lang.AssertionError: assertion failed: Number of clusters must be greater than one.
> at scala.Predef$.assert(Predef.scala:170)
> at org.apache.spark.ml.evaluation.SquaredEuclideanSilhouette$.computeSilhouetteScore(ClusteringEvaluator.scala:416)
> at org.apache.spark.ml.evaluation.ClusteringEvaluator.evaluate(ClusteringEvaluator.scala:96)
> ... 49 elided
Of course i tried changing k. It does not respond. On top of that, I have clusters with infinite cluster centers. For absolutely no value of k my clusters are stable => silhouette gives weird error?
`model.clusterCenters.foreach(println)`
> [3217567.1300936914,145.06533614203505,Infinity,Infinity,Infinity]
please advise.
It'd be a nice improvement if there was a way to access the distance between the left and right subtrees of the resulting hierarchical clustering tree without having to re-run the distance function. Perhaps this information could be recorded in the canonical object. This would make it easier (and cheaper) to generate an arbitrary number of clusters from the tree instead of just decending the tree to some depth to generate 2^depth clusters.
It would be even better if there was a function bound to the result of hcluster that accepted some int number of clusters and output the clusters in a list.
Update http://harthur.github.io/clusterfck/. It's stating to use:
var clusters = clusterfck.hcluster(colors, clusterfck.EUCLIDEAN_DISTANCE, clusterfck.AVERAGE_LINKAGE, threshold);
Instead of:
var tree = clusterfck.hcluster(colors, "euclidean", "single");
Or even better, remove http://harthur.github.io/clusterfck/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.