import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
/anaconda3/envs/py35/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
data = pd.read_csv("credit-a.csv", header=None)
data.head(2)
|
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
| 0 |
0 |
30.83 |
0.00 |
0 |
0 |
9 |
0 |
1.25 |
0 |
0 |
1 |
1 |
0 |
202 |
0.0 |
-1 |
| 1 |
1 |
58.67 |
4.46 |
0 |
0 |
8 |
1 |
3.04 |
0 |
0 |
6 |
1 |
0 |
43 |
560.0 |
-1 |
from sklearn.model_selection import train_test_split
x = data[data.columns[:-1]]
y = data[15].replace(-1, 0)
x_train, x_test, y_train, y_test = train_test_split(x, y)
from sklearn import preprocessing
scaler = preprocessing.StandardScaler().fit(x_train)
x_train = scaler.transform(x_train)
x_test = scaler.transform(x_test)
from sklearn.svm import SVC
/anaconda3/envs/py35/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
model = SVC(kernel='poly', degree=3, C=5)
model.fit(x_train, y_train)
SVC(C=5, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovr', degree=3, gamma='auto', kernel='poly',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
model.score(x_test, y_test)
0.8597560975609756
model2 = SVC(kernel='rbf', gamma=0.5, C=5)
model2.fit(x_train, y_train)
SVC(C=5, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovr', degree=3, gamma=0.5, kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
model2.score(x_test, y_test)
0.8170731707317073