资源简介
svm-simple.py(matplotlib)
代码片段和文件信息
# -*- coding:UTF-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import random
“““
函数说明:读取数据
Parameters:
fileName - 文件名
Returns:
dataMat - 数据矩阵
labelMat - 数据标签
Author:
Jack Cui
Blog:
http://blog.csdn.net/c406495762
Zhihu:
https://www.zhihu.com/people/Jack--Cui/
Modify:
2017-09-21
“““
def loadDataSet(fileName):
dataMat = []; labelMat = []
fr = open(fileName)
for line in fr.readlines(): #逐行读取,滤除空格等
lineArr = line.strip().split(‘\t‘)
dataMat.append([float(lineArr[0]) float(lineArr[1])]) #添加数据
labelMat.append(float(lineArr[2])) #添加标签
return dataMatlabelMat
“““
函数说明:随机选择alpha
Parameters:
i - alpha_i的索引值
m - alpha参数个数
Returns:
j - alpha_j的索引值
Author:
Jack Cui
Blog:
http://blog.csdn.net/c406495762
Zhihu:
https://www.zhihu.com/people/Jack--Cui/
Modify:
2017-09-21
“““
def selectJrand(i m):
j = i #选择一个不等于i的j
while (
- 上一篇:python数据分析与处理
- 下一篇:使用模块与库编程2.pptx 教程
评论
共有 条评论