CategoriesCount: Integer;
The CategoriesCount property determines the number of clusters the source data is divided into.
By default, the data is divided into two clusters.
Executing the example requires that the repository contains:
A table with the DM_TABLE identifier containing data for analysis
A regular report with the DM_REPORT_RES identifier, to which analysis results will be loaded.
Add links to the Metabase, Ms, Report, Stat, Tab system assemblies.
Sub UserKModes;
Var
mb: IMetabase;
ReportDS: IDmReportDataSource;
TableDS: IDmTableDataSource;
Method: IDmMethod;
Report: IPrxReport;
Shs: IPrxSheets;
Sheet: ITabSheet;
DM: IDmKmodesClusterAnalysis;
i, j: Integer;
Attrs: Array Of Integer;
Reports: IDmReports;
DmReport: IDmReport;
Begin
mb := MetabaseClass.Active;
// Create calculation method
Method := (New DataMiningMethod.Create) As IDmMethod;
// Specify method type
Method.Kind := DmMethodKind.KmodesClusterAnalysis;
// Create table data source
TableDS := (New TableDataSource.Create) As IDmTableDataSource;
// Determine source table
TableDS.Table := mb.ItemByID("DM_TABLE").Bind;
// Set input data source
Method.InputDataSource := TableDS;
// Create a data source that is a regular report
ReportDS := (New ReportDataSource.Create) As IDmReportDataSource;
// Set data consumer
Method.OutputDataSource := ReportDS;
// Set up calculation method parameters
DM := Method.Details As IDmKmodesClusterAnalysis;
// Set forecasting data
Attrs := New Integer[6];
For i := 0 To 5 Do
Attrs[i] := i;
End For;
DM.Attributes := Attrs;
// Set number of clusters
DM.CategoriesCount := 3;
// Perform analysis and output results
Reports := Method.Execute;
DmReport := reports.FindByType(DmReportType.KmodesClusterAnalysis);
ReportDS := DmReport.Generate;
ReportDS.TabSheet.View.Selection.SelectAll;
ReportDS.TabSheet.View.Selection.Copy;
// Get regular report, to which results will be loaded
Report := mb.ItemByID("DM_REPORT_RES").Edit As IPrxReport;
Shs := Report.Sheets;
Shs.Clear;
Sheet := (Shs.Add("", PrxSheetType.Table) As IPrxTable).TabSheet;
Sheet.Table.Paste;
Sheet.Columns(0, 1).AdjustWidth;
Sheet.Rows(0, 1).AdjustHeight;
Report.Sheets.Item(0).Name := ReportDS.Caption;
// Save loaded data
(Report As IMetabaseObject).Save;
// Display analyzed data to the console window
For i := 0 To TableDS.RecordCount - 1 Do
For j := 0 To TableDS.FieldCount - 1 Do
Debug.Write(TableDS.Item(i, j) + "; ");
End For;
Debug.WriteLine("");
End For;
End Sub UserKModes;
After executing the example data from the DM_TABLE table will be clustered using the K-modes method. Analysis results will be loaded to the DM_REPORT_RES report. Analyzed data will be displayed in the console window.
See also: