numAttributes++;
}
}
// Check whether there are still attributes left
Matrix independent = null, dependent = null;
double[] weights = null;
if (numAttributes > 0) {
independent = new Matrix(m_TransformedData.numInstances(),
numAttributes);
dependent = new Matrix(m_TransformedData.numInstances(), 1);
for (int i = 0; i < m_TransformedData.numInstances(); i ++) {
Instance inst = m_TransformedData.instance(i);
int column = 0;
for (int j = 0; j < m_TransformedData.numAttributes(); j++) {
if (j == m_ClassIndex) {
dependent.setElement(i, 0, inst.classValue());
} else {
if (selectedAttributes[j]) {
double value = inst.value(j) - m_Means[j];
// We only need to do this if we want to
// scale the input
if (!m_checksTurnedOff) {
value /= m_StdDevs[j];
}
independent.setElement(i, column, value);
column++;
}
}
}
}
// Grab instance weights
weights = new double [m_TransformedData.numInstances()];
for (int i = 0; i < weights.length; i++) {
weights[i] = m_TransformedData.instance(i).weight();
}
}
// Compute coefficients (note that we have to treat the
// intercept separately so that it doesn't get affected
// by the ridge constant.)
double[] coefficients = new double[numAttributes + 1];
if (numAttributes > 0) {
double[] coeffsWithoutIntercept =
independent.regression(dependent, weights, m_Ridge);
System.arraycopy(coeffsWithoutIntercept, 0, coefficients, 0,
numAttributes);
}
coefficients[numAttributes] = m_ClassMean;