From 8ea6e83f428a2248d01f052c57e6e60e3fb63503 Mon Sep 17 00:00:00 2001 From: Muhammed Hamza Tokat Date: Tue, 21 Oct 2025 15:48:23 +0300 Subject: [PATCH] Added SVM example implementation --- svm.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 svm.cpp diff --git a/svm.cpp b/svm.cpp new file mode 100644 index 0000000000..7372d669e2 --- /dev/null +++ b/svm.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +using namespace std; + +// Basit bir linear SVM örneği (öğrenme yok, sadece mantık gösterimi) +class SVM +{ +public: + vector weights; + double bias; + + SVM() + { + weights = {0.5, -0.3}; + bias = 0.1; + } + + int predict(vector x) + { + double sum = bias; + for (int i = 0; i < x.size(); i++) + sum += x[i] * weights[i]; + return sum >= 0 ? 1 : -1; + } +}; + +int main() +{ + SVM model; + vector> data = {{1, 2}, {-1, -2}, {2, 3}, {-2, -3}}; + for (auto &x : data) + { + cout << "Prediction for (" << x[0] << ", " << x[1] << "): " + << model.predict(x) << endl; + } + return 0; +}