ml.regression.RegressorBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jstat Show documentation
Show all versions of jstat Show documentation
Java Library for Statistical Analysis.
The newest version!
package ml.regression;
import datasets.VectorDouble;
import optimization.ISupervisedOptimizer;
import datastructs.IVector;
import datasets.DenseMatrixSet;
import maths.functions.IVectorRealFunction;
public class RegressorBase, HypothesisType extends IVectorRealFunction>> {
/**
* Train the regressor on the given dataset
*/
public OutputType train(DataSetType dataSet, VectorDouble y, ISupervisedOptimizer optimizer){
return optimizer.optimize(dataSet, y, this.hypothesisType);
}
/**
* Predict the value for the given input
*/
public double predict(VectorDouble y){
return (double) this.hypothesisType.evaluate(y);
}
/**
* Predict the outputs over the given dataset
*/
public VectorDouble predict(DataSetType dataSetType){
VectorDouble predictions = new VectorDouble(dataSetType.m(), 0.0);
for(int idx=0; idx r = dataSet.getRow(row);
double error = y.get(row) - this.hypothesisType.evaluate(r);
errs.set(row , error);
}
return errs;
}
/**
* Protected constructor.
*/
protected RegressorBase(HypothesisType hypothesis){
this.hypothesisType = hypothesis;
}
/**
* The hypothesis function assumed by the regressor
*/
protected HypothesisType hypothesisType;
}