71 void fit(
const std::vector<std::vector<double>> &X_train,
72 const std::vector<int> &y_train);
79 std::vector<int>
predict(
const std::vector<std::vector<double>> &X_test);
87 predict_proba(
const std::vector<std::vector<double>> &X_test);
95 double score(
const std::vector<std::vector<double>> &X_test,
96 const std::vector<int> &y_test);
136 const std::vector<int> &y,
148 std::vector<double>
grid_search(
const std::vector<std::vector<double>> &X,
149 const std::vector<int> &y,
150 const std::vector<double> &C_values,
151 const std::vector<double> &kernel_params,
183 double hinge_loss(
double prediction,
int label);
191 double compute_loss(
const std::vector<std::vector<double>> &X,
192 const std::vector<int> &y);
200 const std::vector<int> &y);
208 double kernel(
const std::vector<double> &x1,
const std::vector<double> &x2);
217 const std::vector<double> &x2);
240 double accuracy(
const std::vector<int> &predictions,
241 const std::vector<int> &labels);
Support Vector Classifier (SVC) for binary classification using Stochastic Gradient Descent.
void set_random_state(int seed)
Set the random seed for reproducibility.
double dot_product(const std::vector< double > &x1, const std::vector< double > &x2)
Compute the dot product between two vectors.
SVC(double C_=1.0, double l_rate=0.01, int max_iters=1000, double tol=1e-4)
Constructor for SVC class.
void set_verbose(bool vbose)
Enable or disable verbose output during training.
void set_kernel(const std::string &k_type)
Set the kernel type for the SVC.
double score(const std::vector< std::vector< double >> &X_test, const std::vector< int > &y_test)
Calculate the accuracy of the model on given test data.
std::vector< double > predict_proba(const std::vector< std::vector< double >> &X_test)
Predict class probabilities for given test data.
void update_weights(const std::vector< std::vector< double >> &X, const std::vector< int > &y)
Update weights and bias using stochastic gradient descent.
std::vector< int > k_fold_indices(int num_instances, int k)
Generate k-fold indices for cross-validation.
std::vector< double > weights
double sigmoid(double z)
Sigmoid activation function.
void fit(const std::vector< std::vector< double >> &X_train, const std::vector< int > &y_train)
Fit the SVC model to the training data.
double cross_val_score(const std::vector< std::vector< double >> &X, const std::vector< int > &y, int cv=5)
Perform k-fold cross-validation on the model.
void set_kernel_parameters(double k_param)
Set the kernel parameters for the SVC.
void set_penalty(const std::string &p_type)
Set the penalty type for regularization.
double kernel(const std::vector< double > &x1, const std::vector< double > &x2)
Compute the kernel function between two vectors.
double hinge_loss(double prediction, int label)
Compute the hinge loss for a given prediction and true label.
double accuracy(const std::vector< int > &predictions, const std::vector< int > &labels)
Compute the accuracy of predictions.
std::vector< double > grid_search(const std::vector< std::vector< double >> &X, const std::vector< int > &y, const std::vector< double > &C_values, const std::vector< double > &kernel_params, int cv=5)
Perform grid search for hyperparameter tuning.
std::vector< int > predict(const std::vector< std::vector< double >> &X_test)
Predict labels for given test data.
double compute_loss(const std::vector< std::vector< double >> &X, const std::vector< int > &y)
Compute the total loss (including regularization) for the model.
The source C++ openGPMP namespace.