public List <int> Predict(List <List <int> > X)
        {
            int numExamples = X.Count;
            int numFeatures = numExamples != 0 ? X[0].Count : 0;

            var yhat = new List <int>();

            if (_stump == null || _stump.splitVariable == -1)
            {
                for (int i = 0; i < numExamples; i++)
                {
                    yhat.Add(_stump.splitSat);
                }
            }
            else if (subModel1 == null)
            {
                yhat = _stump.Predict(X);
            }
            else
            {
                var pred1 = subModel1.Predict(X.Where(x => x[_stump.splitVariable] > _stump.splitValue).ToList());
                var pred0 = subModel0.Predict(X.Where(x => x[_stump.splitVariable] <= _stump.splitValue).ToList());

                var pred1Index = 0;
                var pred0Index = 0;

                for (int i = 0; i < numExamples; i++)
                {
                    if (X[i][_stump.splitVariable] > _stump.splitValue)
                    {
                        yhat.Add(pred1[pred1Index]);
                        pred1Index++;
                    }
                    else
                    {
                        yhat.Add(pred0[pred0Index]);
                        pred0Index++;
                    }
                }
            }

            return(yhat.ToList());
        }
Beispiel #2
0
 public List <int> Predict(List <List <int> > X)
 {
     return(decisionTreeRoot.Predict(X));
 }