The above article explains the principle, this article directly on the core code ~
Code is long, so the understanding may be a bit cumbersome, the core idea is to calculate the selected dimension after traversing the data, gradually cycle to calculate the confidence level, and eliminate the lowest value after each cycle.
One thing to note here is that I first wanted to use ArrayList to construct a stack structure for data traversal storage and calculation, because this is more efficient.
But later found that, if you want to change the type and the number of factors later, you need to do a lot of refactoring of the code to achieve the functionality of the update, and for my friend code such as the hard hand is estimated to be similar to writing the heavenly book. So at the time of implementation I gave up some of the efficiency, set each type to a single data table, then each table writes all the factors of that type, and finally the data is traversed by reading the tables in the database. In this case, the later wants to change the type and factor, can be directly in the database modification in the manner of processing, the code does not need to change the big.
= = There is no way, after all, not everyone will write code ... )
namespace fmanage{public partial class Analy:form {private system.windows.forms.checkbox[] Checkboxfactor S Private DataSet DS; Private int[] rowtables; Private int[] Flag; Private int[] dimention; Private int[] fee; private int p; Public Analy () {InitializeComponent (); This.panel1.SuspendLayout (); This. SuspendLayout (); The data loading process is slightly this.checkboxfactors = new system.windows.forms.checkbox[6];//setting feature selection for (int i = 0; I &l T 6; i++) {This.checkboxfactors[i] = new System.Windows.Forms.CheckBox (); This.checkboxfactors[i]. AutoSize = true; This.checkboxfactors[i]. Location = new System.Drawing.Point (total + i% 3 *, + + (int) Math.floor (convert.todouble (I/3) * 40)); This.checkboxfactors[i]. Size = new System.Drawing.Size (84, 16); This.checkboxfactors[i]. TabIndex = i + 1; This.checkboxfactors[i]. Usevisualstylebackcolor = true; THIS.PANEL1.CONTROLS.ADD (This.checkboxfactors[i]); } this.panel1.ResumeLayout (FALSE); This.panel1.PerformLayout (); This. ResumeLayout (FALSE); This. PerformLayout (); private void Analy_load (object sender, EventArgs e) {rowtables = new int[8]; for (int i = 0; i < 8; i++) {Rowtables[i] = ds. Tables[i]. Rows.Count; } dimention = new int[8]; for (int i = 0; i < 8; i++) {Dimention[i] = ds. Tables[i]. Rows.Count; The}//calculation selects the dimension private void Countfee (ref int[] fee) {int p; for (int i = 0; i < dimention[7]; i++) {p = 0; for (int j = 0; J < 7; J + +) {if (flag[j] = = 1) fee[i] + = System.Convert.ToInt32 (ds. TABLES[7]. Rows[i]. Itemarray[j + 1]) * (int) Math.pow (ten, p++); }}} private void circlestring (int a, int end, ref string[] finalstring, ref int[] needle, Strin G[][] tempstring) {for (int i = 0; i < Tempstring[a]. Length; i++) {Needle[a] = i; if (a = = End-1) {for (int j = 0; J < End; J + +) { finalstring[p++] = tempstring[j][needle[j]]; }} else {circlestring (A + 1, end, ref finalstring, ref n Eedle, tempstring); }}} private void circlecalculationstring (int a, int end, ref string[] finalcalculation, ref int [] needlecalculation, string[][] tempcalculation) {for (int i = 0; i < Tempcalculation[a]. Length; i++) { Needlecalculation[a] = i; if (a = = End-1) {for (int j = 0; J < End; J + +) { finalcalculation[p++] = tempcalculation[j][needlecalculation[j]]; }} else {circlecalculationstring (A + 1, end, ref FINALCA Lculation, ref needlecalculation, tempcalculation); }}}//compute support degree and confidence private void Buttoncalculate_click (object sender, EventArgs e) { Double zhichidunumber = convert.todouble (rank1. Text)/100; Double zhixindunumber = convert.todouble (rank2. Text)/100; fee = new Int[dimention[7]]; Flag = new Int[7]; Flag[0] = 1; for (int i = 0; i < 6; i++) {if (This.checkboxfactors[i]. Checked) Flag[i + 1] = 1; else Flag[i + 1] = 0; } countfee (ref fee); #region showstring string[][] tempstring = new String[flag. Sum ()-1][]; int temp = 0; for (int i = 0; i < flag. Sum ()-1; i++) {do {temp++; if (temp = = 7) Break,} while (flag[temp] = = 0); Tempstring[i] = new String[dimention[temp]]; for (int j = 0; J < Dimention[temp]; J + +) {Tempstring[i][j] = ds. Tables[temp]. ROWS[J]. ITEMARRAY[1]. ToString (); }} int[] needlestring = new Int[flag. Sum ()-1]; for (int i = 0; i < flag. Sum ()-1; i++) {Needlestring[i] = 0; } int finalnumber = 1; for (int i = 1; i < 7; i++) {if (flag[i] = = 1) finalnumber *= ds. Tables[i]. Rows.Count; } datatable showtable = new DataTable ("Showtable"); DataColumn Finalcol = ShowTable.Columns.Add ("ID", typeof (Int32)); Finalcol.allowdbnull = false; Finalcol.unique = true; for (int i = 1; i < 7; i++) {if (flag[i] = = 1) showTable.Columns.Add (ds.t ABLES[7]. Columns[i + 1]. ColumnName, typeof (String)); } SHOWTABLE.COLUMNS.ADD ("Support degree (%)", typeof (Double)); SHOWTABLE.COLUMNS.ADD ("confidence level (%)", typeof (Double)); string[] showstring = new String[finalnumber * (flag. Sum ()-1)]; p = 0; Circlestring (0, flag. Sum ()-1, ref showstring, ref needlestring, tempstring); DataRow Showrow; p = 0; for (int i = 0; i < Finalnumber; i++) {showrow = Showtable.newrow (); Showrow[0] = i + 1; for (int j = 0; J < flag. Sum ()-1; J + +) {showrow[j + 1] = showstring[p++]; } ShowroW[flag. Sum ()] = 0; Showrow[flag. Sum () + 1] = 0; SHOWTABLE.ROWS.ADD (Showrow); } #endregion #region calculation string[][] tempcalculation = new String[flag. Sum () []; temp = 0; for (int i = 0; i < flag. Sum (); i++) {Tempcalculation[i] = new String[dimention[temp]]; for (int j = 0; J < Dimention[temp]; J + +) {Tempcalculation[i][j] = ds. Tables[temp]. ROWS[J]. Itemarray[0]. ToString (); } do {temp++; if (temp = = 7) Break,} while (flag[temp] = = 0); } int[] Needlecalculation = new Int[flag. Sum ()]; for (int i = 0; i < flag. Sum (); i++) {Needlecalculation[i] = 0; } finalnumber = 1; for (int i = 0; i < 7; i++) {if (flag[i] = = 1) finalnumber *= ds. tables[I]. Rows.Count; } datatable calculationtable = new DataTable ("Calculationtable"); for (int i = 0; i < 7; i++) {if (flag[i] = = 1) calculationtable.columns.a DD (ds. TABLES[7]. Columns[i + 1]. ColumnName, typeof (String)); } string[] Finalcalculation = new String[finalnumber * flag. Sum ()]; p = 0; Circlecalculationstring (0, flag. Sum (), ref finalcalculation, ref needlecalculation, tempcalculation); DataRow Calculationrow; p = 0; for (int i = 0; i < Finalnumber; i++) {calculationrow = Calculationtable.newrow (); for (int j = 0; J < flag. Sum (); J + +) {Calculationrow[j] = finalcalculation[p++]; } calculationTable.Rows.Add (Calculationrow); } #endregion int[] Objectivefee = new Int[finalnumber]; for (int i = 0, i < Finalnumber; i++) {for (int j = 0; J < flag. Sum (); J + +) {Objectivefee[i] + = System.Convert.ToInt32 (Calculationtable.rows[i]. ITEMARRAY[J]) * (int) Math.pow (j); }} double[,] times = new double[3, FINALNUMBER/2]; for (int i = 0, i < FINALNUMBER/2; i++) {for (int j = 0; J < Dimention[7]; j + +) {if (objectivefee[i] = = Fee[j]) times[0, i]++; }} for (int i = FINALNUMBER/2; i < Finalnumber; i++) {for (int j = 0; J < Dimention[7]; J + +) {if (objectivefee[i] = = Fee[j]) times[1, I-finalnumber/ 2]++; }} for (int i = 0; i < FINALNUMBER/2; i++) {times[2, I] = times[0, I] + times[1, I]; } double[] Zhichidu = new DOUBLE[FINALNUMBER/2]; for (int i = 0; i < FINALNUMBER/2; i++) {Zhichidu[i] = times[2, I]/1000.0; } double[] Zhixindu = new DOUBLE[FINALNUMBER/2]; for (int i = 0; i < FINALNUMBER/2; i++) {if (times[2, I] > 0) { Zhixindu[i] = ((int) (times[0, I]/times[2, I] * 10000))/10000.0; } else Zhixindu[i] = 0; } for (int i = 0; i < FINALNUMBER/2; i++) {Showtable.rows[i][flag. Sum ()] = Zhichidu[i]; Showtable.rows[i][flag. Sum () + 1] = Zhixindu[i]; } for (int i = 0; i < ShowTable.Rows.Count; i++) {Showtable.rows[i][0] = i + 1; Showtable.rows[i][flag. Sum ()] = (int) (Convert.todouble (Showtable.rows[i][flag. Sum ()]) * 1000)/10.0; Showtable.rows[i][flag. Sum () + 1] = (int) (Convert.todouble (Showtable.rows[i][flag). Sum () + 1]) * 1000)/10.0; } This.dataGridView1.DataSource = null; This.dataGridView1.DataSource = Showtable.defaultview; This.dataGridView1.Visible = true; } }}
Implementation of mining--apriori algorithm for GIS Information Association rules (next)