GithubHelp home page GithubHelp logo

Comments (3)

Alexsandruss avatar Alexsandruss commented on July 17, 2024

This is expected behavior for now. Warning for n_iter_ property might be added.

max_iter = 10000 if self.max_iter == -1 else self.max_iter
# TODO: remove this workaround
# when oneDAL SVM starts support of 'n_iterations' result
self.n_iter_ = 1 if max_iter < 1 else max_iter

from scikit-learn-intelex.

caspimoshe avatar caspimoshe commented on July 17, 2024

This is expected behavior for now. Warning for n_iter_ property might be added.

max_iter = 10000 if self.max_iter == -1 else self.max_iter
# TODO: remove this workaround
# when oneDAL SVM starts support of 'n_iterations' result
self.n_iter_ = 1 if max_iter < 1 else max_iter

Thanks for the fast response, Alex.
My main issue is that the max_iter parameter seem to have no effect.

Attaching code that shows it:
With patch the code ran for -0.84 seconds and managed to fit the data
`import time

import numpy as np
from sklearnex import patch_sklearn

patch_sklearn()
from sklearn.svm import SVR

patch_svr = SVR(max_iter=2)
np.random.seed(0)
X = np.random.randn(int(1e5), 5)
y = np.mean(X, axis=1)

tic = time.time()
patch_svr.fit(X, y)
print("Time to fit SVR with patch:", time.time() - tic)

score = patch_svr.score(X, y)
print("Score:", score)`
image

Without the patch the model terminated early, after 0.34 seconds and did not fit the data
`import time

import numpy as np
from sklearnex import patch_sklearn

patch_sklearn()
from sklearn.svm import SVR

patch_svr = SVR(max_iter=2)
np.random.seed(0)
X = np.random.randn(int(1e5), 5)
y = np.mean(X, axis=1)

tic = time.time()
patch_svr.fit(X, y)
print("Time to fit SVR with patch:", time.time() - tic)

score = patch_svr.score(X, y)
print("Score:", score)`
image

from scikit-learn-intelex.

Alexsandruss avatar Alexsandruss commented on July 17, 2024

sklearn and sklearnex use different implementations of SVM, thus, different behavior on same number of iterations it expected.
SVM algorithm stopping is controlled by two parameters: maximum number of iterations (max_iter) and threshold/tolerance for stopping criterion (tol). sklearnex SVM might stop in same point while max_iters (>= stopping point) are widely different due to trigger of stopping criterion. Because of previously mentioned workaround it's impossible to know how many iterations were performed. If tol is significantly close to 0 (for example, 1e-32), stopping criterion would be unreachable and SVM training time becomes strictly proportional to max_iter.

from scikit-learn-intelex.

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.