pmlpp/mlpp/uni_lin_reg/uni_lin_reg.cpp

35 lines
750 B
C++
Raw Normal View History

//
// UniLinReg.cpp
//
// Created by Marc Melikyan on 9/29/20.
//
2023-01-24 18:12:23 +01:00
#include "uni_lin_reg.h"
#include "../lin_alg/lin_alg.h"
#include "../stat/stat.h"
#include <iostream>
// General Multivariate Linear Regression Model
// ŷ = b0 + b1x1 + b2x2 + ... + bkxk
// Univariate Linear Regression Model
// ŷ = b0 + b1x1
2023-01-24 19:20:18 +01:00
2023-01-24 19:00:54 +01:00
UniLinReg::UniLinReg(std::vector<double> x, std::vector<double> y) :
inputSet(x), outputSet(y) {
Stat estimator;
b1 = estimator.b1Estimation(inputSet, outputSet);
b0 = estimator.b0Estimation(inputSet, outputSet);
}
2023-01-24 19:00:54 +01:00
std::vector<double> UniLinReg::modelSetTest(std::vector<double> x) {
LinAlg alg;
return alg.scalarAdd(b0, alg.scalarMultiply(b1, x));
}
2023-01-24 19:00:54 +01:00
double UniLinReg::modelTest(double input) {
return b0 + b1 * input;
}
2023-01-24 19:20:18 +01:00