Example #1
0
#standard imports from numpy, scikit-learn and matplotlib
import numpy as np
from time import time
import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
from sklearn import svm, pipeline
from sklearn.svm import LinearSVC
from sklearn.kernel_approximation import (RBFSampler, Nystroem)
from sklearn.preprocessing import StandardScaler
# implementations of the proposed feature maps
import FeatureMaps as maps
# data reading module
import DataReader as DR

#get the dataset
X_train, X_test, y_train, y_test = DR.Magic()

#scale the dataset
scaler = StandardScaler()
X_train = scaler.fit_transform(X_train)
X_test = scaler.transform(X_test)

#exact rbf performance
start = time()
rbf_clf = svm.SVC(C=1, kernel='rbf', gamma=0.2).fit(X_train, y_train)
rbf_time = (time() - start)
rbf_score = accuracy_score(y_test, rbf_clf.predict(X_test))

#linear performance
start = time()
linear_clf = LinearSVC(C=1, dual=False).fit(X_train, y_train)