The document is a continuation of the previous document, if you have landed directly on this page then, Please read from page Get started.

What is linearPredict component ?#

linearPredict component is used to perform the linear regression prediction i.e. it takes testset.csv as an input which has one column(e.g. x) with values and as an output it gives output.csv file which has column with predicted values.

  • Description : linearPredict() takes an input(through STDIN) as .csv file and column name 1 and column name 2 where column1 has values and column2 is empty but which values will be predicted. Check Input and output parameters for details.
  • Parameters :
    • Input(Via STDIN) : A JSON String with following contents:
      • Input1 : .csv file name (which container 1 column with values)
      • Input2 : column1 name (column which present in above .csv file)
      • Input3 : column2 name (which will get stored in output.csv file with predicted output)
    • Output(Via STDOUT) : A JSON string with following contents
      • output.csv file gets stored.

List of linearPredict features in shunya stack#

  1. linearPredict component predicts the y column value when given x columns using linear regression.

Using linearPredict features in Shunya stack#

1. Getting prediction using linearPredict component#

  • linearPredicts give output.csv which contains predicted values.

Lets look into code to understand how to output.


// call linearPredict API
subprocess::popen linearTrain("/usr/bin/linearPredict", {});
linearPredict.stdin() << jsonDoc2Text(inputJson) << std::endl;
std::string linearPredictOut;
// Get output from STDOUT
linearPredict.stdout() >> linearPredictOut;

with above c++ program, you will get output.csv file stored in your system, which has predicted values.


# calling linearPredict API
linearPredict = Popen(['/usr/bin/linearPredict'], stdout=PIPE, stdin=PIPE)
# Passing input to STDIN and getting an output from STDOUT
linearPredictOut = linearPredict.communicate(input=inputJson1_data.encode('utf-8'))[0]

with above python program, you will get output.csv file stored in your system, which has predicted values.

Understand this component with an example (ready to use code)#

  • This is an example for linear-regression, training and prediction here we will be using 2 components: linearTrain and linearPredict
  • Check this ready to use example in c++ and python
  • C++ Example
    git clone
    cd shunya-ai-examples/ml-examples/cpp-examples/linear-reg
  • In this folder there is a file, linear-reg.cpp
  • linearTrain Components used
    subprocess::popen linearTrain("/usr/bin/linearTrain", {});
  • linearPredict component used
    subprocess::popen linearPredict("/usr/bin/linearPredict", {});
  • Run code by yourself
    mkdir build && cd build
    cmake .. && make
    • You will get a new file store in system i.e. output.csv with predicted values.

Facing errors with the component?#