Skip to main content

logisticTrain

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

logisticTrain component is used to train the logistic regression model on 3 parameters and saves the learnt parameters in trainedValues.txt file.

  • Description : logisticTrain() takes an input(through STDIN) as .csv file and column name 1, column name 2 and column name 3 with values, which we train using logistic regression algorithm and trained parameters are stored in .txt file for further use. Check Input and output parameters for details.
  • Parameters :
    • Input(Via STDIN) : A JSON String with following contents:
      • Input1 : .csv file name (which container 2 columns with values)
      • Input2 : column1 name
      • Input3 : column2 name
      • Input4 : column3 name
    • Output(Via STDOUT) : A JSON string with following contents
      • trainedValues.txt file which contains trained values i.e. the model

List of logisticTrain features in shunya stack

  1. logisticTrain component train the logistic-regression model on csv file and stored the trained values in .txt file.

Using logisticTrain features in Shunya stack

1. Getting trained values after linear-regression using logisticTrain component

  • logisticTrain give trainedValues.txt which contains predicted values.

Lets look into code to understand how to output.

C++

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

with above c++ program, you will get trainedValues.txt file stored in your system, which has trained values.

Python

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

with above python program, you will get trainedValues.txt file stored in your system, which has trained 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?