Changeset 17888
- Timestamp:
- 03/12/21 14:35:03 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/GeneralizedAdditiveModelAlgorithm.cs
r17815 r17888 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 600)] 40 40 public sealed class GeneralizedAdditiveModelAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 41 41 42 #region ParameterNames 42 43 … … 46 47 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; 47 48 private const string CreateSolutionParameterName = "CreateSolution"; 49 48 50 #endregion 49 51 … … 141 143 var problemData = Problem.ProblemData; 142 144 var ds = problemData.Dataset; 143 var trainRows = problemData.TrainingIndices ;144 var testRows = problemData.TestIndices ;145 var trainRows = problemData.TrainingIndices.ToArray(); 146 var testRows = problemData.TestIndices.ToArray(); 145 147 var avgY = problemData.TargetVariableTrainingValues.Average(); 146 148 var inputVars = problemData.AllowedInputVariables.ToArray(); … … 178 180 double[] resTest = problemData.TargetVariableTestValues.Select(yi => yi - avgY).ToArray(); 179 181 180 curRMSE.Value = res.StandardDeviation();181 curRMSETest.Value = resTest.StandardDeviation();182 rmseRow.Values.Add( res.StandardDeviation());183 rmseRowTest.Values.Add( resTest.StandardDeviation());182 curRMSE.Value = RMSE(res); 183 curRMSETest.Value = RMSE(resTest); 184 rmseRow.Values.Add(curRMSE.Value); 185 rmseRowTest.Values.Add(curRMSETest.Value); 184 186 185 187 … … 197 199 AddInPlace(resTest, f[inputIdx].GetEstimatedValues(ds, testRows)); 198 200 199 rssTable[inputIdx, 0] = res.Variance();201 rssTable[inputIdx, 0] = MSE(res); 200 202 f[inputIdx] = RegressSpline(problemData, inputVar, res, lambda); 201 203 … … 204 206 } 205 207 206 curRMSE.Value = res.StandardDeviation();207 curRMSETest.Value = resTest.StandardDeviation();208 curRMSE.Value = RMSE(res); 209 curRMSETest.Value = RMSE(resTest); 208 210 rmseRow.Values.Add(curRMSE.Value); 209 211 rmseRowTest.Values.Add(curRMSETest.Value); … … 215 217 var model = new RegressionEnsembleModel(f.Concat(new[] { new ConstantModel(avgY, problemData.TargetVariable) })); 216 218 model.AverageModelEstimates = false; 217 var solution = model.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 219 var solution = model.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 218 220 Results.Add(new Result("Ensemble solution", solution)); 219 221 } 222 } 223 224 public static double MSE(IEnumerable<double> residuals) { 225 var mse = residuals.Select(r => r * r).Average(); 226 return mse; 227 } 228 229 public static double RMSE(IEnumerable<double> residuals) { 230 var mse = MSE(residuals); 231 var rmse = Math.Sqrt(mse); 232 return rmse; 220 233 } 221 234
Note: See TracChangeset
for help on using the changeset viewer.