RecommendationRule(Index: Integer): ISlRecommendationRule;
RecommendationRule[Index: integer]: Prognoz.Platform.Interop.Stat.ISlRecommendationRule;
Index. Rule index.
The RecommendationRule property returns the specified rule obtained as the result of method calculation.
Rule indexation is continuous starting with zero. The number of rules is returned by the ISmAssociationRules.RecommendationRulesCount property.
Add a link to the Stat system assembly.
Sub UserProc;
Var
tr, obj: Array[45] Of Integer;
AsRu: SmAssociationRules;
res, i, j, Count: integer;
s: string;
Rule: ISlRecommendationRule;
ConditionItemset, ResultItemset, FreqItemset: ISlFrequentItemset;
Itemset: Array Of Integer;
Begin
// Array containing transactions
tr[0] := 1; tr[15] := 6; tr[30] := 11;
tr[1] := 1; tr[16] := 6; tr[31] := 11;
tr[2] := 1; tr[17] := 6; tr[32] := 11;
tr[3] := 2; tr[18] := 7; tr[33] := 12;
tr[4] := 2; tr[19] := 7; tr[34] := 12;
tr[5] := 2; tr[20] := 7; tr[35] := 12;
tr[6] := 3; tr[21] := 8; tr[36] := 13;
tr[7] := 3; tr[22] := 8; tr[37] := 13;
tr[8] := 3; tr[23] := 8; tr[38] := 13;
tr[9] := 4; tr[24] := 9; tr[39] := 14;
tr[10] := 4; tr[25] := 9; tr[40] := 14;
tr[11] := 4; tr[26] := 9; tr[41] := 14;
tr[12] := 5; tr[27] := 10; tr[42] := 15;
tr[13] := 5; tr[28] := 10; tr[43] := 15;
tr[14] := 5; tr[29] := 10; tr[44] := 15;
// Array containing elements
obj[0] := 0; obj[15] := 3; obj[30] := 6;
obj[1] := 2; obj[16] := 4; obj[31] := 7;
obj[2] := 2; obj[17] := 5; obj[32] := 7;
obj[3] := 0; obj[18] := 6; obj[33] := 6;
obj[4] := 1; obj[19] := 4; obj[34] := 7;
obj[5] := 2; obj[20] := 5; obj[35] := 8;
obj[6] := 0; obj[21] := 5; obj[36] := 1;
obj[7] := 1; obj[22] := 4; obj[37] := 1;
obj[8] := 2; obj[23] := 5; obj[38] := 2;
obj[9] := 0; obj[24] := 6; obj[39] := 3;
obj[10] := 0; obj[25] := 7; obj[40] := 4;
obj[11] := 2; obj[26] := 4; obj[41] := 4;
obj[12] := 3; obj[27] := 6; obj[42] := 5;
obj[13] := 4; obj[28] := 7; obj[43] := 7;
obj[14] := 5; obj[29] := 8; obj[44] := 7;
// Create method
AsRu := New SmAssociationRules.Create;
// Arrays of transactions and elements
AsRu.Transactions := tr;
AsRu.Objects := obj;
// Minimum support (%)
AsRu.MinimumSupport := 10;
AsRu.UseSupportPercent := True;
// Minimum confidence level
AsRu.MinimumConfidence := 0.4;
// Maximum number of frequently occurred element sets
AsRu.MaximumFrequentItemsetsCount := 200000;
// Minimum number of elements in frequently occurred set
AsRu.MinimumFrequentItemsetSize := 1;
// Maximum number of elements in frequently occurred set
AsRu.MaximumFrequentItemsetSize := 3;
// Minimum significance level
AsRu.MinimumImportance := 0.1;
// Missing data treatment method
AsRu.MissingData.Method := MissingDataMethod.Casewise;
// Perform calculation and output results
res := AsRu.Execute;
If res = 0 Then
Count := AsRu.RecommendationRulesCount;
Debug.WriteLine("Number of significant rules: " + Count.ToString);
For i := 0 To Count - 1 Do
s := "";
s := s + "Condition: ";
Rule := AsRu.RecommendationRule(i);
ConditionItemset := Rule.ExplanatoryItemset;
Itemset := ConditionItemset.Itemset;
For j := 0 To Itemset.Length - 1 Do
s := s + Itemset[j].ToString + ",";
End For;
ResultItemset := Rule.ExplainedItemset;
Itemset := ResultItemset.Itemset;
s := s + " -> consequence: ";
For j := 0 To Itemset.Length - 1 Do
s := s + Itemset[j].ToString + ",";
End For;
Debug.WriteLine(s);
Debug.Indent;
Debug.WriteLine("- confidence level: " + Rule.Confidence.ToString);
Debug.WriteLine("- significance level: " + Rule.Importance.ToString);
Debug.WriteLine("- support (%): " + Rule.SupportPercent.ToString);
Debug.WriteLine("- support (number of transactions): " + Rule.SupportCount.ToString);
Debug.Unindent;
End For;
Debug.WriteLine("");
Count := AsRu.FrequentItemsetsCount;
Debug.WriteLine("Number of frequently occurred element sets: " + Count.ToString);
For i := 0 To Count - 1 Do
s := "Set: ";
FreqItemset := AsRu.FrequentItemset(i);
Itemset := FreqItemset.Itemset;
For j := 0 To Itemset.Length - 1 Do
s := s + Itemset[j].ToString + ";";
End For;
Debug.WriteLine(s);
Debug.Indent;
Debug.WriteLine("- support (%): " + FreqItemset.SupportPercent.ToString);
Debug.WriteLine("- support (number of transactions): " + FreqItemset.SupportCount.ToString);
Debug.Unindent;
End For;
End If;
End Sub UserProc;
After executing the example the specified data is analyzed by the Association Analysis analysis, the console window displays method execution results:
Number of significant rules.
Number of often met data sets.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
tr, obj: Array[45] Of Integer;
AsRu: SmAssociationRules;
res, i, j, Count: integer;
s: string;
Rule: ISlRecommendationRule;
ConditionItemset, ResultItemset, FreqItemset: ISlFrequentItemset;
Itemset: System.Array;
Begin
// Array containing transactions
tr[0] := 1; tr[15] := 6; tr[30] := 11;
tr[1] := 1; tr[16] := 6; tr[31] := 11;
tr[2] := 1; tr[17] := 6; tr[32] := 11;
tr[3] := 2; tr[18] := 7; tr[33] := 12;
tr[4] := 2; tr[19] := 7; tr[34] := 12;
tr[5] := 2; tr[20] := 7; tr[35] := 12;
tr[6] := 3; tr[21] := 8; tr[36] := 13;
tr[7] := 3; tr[22] := 8; tr[37] := 13;
tr[8] := 3; tr[23] := 8; tr[38] := 13;
tr[9] := 4; tr[24] := 9; tr[39] := 14;
tr[10] := 4; tr[25] := 9; tr[40] := 14;
tr[11] := 4; tr[26] := 9; tr[41] := 14;
tr[12] := 5; tr[27] := 10; tr[42] := 15;
tr[13] := 5; tr[28] := 10; tr[43] := 15;
tr[14] := 5; tr[29] := 10; tr[44] := 15;
// Array containing elements
obj[0] := 0; obj[15] := 3; obj[30] := 6;
obj[1] := 2; obj[16] := 4; obj[31] := 7;
obj[2] := 2; obj[17] := 5; obj[32] := 7;
obj[3] := 0; obj[18] := 6; obj[33] := 6;
obj[4] := 1; obj[19] := 4; obj[34] := 7;
obj[5] := 2; obj[20] := 5; obj[35] := 8;
obj[6] := 0; obj[21] := 5; obj[36] := 1;
obj[7] := 1; obj[22] := 4; obj[37] := 1;
obj[8] := 2; obj[23] := 5; obj[38] := 2;
obj[9] := 0; obj[24] := 6; obj[39] := 3;
obj[10] := 0; obj[25] := 7; obj[40] := 4;
obj[11] := 2; obj[26] := 4; obj[41] := 4;
obj[12] := 3; obj[27] := 6; obj[42] := 5;
obj[13] := 4; obj[28] := 7; obj[43] := 7;
obj[14] := 5; obj[29] := 8; obj[44] := 7;
// Create method
AsRu := New SmAssociationRules.Create();
// Arrays of transactions and elements
AsRu.Transactions := tr;
AsRu.Objects := obj;
// Minimum support (%)
AsRu.MinimumSupport := 10;
AsRu.UseSupportPercent := True;
// Minimum confidence level
AsRu.MinimumConfidence := 0.4;
// Maximum number of frequently occurred element sets
AsRu.MaximumFrequentItemsetsCount := 200000;
// Minimum number of elements in frequently occurred set
AsRu.MinimumFrequentItemsetSize := 1;
// Maximum number of elements in frequently occurred set
AsRu.MaximumFrequentItemsetSize := 3;
// Minimum significance level
AsRu.MinimumImportance := 0.1;
// Missing data treatment method
AsRu.MissingData.Method := MissingDataMethod.mdmCasewise;
// Perform calculation and output results
res := AsRu.Execute();
If res = 0 Then
Count := AsRu.RecommendationRulesCount;
System.Diagnostics.Debug.WriteLine("Number of significant rules: " + Count.ToString());
For i := 0 To Count - 1 Do
s := "";
s := s + "Condition: ";
Rule := AsRu.RecommendationRule[i];
ConditionItemset := Rule.ExplanatoryItemset;
Itemset := ConditionItemset.Itemset;
For j := 0 To Itemset.Length - 1 Do
s := s + Itemset[j].ToString() + ",";
End For;
ResultItemset := Rule.ExplainedItemset;
Itemset := ResultItemset.Itemset;
s := s + " -> consequence: ";
For j := 0 To Itemset.Length - 1 Do
s := s + Itemset[j].ToString() + ",";
End For;
System.Diagnostics.Debug.WriteLine(s);
System.Diagnostics.Debug.Indent();
System.Diagnostics.Debug.WriteLine("- confidence level: " + Rule.Confidence.ToString());
System.Diagnostics.Debug.WriteLine("- significance level: " + Rule.Importance.ToString());
System.Diagnostics.Debug.WriteLine("- support (%): " + Rule.SupportPercent.ToString());
System.Diagnostics.Debug.WriteLine("- support (number of transactions): " + Rule.SupportCount.ToString());
System.Diagnostics.Debug.Unindent();
End For;
System.Diagnostics.Debug.WriteLine("");
Count := AsRu.FrequentItemsetsCount;
System.Diagnostics.Debug.WriteLine("Number of frequently occurred element sets: " + Count.ToString());
For i := 0 To Count - 1 Do
s := "Set: ";
FreqItemset := AsRu.FrequentItemset[i];
Itemset := FreqItemset.Itemset;
For j := 0 To Itemset.Length - 1 Do
s := s + Itemset[j].ToString() + ";";
End For;
System.Diagnostics.Debug.WriteLine(s);
System.Diagnostics.Debug.Indent();
System.Diagnostics.Debug.WriteLine("- support (%): " + FreqItemset.SupportPercent.ToString());
System.Diagnostics.Debug.WriteLine("- support (number of transactions): " + FreqItemset.SupportCount.ToString());
System.Diagnostics.Debug.Unindent();
End For;
End If;
End Sub;
See also: