In the previous section, we performed all of the computation in a single script. While this is fine for data exploration, it means that we cannot reuse the logistic regression code that we have built. In this section, we will start the construction of a machine learning library that you can reuse across different projects.
We will factor the logistic regression algorithm out into its own class. We construct a LogisticRegression
class:
import breeze.linalg._ import breeze.numerics._ import breeze.optimize._ class LogisticRegression( val training:DenseMatrix[Double], val target:DenseVector[Double]) {
The class takes, as input, a matrix representing the training set and a vector denoting the target variable. Notice how we assign these to vals
, meaning that they are set on class creation and will remain the same until the class is destroyed. Of course, the DenseMatrix
and DenseVector
objects are mutable, so the values that training
and target
point to might change...