资源简介
支持向量机(support vector machine,简称SVM)于1964年由Vapnik和Chervonenkis建立,在上世纪90年代获得快速发展并衍生出一系列改进和扩展算法,在人像识别、文本分类、手写字识别及生物信息学等领域获得广泛应用。
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Tue May 7 17:17:22 2019
@author: wwc
“““
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.samples_generator import make_blobs
class SMO(object):
def __init__(self C = 100 toler = 0.001 maxIter = 10000):
self.C = C
self.tol = toler
self.maxIter = maxIter
def fit(self X y):
self.X self.y = X y
self.n_samples = len(X)
self.alphas = np.zeros(self.n_samples dtype = float)
self.b = 0.
self.Error = np.zeros_like(self.alphas)
self.iterNum = 0
iterNum = 0
examineAll = True
alphaChanged = 0
while iterNum < self.maxIter and (alphaChanged > 0 or examineAll == True):
alphaChanged = 0
if examineAll:
for i in range(len(self.X)): alphaChanged += self._innerLoop(i)
iterNum += 1
examineAll = False
评论
共有 条评论