axle.ml.LinearRegression makes use of axle.algebra.LinearAlgebra.

See the wikipedia page on Linear Regression

Predicting Home Prices

case class RealtyListing(size: Double, bedrooms: Int, floors: Int, age: Int, price: Double)
// defined class RealtyListing

val listings = List(
  RealtyListing(2104, 5, 1, 45, 460d),
  RealtyListing(1416, 3, 2, 40, 232d),
  RealtyListing(1534, 3, 2, 30, 315d),
  RealtyListing(852, 2, 1, 36, 178d))
// listings: List[RealtyListing] = List(RealtyListing(2104.0,5,1,45,460.0), RealtyListing(1416.0,3,2,40,232.0), RealtyListing(1534.0,3,2,30,315.0), RealtyListing(852.0,2,1,36,178.0))

Create a price estimator using linear regression.

import cats.implicits._
// import cats.implicits._

import spire.implicits.DoubleAlgebra
// import spire.implicits.DoubleAlgebra

import axle.jblas._
// import axle.jblas._

implicit val laJblasDouble = axle.jblas.linearAlgebraDoubleMatrix[Double]
// laJblasDouble: axle.algebra.LinearAlgebra[org.jblas.DoubleMatrix,Int,Int,Double] = axle.jblas.package$$anon$7@69c0b840

import axle.ml.LinearRegression
// import axle.ml.LinearRegression

val priceEstimator = LinearRegression(
  listings,
  numFeatures = 4,
  featureExtractor = (rl: RealtyListing) => (rl.size :: rl.bedrooms.toDouble :: rl.floors.toDouble :: rl.age.toDouble :: Nil),
  objectiveExtractor = (rl: RealtyListing) => rl.price,
  α = 0.1,
  iterations = 100)
// priceEstimator: axle.ml.LinearRegression[RealtyListing,org.jblas.DoubleMatrix] = <function1>

Use the estimator

priceEstimator(RealtyListing(1416, 3, 2, 40, 0d))
// res0: Double = 288.60017635814035

Plot the error during the training

import spire.implicits._
// import spire.implicits._

import axle.visualize._
// import axle.visualize._

import axle.algebra.Plottable._
// import axle.algebra.Plottable._

import axle.eqTreeMap
// import axle.eqTreeMap

val errorPlot = Plot(
  () => List(("error" -> priceEstimator.errTree)),
  connect = true,
  drawKey = true,
  colorOf = (label: String) => Color.black,
  title = Some("Linear Regression Error"),
  xAxis = Some(0d),
  xAxisLabel = Some("step"),
  yAxis = Some(0),
  yAxisLabel = Some("error"))
// errorPlot: axle.visualize.Plot[String,Int,Double,scala.collection.immutable.TreeMap[Int,Double]] = Plot(<function0>,true,true,700,600,50,4,20,50,80,Courier New,12,false,Palatino,20,<function1>,Some(Linear Regression Error),None,Some(0.0),Some(step),Some(0),Some(error))

import axle.web._
// import axle.web._

svg(errorPlot, "lrerror.svg")

lr error