Regression: Better guard for not-finite values
This commit is contained in:
@@ -33,7 +33,7 @@ RegressionResult regression(std::vector<float> &x, std::vector<float> &y, const
|
||||
int64_t nelem = 0;
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (std::isfinite(y[i])) {
|
||||
if (std::isfinite(y[i]) && std::isfinite(x[i])) {
|
||||
x_sum += x[i];
|
||||
y_sum += y[i];
|
||||
x2_sum += x[i] * x[i];
|
||||
@@ -58,9 +58,11 @@ RegressionResult regression(std::vector<float> &x, std::vector<float> &y, const
|
||||
fptype ss_reg = 0.0;
|
||||
|
||||
for (int i = 0; i < nelem; i++) {
|
||||
fptype pred = slope * x[i] + intercept;
|
||||
ss_tot += (y[i] - y_mean) * (y[i] - y_mean);
|
||||
ss_reg += (pred - y_mean) * (pred - y_mean);
|
||||
if (std::isfinite(y[i]) && std::isfinite(x[i])) {
|
||||
fptype pred = slope * x[i] + intercept;
|
||||
ss_tot += (y[i] - y_mean) * (y[i] - y_mean);
|
||||
ss_reg += (pred - y_mean) * (pred - y_mean);
|
||||
}
|
||||
}
|
||||
|
||||
fptype r_square = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user