Git Product home page Git Product logo

Comments (6)

cjlin1 avatar cjlin1 commented on August 17, 2024

from libsvm.

lzm42 avatar lzm42 commented on August 17, 2024

from sklearn.datasets import laod_wine,load_breast_cancer. I deleted the target columns of two datasets and standardized them

from libsvm.

cjlin1 avatar cjlin1 commented on August 17, 2024

Could you show us your code?

from libsvm.

lzm42 avatar lzm42 commented on August 17, 2024

about what?Cpp code?

#include <svm.h>
#include <iostream>

class OneClassSvm2
{
public:
        OneClassSvm2(string kernel, double nu, double gamma, double c);
        ~OneClassSvm2();
        int getKernelType(string type);
        void train(std::vector<svm_node*> data);
        void predict(std::vector<svm_node*> data);

private:
        int _kernel;
        double _nu;
        double _gamma;
        double _C;
        svm_model* model;
};


OneClassSvm2::OneClassSvm2(string kernel="rbf", double nu=0.5, double gamma=0.5, double c=1.0) {
    this->_kernel = this->getKernelType(kernel);
    this->_nu = nu;
    this->_gamma = gamma;
    this->_C = c;
    this->model = nullptr;
}

OneClassSvm2::~OneClassSvm2() {
    if (this->model != nullptr) {
        svm_free_and_destroy_model(&this->model);
    }
}

int OneClassSvm2::getKernelType(string type) {
    if (type == "rbf") {
        return RBF;
    }
    else if (type == "linear") {
        return LINEAR;
    }
    else if (type == "poly") {
        return POLY;
    }
    else if (type == "sigmoid") {
        return SIGMOID;
    }
}

void OneClassSvm2::train(std::vector<svm_node*> data) {
    try {
        int label_len = data.size();
        std::vector<double> labels;
        svm_parameter param;
        param.svm_type = ONE_CLASS;
        param.kernel_type = this->_kernel;
        param.nu = this->_nu;
        param.gamma = this->_gamma;
        param.C = this->_C;
        param.eps = 1e-6;

        svm_problem prob;

        for (int i = 0; i < label_len; i++) {
            labels.push_back(1);
        }

        prob.l = label_len;
        prob.y = labels.data();
        prob.x = data.data();


        this->model = svm_train(&prob, &param);
    }
    catch (const std::exception &e) {
        cout << "训练异常:" << e.what() << endl;
    }
}

void OneClassSvm2::predict(std::vector<svm_node*> data) {
    vector<double> result;
    try {
        for (auto value : data) {
            double predicted_label = svm_predict(model, value);
            result.push_back(predicted_label);
            std::cout << " " << predicted_label;
        }
        cout << "结果大小:" << result.size() << endl;
    }
    catch (const std::exception& e) {
        cout << "预测异常:" << e.what() << endl;
    }
}

When we examine the code, we find that there are no suitable parameters to control the iteration

from libsvm.

cjlin1 avatar cjlin1 commented on August 17, 2024

from libsvm.

lzm42 avatar lzm42 commented on August 17, 2024

We only need data and parameters to reproduce it. We did not make any changes to the code, it was just a simple call, so there are no relevant logs

from libsvm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.