In [2]:
import pandas as pd
import numpy as np
import joblib
from sklearn.svm import SVC
from sklearn.cross_validation import train_test_split
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
In [3]:
data = pd.read_csv("data/driver_image.csv")
data = data.ix[:,1:]
X_data = data.ix[:,:-1]
y_data = data.ix[:,-1]
X_train, X_test, y_train, y_test = train_test_split(X_data, y_data, test_size=0.25)
In [ ]:
%%time
svc_linear = SVC(kernel='linear').fit(X_train, y_train)
In [4]:
joblib.dump(svc_linear, "model/svc_linear") #save model
In [5]:
svc_linear = joblib.load("model/svc_linear")
In [6]:
%%time
linear_predict = svc_linear.predict(X_test)
In [7]:
print(classification_report(y_test, linear_predict))
In [8]:
confusion_matrix(y_test, linear_predict)
Out[8]:
In [9]:
sum(y_test != linear_predict)
Out[9]:
In [ ]:
from sklearn.svm import SVC
In [36]:
%%time
svc_rbf = SVC(kernel='rbf', gamma=0.00000009).fit(X_train, y_train)
In [37]:
joblib.dump(svc_rbf, "model/svc_rbf") #save model
Out[37]:
In [10]:
svc_rbf = joblib.load("model/svc_rbf")
In [11]:
%%time
rbf_predict = svc_rbf.predict(X_test)
In [12]:
print(classification_report(y_test, rbf_predict))
In [13]:
confusion_matrix(y_test, rbf_predict)
Out[13]:
In [14]:
sum(y_test != rbf_predict)
Out[14]:
In [ ]: