Last active
April 15, 2016 08:26
-
-
Save sakapon/705b50445ba3c6c9869802fd78f7abbe to your computer and use it in GitHub Desktop.
Usage of Clustering of Bellona.Analysis 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using Bellona.Analysis.Clustering; | |
namespace ClusteringConsole | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// 色のデータを用意します (実際にはもっと多く)。 | |
var colors = new[] { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet }; | |
// ClusteringModel.CreateAuto メソッドでモデルを初期化します。 | |
// ラムダ式で、特徴量を表すベクトルを指定します。 | |
// Train メソッドで学習させます。 | |
var model = ClusteringModel.CreateAuto<Color>(c => new double[] { c.R, c.G, c.B }) | |
.Train(colors); | |
// 学習結果のモデルから、クラスターにアクセスします。 | |
var cluster0 = model.Clusters[0]; | |
// 各クラスターには 0 から始まる ID が付けられます。 | |
Console.WriteLine(cluster0.Id); | |
// クラスターに含まれる要素を列挙します。 | |
foreach (var record in cluster0.Records) | |
Console.WriteLine(record.Element.Name); | |
// 別の色をクラスターに割り当てます (この場合、学習はしません)。 | |
var assignedCluster = model.Assign(Color.Gold); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment