Created
June 9, 2020 13:40
-
-
Save marketneutral/40b931b32998cc12fad4206ac67bf779 to your computer and use it in GitHub Desktop.
Parallel Predict for ML Estimator
This file contains 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 joblib import Parallel, delayed | |
from sklearn import svm | |
data_train = [[0,2,3],[1,2,3],[4,2,3]] | |
targets_train = [0,1,0] | |
clf = svm.SVC(kernel='rbf', degree=3, C=10, gamma=0.3, probability=True) | |
clf.fit(data_train, targets_train) | |
to_be_predicted = np.array([[1,3,4], [1,3,4], [1,3,5]]) | |
clf.predict(to_be_predicted) | |
n_cores = 3 | |
parallel = Parallel(n_jobs=n_cores) | |
results = parallel(delayed(clf.predict)(to_be_predicted[i].reshape(-1,3)) for i in range(n_cores)) | |
np.vstack(results).flatten() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment