コード例 #1
0
        public override IRegressionModel Build(IRegressionProblemData pd, IRandom random,
                                               CancellationToken cancellationToken, out int numberOfParameters)
        {
            var pca    = PrincipleComponentTransformation.CreateProjection(pd.Dataset, pd.TrainingIndices, pd.AllowedInputVariables, normalize: true);
            var pcdata = pca.TransformProblemData(pd);
            ComponentReducedLinearModel bestModel = null;
            var bestCvrmse = double.MaxValue;

            numberOfParameters = 1;
            for (var i = 1; i <= Math.Min(NumberOfComponents, pd.AllowedInputVariables.Count()); i++)
            {
                var pd2    = (IRegressionProblemData)pcdata.Clone();
                var inputs = new HashSet <string>(pca.ComponentNames.Take(i));
                foreach (var v in pd2.InputVariables.CheckedItems.ToArray())
                {
                    pd2.InputVariables.SetItemCheckedState(v.Value, inputs.Contains(v.Value.Value));
                }
                double rmse;
                var    model = PreconstructedLinearModel.CreateLinearModel(pd2, out rmse);
                if (rmse > bestCvrmse)
                {
                    continue;
                }
                bestModel          = new ComponentReducedLinearModel(pd2.TargetVariable, model, pca);
                numberOfParameters = i + 1;
                bestCvrmse         = rmse;
            }
            return(bestModel);
        }
コード例 #2
0
 private ComponentReducedLinearModel(ComponentReducedLinearModel original, Cloner cloner) : base(original, cloner)
 {
     Model = cloner.Clone(original.Model);
     Pca   = cloner.Clone(original.Pca);
 }