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"; }
private RandomForestModelFull(RandomForestModelFull original, Cloner cloner) : base(original, cloner) { randomForest = new alglib.decisionforest(); randomForest.innerobj.bufsize = original.randomForest.innerobj.bufsize; randomForest.innerobj.nclasses = original.randomForest.innerobj.nclasses; randomForest.innerobj.ntrees = original.randomForest.innerobj.ntrees; randomForest.innerobj.nvars = original.randomForest.innerobj.nvars; randomForest.innerobj.trees = (double[])original.randomForest.innerobj.trees.Clone(); // following fields are immutable so we don't need to clone them inputVariables = original.inputVariables; classValues = original.classValues; }
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,... }
// random forest models can only be created through the static factory methods CreateRegressionModel and CreateClassificationModel private RandomForestModel(string targetVariable, alglib.decisionforest randomForest, int seed, IDataAnalysisProblemData originalTrainingData, int nTrees, double r, double m, double[] classValues = null) : base(targetVariable) { this.name = ItemName; this.description = ItemDescription; // the model itself this.randomForest = randomForest; // data which is necessary for recalculation of the model this.seed = seed; this.originalTrainingData = (IDataAnalysisProblemData)originalTrainingData.Clone(); this.classValues = classValues; this.nTrees = nTrees; this.r = r; this.m = m; }
public RandomForestModelFull(alglib.decisionforest decisionForest, string targetVariable, IEnumerable <string> inputVariables, IEnumerable <double> classValues = null) : base(targetVariable) { this.name = ItemName; this.description = ItemDescription; randomForest = decisionForest; this.inputVariables = inputVariables.ToArray(); //classValues are only use for classification models if (classValues == null) { this.classValues = new double[0]; } else { this.classValues = classValues.ToArray(); } }
private void RecalculateModel() { double rmsError, oobRmsError, relClassError, oobRelClassError; var regressionProblemData = originalTrainingData as IRegressionProblemData; var classificationProblemData = originalTrainingData as IClassificationProblemData; if (regressionProblemData != null) { var model = CreateRegressionModel(regressionProblemData, nTrees, r, m, seed, out rmsError, out oobRmsError, out relClassError, out oobRelClassError); randomForest = model.randomForest; } else if (classificationProblemData != null) { var model = CreateClassificationModel(classificationProblemData, nTrees, r, m, seed, out rmsError, out oobRmsError, out relClassError, out oobRelClassError); randomForest = model.randomForest; } }
private RandomForestModel(RandomForestModel original, Cloner cloner) : base(original, cloner) { randomForest = new alglib.decisionforest(); randomForest.innerobj.bufsize = original.randomForest.innerobj.bufsize; randomForest.innerobj.nclasses = original.randomForest.innerobj.nclasses; randomForest.innerobj.ntrees = original.randomForest.innerobj.ntrees; randomForest.innerobj.nvars = original.randomForest.innerobj.nvars; // we assume that the trees array (double[]) is immutable in alglib randomForest.innerobj.trees = original.randomForest.innerobj.trees; // allowedInputVariables is immutable so we don't need to clone allowedInputVariables = original.allowedInputVariables; // clone data which is necessary to rebuild the model this.seed = original.seed; this.originalTrainingData = cloner.Clone(original.originalTrainingData); // classvalues is immutable so we don't need to clone this.classValues = original.classValues; this.nTrees = original.nTrees; this.r = original.r; this.m = original.m; }
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 RandomForestModelFull(StorableConstructorFlag _) : base(_) { randomForest = new alglib.decisionforest(); }
private RandomForestModel(bool deserializing) : base(deserializing) { // for backwards compatibility (loading old solutions) randomForest = new alglib.decisionforest(); }
private RandomForestModel(StorableConstructorFlag _) : base(_) { // for backwards compatibility (loading old solutions) randomForest = new alglib.decisionforest(); }
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 void getVariableImportanceChart() { if (df == null) df = getDfModel(); string[] errortype = { "RMSE", "Average", "Average Relative", "Average Cross Entropy", "Classification" }; if (reg) { errortype = new string[] { "RMSE", "Average", "Average Relative" }; } Forms.Stats.frmChart hist = (Forms.Stats.frmChart)ModelHelper.generateVariableImportanceGraphic(IndependentFieldNames,errortype); System.Windows.Forms.ComboBox cmbPrimary = (System.Windows.Forms.ComboBox)hist.Controls["cmbPrimary"]; cmbPrimary.SelectedValueChanged += new EventHandler(cmbPrimary_SelectedValueChanged_VI); hist.chrHistogram.Show(); if (reg) { cmbPrimary.SelectedItem = "RMSE"; } else { cmbPrimary.SelectedItem = "Classification"; } hist.Show(); }
private void getRegChart() { if (df == null) df = getDfModel(); Forms.Stats.frmChart hist = (Forms.Stats.frmChart)ModelHelper.generateProbabilityGraphic(IndependentFieldNames); System.Windows.Forms.ComboBox cmbPrimary = (System.Windows.Forms.ComboBox)hist.Controls["cmbPrimary"]; cmbPrimary.SelectedValueChanged += new EventHandler(cmbPrimary_SelectedValueChanged); System.Windows.Forms.TrackBar tb = (System.Windows.Forms.TrackBar)hist.Controls["tbQ"]; tb.Scroll += new EventHandler(tb_RegionChanged); hist.chrHistogram.Show(); cmbPrimary.SelectedItem = IndependentFieldNames[0]; hist.Show(); }
// random forest models can only be created through the static factory methods CreateRegressionModel and CreateClassificationModel private RandomForestModel(alglib.decisionforest randomForest, int seed, IDataAnalysisProblemData originalTrainingData, int nTrees, double r, double m, double[] classValues = null) : base() { this.name = ItemName; this.description = ItemDescription; // the model itself this.randomForest = randomForest; // data which is necessary for recalculation of the model this.seed = seed; this.originalTrainingData = (IDataAnalysisProblemData)originalTrainingData.Clone(); this.classValues = classValues; this.nTrees = nTrees; this.r = r; this.m = m; }