February 2018
Intermediate to advanced
378 pages
10h 14m
English
The gradient descent for multiple linear regression can be calculated as follows:
// derivative of a cost function private func costGradient(trueVec: [Double], predictedVec: [Double], xMatFlattened: [Double]) -> [Double] { let matCount = xMatFlattened.count let featureCount = weights.count precondition(matCount > 0) precondition(Double(matCount).truncatingRemainder(dividingBy: Double(featureCount)) == 0) let sampleCount = trueVec.count precondition(sampleCount > 0) precondition(sampleCount*featureCount == matCount) let labelSize = 1 let diffVec = vecSubtract(predictedVec, trueVec) // Normalize by vector length. let scaleBy = 1/Double(sampleCount) let result = gemm(aMat: xMatFlattened, bMat: ...Read now
Unlock full access