# Method 1 : SVM (Support Vector Machine)
from sklearn.svm import LinearSVC, SVC
svm = LinearSVC(class_weight='balanced', random_state=42, loss="hinge", fit_intercept=False)
svm_alternative = SVC(kernel='linear', gamma=.5, probability=True) # Alternative 1
# in contrast to scikit-learn's LinearSVC, Snap ML offers multi-threaded CPU/GPU training of SVMs
from snapml import SupportVectorMachine
snapml_svm_cpu = SupportVectorMachine(class_weight='balanced', n_jobs=4, fit_intercept=False) # Alternative 2
snapml_svm_gpu = SupportVectorMachine(class_weight='balanced', use_gpu=True, fit_intercept=False) # Alternative 3
# Method 2 : SGD (Stochastic Gradient Descent)
from sklearn.linear_model import SGDClassifier
sgd = SGDClassifier(loss='hinge', class_weight='balanced', random_state=42, fit_intercept=False)
# Measure training time
t0 = time.time()
model.fit(X_train, y_train)
train_time = time.time() - t0
# Predict
y_pred = model.predict(X_test)
# Evaluate model
roc_auc_score(y_test, y_pred)
# Get confidence score for probability
y_pred_conf = model.decision_function(X_test)
# Evaluate hinge loss
hinge_loss(y_test, y_pred_conf)
# See index of support vectors in X
svm.support_
# Fetch support vector points from training set (Training with only support will yield same model)
X_small = X[svm.support_]
y_small = y[svm.support_]