Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Bagging Classifier with a support vector machine model

When I am trying to execute

svm = SVC(gamma='auto',random_state = 42,probability=True)
BaggingClassifier(base_estimator=svm, n_estimators=31, random_state=314).fit(X,y)

It runs indefinitely. Is the command causing the computation to occur at a very slow pace or am I doing it the wrong way?

like image 764
Basileus Avatar asked Oct 28 '22 00:10

Basileus


1 Answers

You are using it correctly. SVC is just super slow. Here is how you can check that:

from sklearn.svm import LinearSVC
from sklearn.ensemble import BaggingClassifier
import hasy_tools  # pip install hasy_tools

# Load and preprocess data
data = hasy_tools.load_data()
X = data['x_train']
X = hasy_tools.preprocess(X)
X = X.reshape(len(X), -1)
y = data['y_train']

# Reduce dataset
dataset_size = 100
X = X[:dataset_size]
y = y[:dataset_size]

# Define model
svm = LinearSVC(random_state=42)
model = BaggingClassifier(base_estimator=svm, n_estimators=31, random_state=314)

# Fit
model.fit(X, y)

More details on why SVC is slow can be found on datascience.SE.

like image 58
Martin Thoma Avatar answered Nov 15 '22 05:11

Martin Thoma