sklearn svm
生活随笔
收集整理的這篇文章主要介紹了
sklearn svm
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 88return f(*args, **kwds)
復制代碼 data = pd.read_csv("credit-a.csv", header=None)
復制代碼data.head(2)
復制代碼
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 88return 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
復制代碼
| 0 | 30.83 | 0.00 | 0 | 0 | 9 | 0 | 1.25 | 0 | 0 | 1 | 1 | 0 | 202 | 0.0 | -1 |
| 1 | 58.67 | 4.46 | 0 | 0 | 8 | 1 | 3.04 | 0 | 0 | 6 | 1 | 0 | 43 | 560.0 | -1 |
總結
以上是生活随笔為你收集整理的sklearn svm的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android开发者必备:推荐一款助力开
- 下一篇: 如何基于OceanBase构建应用和数据