openGPMP
Open Source Mathematics Package
kfold.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 
34 #ifndef KFOLD_HPP
35 #define KFOLD_HPP
36 
37 #include <functional>
38 #include <vector>
39 
40 namespace gpmp {
41 
42 namespace ml {
43 
48 class Kfold {
49  public:
54  Kfold(int k);
55 
59  ~Kfold();
60 
66  void split_indices(int num_instances);
67 
77  void
78  perform_cross_validation(std::function<void(int, int)> train_and_test_func);
79 
80  private:
82  int k;
84  std::vector<std::vector<int>> fold_indices;
85 };
86 } // namespace ml
87 
88 } // namespace gpmp
89 
90 #endif
Represents a k-fold cross-validation utility.
Definition: kfold.hpp:48
std::vector< std::vector< int > > fold_indices
Definition: kfold.hpp:84
void split_indices(int num_instances)
Splits the indices of instances into k folds for cross-validation.
Definition: kfold.cpp:45
~Kfold()
Destructor for the Kfold class.
Definition: kfold.cpp:42
Kfold(int k)
Constructor for the Kfold class.
Definition: kfold.cpp:39
void perform_cross_validation(std::function< void(int, int)> train_and_test_func)
Performs k-fold cross-validation using the provided training and testing function.
Definition: kfold.cpp:68
The source C++ openGPMP namespace.