Extracting weights from linear regression model

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting weights from linear regression model

Trevor Grant
Sorry if this is a novice question, but I can't figure out how to extract the weights vector from a multiple linear regression model.  I can fit/predict, but I can't get the weight vector.

Any advice would be appreciated (even snide go read the docs comments, so long as they point me to applicable docs, because I've been struggling with this all day).

Thanks!
tg


Trevor Grant
Data Scientist

"Fortunate is he, who is able to know the causes of things."  -Virgil

Reply | Threaded
Open this post in threaded view
|

Re: Extracting weights from linear regression model

Theodore Vasiloudis
Hello Trevor,

I assume you using the MultipleLinearRegression class in a manner similar to our examples, i.e.:

// Create multiple linear regression learner
val mlr = MultipleLinearRegression()
.setIterations(10)
.setStepsize(0.5)
.setConvergenceThreshold(0.001)

// Obtain training and testing data set
val trainingDS: DataSet[LabeledVector] = ...
val testingDS: DataSet[Vector] = ...

// Fit the linear model to the provided data
mlr.fit(trainingDS)

After you've run the fit method, you can get the weights by calling:

val WeightVector(weights, intercept) = mlr.weightsOption.get.collect().head

weights should be a flink.ml.math.DenseVector object and the intercept a Double.

Regards,
Theodore



On Wed, Oct 7, 2015 at 10:52 PM, Trevor Grant <[hidden email]> wrote:
Sorry if this is a novice question, but I can't figure out how to extract the weights vector from a multiple linear regression model.  I can fit/predict, but I can't get the weight vector.

Any advice would be appreciated (even snide go read the docs comments, so long as they point me to applicable docs, because I've been struggling with this all day).

Thanks!
tg


Trevor Grant
Data Scientist

"Fortunate is he, who is able to know the causes of things."  -Virgil