[mlpack] How to do linear regression?

Jason Liu liuj03 at gmail.com
Tue Jun 12 11:46:09 EDT 2018


Hi,

I copy-pasted some code from mlpack doc

#include <mlpack/methods/linear_regression/linear_regression.hpp>

#include <mlpack/core.hpp>

#include <armadillo>

#include <iostream>


using namespace mlpack::regression;

using namespace std;


int main(int argc, char *argv[]) {


    //The dataset itself.

    arma::mat data;

    data<<1.0<<arma::endr

        <<2.0<<arma::endr

        <<3.0<<arma::endr

        <<4.0<<arma::endr

        <<5.0<<arma::endr;

    cout<<data<<endl;


    //The responses, one row for each row in data.

    arma::vec responses;

    responses<<1.0<<arma::endr

             <<2.0<<arma::endr

             <<3.0<<arma::endr

             <<4.0<<arma::endr

             <<5.0<<arma::endr;

    cout<<responses<<endl;


    //Regress.

    LinearRegression lr(data, responses);


    //Get the parameters, or coefficients.

    arma::vec parameters = lr.Parameters();


    cout << parameters << endl;

    return 0;

}


Unfortunately it gives me


error: Mat::init(): requested size is not compatible with row vector layout

The exception was thrown at the LinearRegression ctor.

What does the error message mean?

What did I do wrong?


Thanks.



Kind Regards

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://knife.lugatgt.org/pipermail/mlpack/attachments/20180612/94901499/attachment.html>


More information about the mlpack mailing list