openGPMP
Open Source Mathematics Package
logreg.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  *
3  * Project
4  * _____ _____ __ __ _____
5  * / ____| __ \| \/ | __ \
6  * ___ _ __ ___ _ __ | | __| |__) | \ / | |__) |
7  * / _ \| '_ \ / _ \ '_ \| | |_ | ___/| |\/| | ___/
8  *| (_) | |_) | __/ | | | |__| | | | | | | |
9  * \___/| .__/ \___|_| |_|\_____|_| |_| |_|_|
10  * | |
11  * |_|
12  *
13  * Copyright (C) Akiel Aries, <akiel@akiel.org>, et al.
14  *
15  * This software is licensed as described in the file LICENSE, which
16  * you should have received as part of this distribution. The terms
17  * among other details are referenced in the official documentation
18  * seen here : https://akielaries.github.io/openGPMP/ along with
19  * important files seen in this project.
20  *
21  * You may opt to use, copy, modify, merge, publish, distribute
22  * and/or sell copies of the Software, and permit persons to whom
23  * the Software is furnished to do so, under the terms of the
24  * LICENSE file. As this is an Open Source effort, all implementations
25  * must be of the same methodology.
26  *
27  *
28  *
29  * This software is distributed on an AS IS basis, WITHOUT
30  * WARRANTY OF ANY KIND, either express or implied.
31  *
32  ************************************************************************/
33 
39 #ifndef LOGREG_hpp
40 #define LOGREG_hpp
41 
42 #include <string>
43 #include <vector>
44 
45 namespace gpmp {
46 
47 namespace ml {
48 
53 class LogReg {
54  public:
63  LogReg(double l_rate = 001, int num_iters = 1000, double lda = 001);
64 
68  ~LogReg();
69 
75  void train(const std::vector<std::vector<double>> &X_train,
76  const std::vector<int> &y_train);
77 
83  std::vector<int> classify(const std::vector<std::vector<double>> &X);
84 
90  std::vector<double> predict(const std::vector<std::vector<double>> &X_test);
91 
98  double accuracy(const std::vector<std::vector<double>> &X_test,
99  const std::vector<int> &y_test);
100 
105  void feature_scaling(std::vector<std::vector<double>> &X);
106 
107  double learning_rate;
110  double lambda;
111  std::vector<double>
119  double sigmoid(double z);
120 
128  double cost_function(const std::vector<std::vector<double>> &X,
129  const std::vector<int> &y);
130 };
131 
132 } // namespace ml
133 
134 } // namespace gpmp
135 #endif
Represents a Logistic Regression classifier.
Definition: logreg.hpp:53
std::vector< double > weights
Definition: logreg.hpp:112
double sigmoid(double z)
Computes the sigmoid function value for the given input.
Definition: logreg.cpp:112
std::vector< int > classify(const std::vector< std::vector< double >> &X)
Predicts the class labels for the given test data.
Definition: logreg.cpp:164
std::vector< double > predict(const std::vector< std::vector< double >> &X_test)
Computes the predicted probabilities for the given test data.
Definition: logreg.cpp:81
~LogReg()
Destructor for the LogReg class.
Definition: logreg.cpp:44
double learning_rate
Definition: logreg.hpp:107
double accuracy(const std::vector< std::vector< double >> &X_test, const std::vector< int > &y_test)
Computes the accuracy of the model on the given test data.
Definition: logreg.cpp:99
LogReg(double l_rate=001, int num_iters=1000, double lda=001)
Constructor for the LogReg class.
Definition: logreg.cpp:40
void train(const std::vector< std::vector< double >> &X_train, const std::vector< int > &y_train)
Trains the logistic regression model on the given training data.
Definition: logreg.cpp:47
double cost_function(const std::vector< std::vector< double >> &X, const std::vector< int > &y)
Computes the cost function value for the given input data and labels.
Definition: logreg.cpp:145
void feature_scaling(std::vector< std::vector< double >> &X)
Performs feature scaling on the input feature matrix.
Definition: logreg.cpp:116
The source C++ openGPMP namespace.