Skip to main content

logisticPredict

warning

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 logisticPredict component ?

logisticPredict component is used to perform the linear regression prediction i.e. it takes testset.csv as an input which has two columns(e.g. x1 and x2) with values and as an output it gives output.csv file which has column with predicted values(e.g. y).

  • Description : logisticPredict() takes an input(through STDIN) as .csv file and column name 1 and column name 2 and column name 3 where column1 and column2 has values and column3 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 (column which present in above .csv file)
      • Input3 : column3 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 logisticPredict features in shunya stack

  1. logisticPredict component predicts the y column value when given x1 and x2 columns using logistic regression.

Using logisticPredict features in Shunya stack

1. Getting prediction using logisticPredict component

  • logisticPredict give output.csv which contains predicted values.

Lets look into code to understand how to output.

C++

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

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

Python

# calling logisticPredict API
logisticPredict = Popen(['/usr/bin/logisticPredict'], stdout=PIPE, stdin=PIPE)
# Passing input to STDIN and getting an output from STDOUT
logisticPredictOut = logisticPredict.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 logistic-regression training and prediction and here we will be using 2 components: logisticTrain and logisticPredict
  • Check this ready to use example in c++ and python
  • C++ Example
    git clone https://gitlab.iotiot.in/shunya/products/shunya-ai-examples.git
    cd shunya-ai-examples/ml-examples/cpp-examples/logistic-reg
  • In this folder there is a file, logistic-reg.cpp
  • logisticTrain Components used
    subprocess::popen logisticTrain("/usr/bin/logisticTrain", {});
  • logisticPredict component used
     subprocess::popen logisticPredict("/usr/bin/logisticPredict", {});
  • Run code by yourself
    mkdir build && cd build
    cmake .. && make
    ./logisticRegCpp
    • You will get a new file store in system i.e. output.csv with predicted values.

Facing errors with the component?