use of org.apache.commons.math3.stat.regression.UpdatingMultipleLinearRegression in project knime-core by knime.
the class Learner method perform.
/**
* @param data The data table.
* @param exec The execution context used for reporting progress.
* @return An object which holds the results.
* @throws CanceledExecutionException When method is cancelled
* @throws InvalidSettingsException When settings are inconsistent with the data
*/
@Override
public PolyRegContent perform(final BufferedDataTable data, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
exec.checkCanceled();
RegressionTrainingData trainingData = new RegressionTrainingData(data, m_outSpec, m_failOnMissing);
int regressorCount = trainingData.getRegressorCount() * m_maxExponent;
SummaryStatistics[] stats = new SummaryStatistics[regressorCount];
UpdatingMultipleLinearRegression regr = initStatistics(regressorCount, stats);
exec.setProgress(0, "Estimating polynomial regression model.");
processTable(exec, trainingData, stats, regr);
RegressionResults result = regr.regress();
RealMatrix beta = MatrixUtils.createRowRealMatrix(result.getParameterEstimates());
List<String> factorList = new ArrayList<String>();
List<String> covariateList = createCovariateListAndFillFactors(data, trainingData, factorList);
// The covariance matrix
RealMatrix covMat = createCovarianceMatrix(result);
PolyRegContent content = new PolyRegContent(m_outSpec, (int) stats[0].getN(), factorList, covariateList, beta, m_offsetValue, covMat, result.getRSquared(), result.getAdjustedRSquared(), stats, m_maxExponent);
return content;
}
use of org.apache.commons.math3.stat.regression.UpdatingMultipleLinearRegression in project knime-core by knime.
the class Learner method perform.
/**
* @param data The data table.
* @param exec The execution context used for reporting progress.
* @return An object which holds the results.
* @throws CanceledExecutionException When method is cancelled
* @throws InvalidSettingsException When settings are inconsistent with the data
*/
@Override
public LinearRegressionContent perform(final BufferedDataTable data, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
exec.checkCanceled();
RegressionTrainingData trainingData = new RegressionTrainingData(data, m_outSpec, m_failOnMissing);
final int regressorCount = Math.max(1, trainingData.getRegressorCount());
SummaryStatistics[] stats = new SummaryStatistics[regressorCount];
UpdatingMultipleLinearRegression regr = initStatistics(regressorCount, stats);
processTable(exec, trainingData, stats, regr);
List<String> factorList = new ArrayList<String>();
List<String> covariateList = createCovariateListAndFillFactors(data, trainingData, factorList);
try {
RegressionResults result = regr.regress();
RealMatrix beta = MatrixUtils.createRowRealMatrix(result.getParameterEstimates());
// The covariance matrix
RealMatrix covMat = createCovarianceMatrix(result);
LinearRegressionContent content = new LinearRegressionContent(m_outSpec, (int) stats[0].getN(), factorList, covariateList, beta, m_includeConstant, m_offsetValue, covMat, result.getRSquared(), result.getAdjustedRSquared(), stats, null);
return content;
} catch (ModelSpecificationException e) {
int dim = (m_includeConstant ? 1 : 0) + trainingData.getRegressorCount() + (factorList.size() > 0 ? Math.max(1, data.getDataTableSpec().getColumnSpec(factorList.get(0)).getDomain().getValues().size() - 1) : 0);
RealMatrix beta = MatrixUtils.createRealMatrix(1, dim);
RealMatrix covMat = MatrixUtils.createRealMatrix(dim, dim);
// fillWithNaNs(beta);
fillWithNaNs(covMat);
return new LinearRegressionContent(m_outSpec, (int) stats[0].getN(), factorList, covariateList, beta, m_includeConstant, m_offsetValue, covMat, Double.NaN, Double.NaN, stats, e.getMessage());
}
}
Aggregations