/// <summary> /// 计算变量重要性 /// </summary> /// <param name="xy"></param> /// <param name="oobavgerror"></param> private void computeSignificant(double[,] xy, alglib.dfreport rep) { int dim1 = xy.GetLength(0); // 测试集大小 int dim2 = xy.GetLength(1); // 自变量个数+1 double[] results = new double[dim2 - 1]; int info; alglib.decisionforest df; alglib.dfreport rep1; for (int i = 0; i < results.Length; i++) { double[,] xy1 = (double[, ])xy.Clone(); // 清空列 for (int j = 0; j < dim1; j++) { xy1[j, i] = 0; } alglib.dfbuildrandomdecisionforest(xy1, dim1, dim2 - 1, this.landInfo.NumOfLandUseTypes, this.NumOfTree, this.SampleRatio, out info, out df, out rep1); results[i] = rep.oobavgce - rep.oobavgce; //this.updateConsoleEvent("变量" + (i + 1) + "的重要性分数oobavgce是" + (rep.oobavgce - rep1.oobavgce)); //this.updateConsoleEvent("变量" + (i + 1) + "的重要性分数oobavgerror是" + (rep.oobavgerror - rep1.oobavgerror)); //this.updateConsoleEvent("变量" + (i + 1) + "的重要性分数oobavgrelerror是" + (rep.oobavgrelerror - rep1.oobavgrelerror)); //this.updateConsoleEvent("变量" + (i + 1) + "的重要性分数oobrelclserror是" + (rep.oobrelclserror - rep1.oobrelclserror)); this.updateConsoleEvent("变量" + (i + 1) + this.driveLayerNames[i] + "的重要性分数oobrmserror是" + (rep1.oobrmserror - rep.oobrmserror)); } }
public void forestText() { //-----------------------------текст из поля ввода-------------------------------- string VocabularyTxt = "../../../data/vocabulary.txt"; vocabulary = File.ReadAllLines(VocabularyTxt); double[] text = new double[vocabulary.Length]; Char[] separators = { ' ', ',', '.', '-', '\n' }; song = richTextBox1.Text.Split(separators); int i = 0; double[] textAnalys = { 0, 0 }; foreach (string str in vocabulary) { foreach (string str1 in song) { if (string.Equals(str, str1)) { text[i] = text[i] + 1; } } i++; } //----------------------------...................................текст из поля ввода // Чтение CSV -------------------------------------------------------------------------------------------------- char separator = ';'; int flags = 0; // Случайный лес решений -------------------------------------------------------------------------------------------------- var dForest1 = new alglib.decisionforest(); var rep = new alglib.dfreport(); int info; alglib.read_csv("../../../data/trainText.csv", separator, flags, out TrainingSet); // ---------------------------------------------------------------------------------------------------Чтение CSV alglib.dfbuildrandomdecisionforestx1(TrainingSet, 40, 2945, 2, 200, 1, 0.9, out info, out dForest1, out rep); alglib.dfprocess(dForest1, text, ref textAnalys); label1.Text = "Random forest:\n" + "Result: " + info.ToString() + "\n" + "Веселый : " + textAnalys[0].ToString() + "\n" + "Грустный : " + textAnalys[1].ToString() + "\n"; // + "Романтический : " + textAnalys[2].ToString() + "\n" // + "Философский : " + textAnalys[3].ToString() + "\n" // + "Политический : " + textAnalys[4].ToString() + "\n" // + "Бессмысленный : " + textAnalys[5].ToString() + "\n"; }
public void construire(double[,] lu) { rf = new alglib.decisionforest(); int npoints = longue - 1; int nvars = larg - 1; int nclasses = 1; int ntrees = 100; int info = 0; double r = 0.66; alglib.dfreport rep = new alglib.dfreport(); alglib.dfbuildrandomdecisionforest(lu, npoints, nvars, nclasses, ntrees, r, out info, out rf, out rep); //Entrée, Samples(nombre de sets), nbFeatures20, nclasse4, trees 100, r 0.66,... }
private static alglib.decisionforest CreateRandomForestModel(int seed, double[,] inputMatrix, int nTrees, double r, double m, int nClasses, out alglib.dfreport rep) { AssertParameters(r, m); AssertInputMatrix(inputMatrix); int info = 0; alglib.math.rndobject = new System.Random(seed); var dForest = new alglib.decisionforest(); rep = new alglib.dfreport(); int nRows = inputMatrix.GetLength(0); int nColumns = inputMatrix.GetLength(1); int sampleSize = Math.Max((int)Math.Round(r * nRows), 1); int nFeatures = Math.Max((int)Math.Round(m * (nColumns - 1)), 1); alglib.dforest.dfbuildinternal(inputMatrix, nRows, nColumns - 1, nClasses, nTrees, sampleSize, nFeatures, alglib.dforest.dfusestrongsplits + alglib.dforest.dfuseevs, ref info, dForest.innerobj, rep.innerobj); if (info != 1) { throw new ArgumentException("Error in calculation of random forest model"); } return(dForest); }
private static alglib.decisionforest CreateRandomForestModel(int seed, double[,] inputMatrix, int nTrees, double r, double m, int nClasses, out alglib.dfreport rep) { AssertParameters(r, m); AssertInputMatrix(inputMatrix); int info = 0; alglib.math.rndobject = new System.Random(seed); var dForest = new alglib.decisionforest(); rep = new alglib.dfreport(); int nRows = inputMatrix.GetLength(0); int nColumns = inputMatrix.GetLength(1); int sampleSize = Math.Max((int)Math.Round(r * nRows), 1); int nFeatures = Math.Max((int)Math.Round(m * (nColumns - 1)), 1); alglib.dforest.dfbuildinternal(inputMatrix, nRows, nColumns - 1, nClasses, nTrees, sampleSize, nFeatures, alglib.dforest.dfusestrongsplits + alglib.dforest.dfuseevs, ref info, dForest.innerobj, rep.innerobj); if (info != 1) throw new ArgumentException("Error in calculation of random forest model"); return dForest; }