本文整理匯總了Java中org.apache.commons.math3.stat.regression.SimpleRegression.getR方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleRegression.getR方法的具體用法?Java SimpleRegression.getR怎麽用?Java SimpleRegression.getR使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.stat.regression.SimpleRegression
的用法示例。
在下文中一共展示了SimpleRegression.getR方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: correlation
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
public static double correlation(IDoubleVector x, IDoubleVector y) {
final int len = x.getLength();
if (len != y.getLength()) {
throw new AdeCoreIllegalArgumentException("Mismatching lengths");
}
if (len < 2) {
throw new AdeCoreIllegalArgumentException("Vectors must have length >=2");
}
final SimpleRegression regression = new SimpleRegression();
for (int i = 0; i < len; i++) {
regression.addData(x.get(i), y.get(i));
}
return regression.getR();
}
示例2: correlation
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
* Computes the Pearson's product-moment correlation coefficient between two arrays.
*
* <p>Throws MathIllegalArgumentException if the arrays do not have the same length
* or their common length is less than 2. Returns {@code NaN} if either of the arrays
* has zero variance (i.e., if one of the arrays does not contain at least two distinct
* values).</p>
*
* @param xArray first data array
* @param yArray second data array
* @return Returns Pearson's correlation coefficient for the two arrays
* @throws DimensionMismatchException if the arrays lengths do not match
* @throws MathIllegalArgumentException if there is insufficient data
*/
public double correlation(final double[] xArray, final double[] yArray) {
SimpleRegression regression = new SimpleRegression();
if (xArray.length != yArray.length) {
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (xArray.length < 2) {
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
xArray.length, 2);
} else {
for(int i=0; i<xArray.length; i++) {
regression.addData(xArray[i], yArray[i]);
}
return regression.getR();
}
}
示例3: correlation
import org.apache.commons.math3.stat.regression.SimpleRegression; //導入方法依賴的package包/類
/**
* Computes the Pearson's product-moment correlation coefficient between the two arrays.
*
* </p>Throws IllegalArgumentException if the arrays do not have the same length
* or their common length is less than 2</p>
*
* @param xArray first data array
* @param yArray second data array
* @return Returns Pearson's correlation coefficient for the two arrays
* @throws DimensionMismatchException if the arrays lengths do not match
* @throws MathIllegalArgumentException if there is insufficient data
*/
public double correlation(final double[] xArray, final double[] yArray) {
SimpleRegression regression = new SimpleRegression();
if (xArray.length != yArray.length) {
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (xArray.length < 2) {
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
xArray.length, 2);
} else {
for(int i=0; i<xArray.length; i++) {
regression.addData(xArray[i], yArray[i]);
}
return regression.getR();
}
}