{"record":{"id":"5e6ef8635147c855","repo":"dotnet/machinelearning","slug":"metric-is-not-supported-5e6ef8","errorCode":null,"errorMessage":"{metric} is not supported!","messagePattern":"(.+?) is not supported!","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.AutoML/API/RegressionExperiment.cs","lineNumber":477,"sourceCode":"                throw;\n            }\n        }\n\n        public void Dispose()\n        {\n            _context.CancelExecution();\n            _context = null;\n        }\n\n        private double GetMetric(RegressionMetric metric, RegressionMetrics metrics)\n        {\n            return metric switch\n            {\n                RegressionMetric.RootMeanSquaredError => metrics.RootMeanSquaredError,\n                RegressionMetric.RSquared => metrics.RSquared,\n                RegressionMetric.MeanSquaredError => metrics.MeanSquaredError,\n                RegressionMetric.MeanAbsoluteError => metrics.MeanAbsoluteError,\n                _ => throw new NotImplementedException($\"{metric} is not supported!\"),\n            };\n        }\n    }\n}\n","sourceCodeStart":459,"sourceCodeEnd":482,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.AutoML/API/RegressionExperiment.cs#L459-L482","documentation":"The RegressionTrialRunner's GetMetric maps RegressionMetric enum values to metric fields; only RootMeanSquaredError, RSquared, MeanSquaredError, and MeanAbsoluteError are mapped. Any other RegressionMetric value reaches the default arm and throws NotImplementedException.","triggerScenarios":"Requesting a RegressionMetric not in the four supported arms (e.g. RootMeanSquaredErrorTransformed, PoissonLoss, or LogLoss) when the runner computes the score of a trial.","commonSituations":"Choosing an optimizer metric that exists on the RegressionMetric enum but is not wired into the AutoML runner; enum members added in newer ML.NET versions; configs specifying a loss metric intended for a different trainer.","solutions":["Set the experiment's optimizer metric to RootMeanSquaredError, RSquared, MeanSquaredError, or MeanAbsoluteError.","Validate the configured metric against the supported set before starting the sweep.","Extend the switch with an arm for the required metric and upstream the change."],"exampleFix":"// before\nvar exp = ctx.Auto().CreateRegressionExperiment(data);\nexp.SetMetric(RegressionMetric.PoissonLoss); // throws in runner\n// after\nexp.SetMetric(RegressionMetric.RootMeanSquaredError);","handlingStrategy":"validation","validationCode":"private static readonly RegressionMetric[] SupportedMetrics =\n{\n    RegressionMetric.RootMeanSquaredError,\n    RegressionMetric.RSquared,\n    RegressionMetric.MeanSquaredError,\n    RegressionMetric.MeanAbsoluteError\n};\n// before running:\nif (!SupportedMetrics.Contains(metric)) throw new ArgumentException($\"Metric {metric} not supported by the regression runner\");","typeGuard":"bool IsSupported(RegressionMetric m) => m is RegressionMetric.RootMeanSquaredError or RegressionMetric.RSquared or RegressionMetric.MeanSquaredError or RegressionMetric.MeanAbsoluteError;","tryCatchPattern":"try { exp.SetMetric(metric); }\ncatch (NotImplementedException) { exp.SetMetric(RegressionMetric.RootMeanSquaredError); // safe default\n}","preventionTips":["Pick optimizer metrics only from the four documented regression metrics","Validate metric config before experiment construction","Prefer RootMeanSquaredError as the safe default for regression sweeps"],"tags":["not-implemented","enum","metric","regression","automl"],"backgroundTag":"unsupported-enum-value","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}