资源简介
SVM算法的代码,用pyhon实现的,可直接用,很方便,下载即可用!该算法可用于机器学习分类研究,是一种典型的分类算法,非常适合论文实验。

代码片段和文件信息
#!/usr/bin/env python
from __future__ import print_function
import sys
try:
import scipy
from scipy import sparse
except:
scipy = None
sparse = None
__all__ = [‘svm_read_problem‘ ‘evaluations‘ ‘csr_find_scale_param‘ ‘csr_scale‘]
def svm_read_problem(data_file_name return_scipy=False):
“““
svm_read_problem(data_file_name return_scipy=False) -> [y x] y: list x: list of dictionary
svm_read_problem(data_file_name return_scipy=True) -> [y x] y: ndarray x: csr_matrix
Read LIBSVM-format data from data_file_name and return labels y
and data instances x.
“““
prob_y = []
prob_x = []
row_ptr = [0]
col_idx = []
for i line in enumerate(open(data_file_name)):
line = line.split(None 1)
# In case an instance with all zero features
if len(line) == 1: line += [‘‘]
label features = line
prob_y += [float(label)]
if scipy != None and return_scipy:
nz = 0
for e in features.split():
ind val = e.split(“:“)
val = float(val)
if val != 0:
col_idx += [int(ind)-1]
prob_x += [val]
nz += 1
row_ptr += [row_ptr[-1]+nz]
else:
xi = {}
for e in features.split():
ind val = e.split(“:“)
xi[int(ind)] = float(val)
prob_x += [xi]
if scipy != None and return_scipy:
prob_y = scipy.array(prob_y)
prob_x = scipy.array(prob_x)
col_idx = scipy.array(col_idx)
row_ptr = scipy.array(row_ptr)
prob_x = sparse.csr_matrix((prob_x col_idx row_ptr))
return (prob_y prob_x)
def evaluations_scipy(ty pv):
“““
evaluations_scipy(ty pv) -> (ACC MSE SCC)
ty pv: ndarray
Calculate accuracy mean squared error and squared correlation coefficient
using the true values (ty) and predicted values (pv).
“““
if not (scipy != None and isinstance(ty scipy.ndarray) and isinstance(pv scipy.ndarray)):
raise TypeError(“type of ty and pv must be ndarray“)
if len(ty) != len(pv):
raise ValueError(“len(ty) must be equal to len(pv)“)
ACC = 100.0*(ty == pv).mean()
MSE = ((ty - pv)**2).mean()
l = len(ty)
sumv = pv.sum()
sumy = ty.sum()
sumvy = (pv*ty).sum()
sumvv = (pv*pv).sum()
sumyy = (ty*ty).sum()
with scipy.errstate(all = ‘raise‘):
try:
SCC = ((l*sumvy-sumv*sumy)*(l*sumvy-sumv*sumy))/((l*sumvv-sumv*sumv)*(l*sumyy-sumy*sumy))
except:
SCC = float(‘nan‘)
return (float(ACC) float(MSE) float(SCC))
def evaluations(ty pv useScipy = True):
“““
evaluations(ty pv useScipy) -> (ACC MSE SCC)
ty pv: list tuple or ndarray
useScipy: convert ty pv to ndarray and use scipy functions for the evaluation
Calculate accuracy mean squared error and squared correlation coefficient
using the true values (ty) and predicted values (pv).
“““
if scipy != None and useScipy:
return evaluations_scipy(scipy.asarray(ty) scipy.asarray(pv))
if len(ty) != len(pv):
raise ValueError(“len(ty) must be equal to len(pv)“)
total_correct = total_error = 0
sumv = sumy = sumvv = sumyy = sumvy = 0
for v y in zip(pv ty):
if y == v:
total_correct += 1
total_error += (v-y)*(v-y)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5121 2018-07-15 22:16 python\commonutil.py
文件 32 2018-07-15 22:16 python\Makefile
文件 15822 2018-07-15 22:16 python\README
文件 13631 2018-07-15 22:16 python\svm.py
文件 9395 2018-07-15 22:16 python\svmutil.py
相关资源
- ppt 机器学习.ppt
- Logistic回归总结非常好的机器学习总结
- Convex Analysis and Optimization (Bertsekas
- 基于蚁群算法优化SVM的瓦斯涌出量预
- 基于模糊聚类和SVM的瓦斯涌出量预测
- 机器学习个人笔记完整版v5.2-A4打印版
- 基于CAN总线与ZigBee的瓦斯实时监测及
- JUNIOR:粒子物理学中无监督机器学习
- 语料库.zip
- SVM-Light资料,使用说明
- 果蝇算法融合SVM的开采沉陷预测模型
- 中国科学技术大学 研究生课程 机器学
- 遗传算法越野小车unity5.5
- BoW|Pyramid BoW+SVM进行图像分类
- 吴恩达机器学习编程题
- shape_predictor_68_face_landmarks.dat.bz2 68个标
- 基于libsvm的图像分割代码
- 机器学习实战高清pdf,中文版+英文版
- 李宏毅-机器学习(视频2017完整)
- 机器学习深度学习 PPT
- 麻省理工:深度学习介绍PPT-1
- 基于SVM及两类运动想象的多通道特征
- 小波包和SVM在轴承故障识别中的应用
- 林智仁教授最新版本LibSVM工具箱
- Wikipedia机器学习迷你电子书之四《D
- 台湾林教授的支持向量机libsvm
- Learning From Data Yaser S. Abu-Mostafa
- 新闻分类语料
- 北大林宙辰:机器学习一阶算法的优
- libsvm-3.20
评论
共有 条评论