Created
March 13, 2019 18:45
-
-
Save bkj/544020f3dd93ca18c2ea18a8cd746637 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process | |
from time import time | |
import numpy as np | |
from exline.helpers import with_timeout | |
from sklearn.svm import SVC | |
def __SVC_fit(model, X, y, out): | |
out['result'] = model.fit(X, y) | |
def SVC_fit(model, X, y, timeout=5): | |
manager = multiprocessing.Manager() | |
out = manager.dict() | |
p = Process(target=__SVC_fit, args=(model, X, y, out), kwargs=kwargs) | |
p.start() | |
p.join(timeout=timeout) | |
if not p.is_alive(): | |
return out['result'] | |
else: | |
print('SVC_fit: timeout', file=sys.stderr) | |
p.terminate() | |
return None | |
model = SVC(C=1000) | |
np.random.seed(123) | |
X = np.random.uniform(0, 1, (10000, 2)) | |
y = np.random.choice((0, 1), 10000) | |
t = time() | |
model = model.fit(X, y) | |
time() - t | |
model.decision_function(X).sum() | |
model = SVC(C=1000) | |
np.random.seed(123) | |
X = np.random.uniform(0, 1, (100000, 2)) | |
y = np.random.choice((0, 1), 100000) | |
t = time() | |
model = SVC_fit(model, X, y) | |
time() - t | |
model.decision_function(X).sum() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment