예제 #1
0
        private double CalculateRsquare(DataSet dataSet, List <Variable> valueArrayX, Variable valueY, Matrix <double> beta)
        {
            double ssTot = 0;
            double ssRes = 0;

            for (var i = 0; i < dataSet.rangeSize(); i++)
            {
                ssTot = ssTot + (dataSet.getValuesArray(valueY)[i] - _functions.Average(valueY.getRange())) * (dataSet.getValuesArray(valueY)[i] - _functions.Average(valueY.getRange()));
                var fittedValue = beta[0, 0];
                for (var j = 0; j < valueArrayX.Count; j++)
                {
                    fittedValue = fittedValue + beta[j + 1, 0] * dataSet.getValuesArray(valueArrayX[j])[i];
                }
                ssRes = ssRes + (dataSet.getValuesArray(valueY)[i] - fittedValue) * (dataSet.getValuesArray(valueY)[i] - fittedValue);
            }
            var rSquare = 1 - ssRes / ssTot;

            return(rSquare);
        }
예제 #2
0
        private double CalculateRsquare(IReadOnlyList <Models.Data> valueArrayX, IReadOnlyList <Models.Data> valueArrayY, Matrix <double> beta)
        {
            double ssTot = 0;
            double ssRes = 0;

            for (var i = 0; i < valueArrayY[0].GetValuesList().Count; i++)
            {
                ssTot = ssTot + (valueArrayY[0].GetValuesList()[i] - _functions.Average(valueArrayY[0].Range)) * (valueArrayY[0].GetValuesList()[i] - _functions.Average(valueArrayY[0].Range));
                var fittedValue = beta[0, 0];
                for (var j = 0; j < valueArrayX.Count; j++)
                {
                    fittedValue = fittedValue + beta[j + 1, 0] * valueArrayX[j].GetValuesList()[i];
                }
                ssRes = ssRes + (valueArrayY[0].GetValuesList()[i] - fittedValue) * (valueArrayY[0].GetValuesList()[i] - fittedValue);
            }
            var rSquare = 1 - ssRes / ssTot;

            return(rSquare);
        }