libsvm

机器学习九大算法---支持向量机

落爺英雄遲暮 提交于 2021-02-17 16:34:21
机器学习九大算法---支持向量机 出处:结构之法算法之道 blog 。 前言 动笔写这个支持向量机( support vector machine)是费了不少劲和困难的,原因很简单,一者这个东西本身就并不好懂,要深入学习和研究下去需花费不少时间和精力,二者这个东西也不好讲清楚,尽管网上已经有朋友写得不错了( 见文末参考链接),但在描述数学公式的时候还是显得不够。得益于同学白石的数学证明,我还是想尝试写一下,希望本文在兼顾通俗易懂的基础上,真真正正能足以成为一篇完整概括和介绍支持向量机的导论性的文章。 本文在写的过程中, 参考了不少资料,包括《支持向量机导论》、《统计学习方法》及网友 pluskid的支持向量机系列等等, 于此,还是一篇 学习笔记,只是加入了自己的理解和总结,有任何不妥之处,还望海涵。全文宏观上整体认识支持向量机的概念和用处,微观上深究部分定理的来龙去脉,证明及原理细节,力保逻辑清晰 & 通俗易懂。 同时,阅读本文时建议大家尽量使用 chrome等浏览器,如此公式才能更好的显示,再者,阅读时 可拿张纸和笔出来,把本文所有定理.公式都亲自推导一遍或者直接打印下来(可直接打印网页版或本文文末附的PDF ,享受随时随地思考、演算的极致快感),在文稿上演算。 Ok,还是那句原话,有任何问题,欢迎任何人随时不吝指正 & 赐教,感谢。 第一层、了解SVM 1.0

sklearn svm基本使用

拟墨画扇 提交于 2021-02-17 07:55:48
SVM基本使用     SVM在解决分类问题具有良好的效果,出名的软件包有 libsvm (支持多种核函数), liblinear 。此外python机器学习库scikit-learn也有svm相关算法, sklearn.svm. SVC 和 sklearn.svm.LinearSVC 分别由libsvm和liblinear发展而来。   推荐使用SVM的步骤为: 将原始数据转化为SVM算法软件或包所能识别的数据格式; 将数据标准化;(防止样本中不同特征数值大小相差较大影响分类器性能) 不知使用什么核函数,考虑使用RBF; 利用交叉验证网格搜索寻找最优参数(C, γ);(交叉验证防止过拟合,网格搜索在指定范围内寻找最优参数) 使用最优参数来训练模型; 测试。 下面利用scikit-learn说明上述步骤: 1 import numpy as np 2 from sklearn.svm import SVC 3 from sklearn.preprocessing import StandardScaler 4 from sklearn.model_selection import GridSearchCV, train_test_split 5 6 def load_data(filename) 7 ''' 8 假设这是鸢尾花数据,csv数据格式为: 9 0,5.1,3.5,1.4

XGBoost使用篇(未完成)

点点圈 提交于 2021-02-12 04:41:14
1.截止到本文(20191104)sklearn没有集成xgboost算法,需要单独安装xgboost库,然后导入使用 xgboost官网安装说明 Pre-built binary wheel for Python 在源码git页面下载包,然后手动安装。 如何安装包 2.xgboost读取文件的格式? xgboost的数据输入数据格式DMatrix目前支持两种数据格式:LibSVM和CSV libsvm数据格式 xgboost可以从libsvm、csv、numpy array、dataframe、xgboost binary buffer file载入训练数据 读入后,数据存储在DMatrix目标文件中。 3.xgboost模型的训练及预测过程? 第一种形式: xgboost原生接口的实现方法 import xgboost as xgb # read in data dtrain = xgb . DMatrix ( 'demo/data/agaricus.txt.train' ) dtest = xgb . DMatrix ( 'demo/data/agaricus.txt.test' ) # specify parameters via map param = { 'max_depth' : 2 , 'eta' : 1 , 'objective' : 'binary

Can we obtain hybrid algorithm for spam filtering from Naive Bayes & SVM?

自闭症网瘾萝莉.ら 提交于 2021-02-08 10:22:06
问题 I am developing a spam filtering application. I need suggestions regarding the hybrid algorithm from Naive Bayes & SVM.(e.g. based on feature vector, probabilities). Any help is appreciated. Can we develop hybrid algorithm from Naive bayes & SVM? 回答1: Not sure why would you want to merge these two specific methods, but you could use ensemble learning methods for that. EDIT: based on your comments, it seems you already have two independently trained classifiers, and would like to use them

Does one-class svm provide a probability estimate?

大城市里の小女人 提交于 2021-01-29 04:03:56
问题 I am using Libsvm for outlier detection (from Java), but I need a probability estimate not just a label. I traced the code and found that this is not possible. In particular, in the function svm_predict_values(..) I see the following code: if(model.param.svm_type == svm_parameter.ONE_CLASS) return (sum>0)?1:-1; else return sum; I understand that one-class SVM tries to estimate the support of some probability distribution given samples or data points from the "normal" class. Given a new data

Predict probabilities using SVM

眉间皱痕 提交于 2020-12-29 07:14:29
问题 I wrote this code and wanted to obtain probabilities of classification. from sklearn import svm X = [[0, 0], [10, 10],[20,30],[30,30],[40, 30], [80,60], [80,50]] y = [0, 1, 2, 3, 4, 5, 6] clf = svm.SVC() clf.probability=True clf.fit(X, y) prob = clf.predict_proba([[10, 10]]) print prob I obtained this output: [[0.15376986 0.07691205 0.15388546 0.15389275 0.15386348 0.15383004 0.15384636]] which is very weird because the probability should have been [0 1 0 0 0 0 0 0] (Observe that the sample

Predict probabilities using SVM

依然范特西╮ 提交于 2020-12-29 07:14:28
问题 I wrote this code and wanted to obtain probabilities of classification. from sklearn import svm X = [[0, 0], [10, 10],[20,30],[30,30],[40, 30], [80,60], [80,50]] y = [0, 1, 2, 3, 4, 5, 6] clf = svm.SVC() clf.probability=True clf.fit(X, y) prob = clf.predict_proba([[10, 10]]) print prob I obtained this output: [[0.15376986 0.07691205 0.15388546 0.15389275 0.15386348 0.15383004 0.15384636]] which is very weird because the probability should have been [0 1 0 0 0 0 0 0] (Observe that the sample

Predict probabilities using SVM

一曲冷凌霜 提交于 2020-12-29 07:14:13
问题 I wrote this code and wanted to obtain probabilities of classification. from sklearn import svm X = [[0, 0], [10, 10],[20,30],[30,30],[40, 30], [80,60], [80,50]] y = [0, 1, 2, 3, 4, 5, 6] clf = svm.SVC() clf.probability=True clf.fit(X, y) prob = clf.predict_proba([[10, 10]]) print prob I obtained this output: [[0.15376986 0.07691205 0.15388546 0.15389275 0.15386348 0.15383004 0.15384636]] which is very weird because the probability should have been [0 1 0 0 0 0 0 0] (Observe that the sample

Predict probabilities using SVM

℡╲_俬逩灬. 提交于 2020-12-29 07:12:52
问题 I wrote this code and wanted to obtain probabilities of classification. from sklearn import svm X = [[0, 0], [10, 10],[20,30],[30,30],[40, 30], [80,60], [80,50]] y = [0, 1, 2, 3, 4, 5, 6] clf = svm.SVC() clf.probability=True clf.fit(X, y) prob = clf.predict_proba([[10, 10]]) print prob I obtained this output: [[0.15376986 0.07691205 0.15388546 0.15389275 0.15386348 0.15383004 0.15384636]] which is very weird because the probability should have been [0 1 0 0 0 0 0 0] (Observe that the sample

matlab2016b配置libsvm的各中坑及解决办法

天大地大妈咪最大 提交于 2020-12-07 04:44:06
Q1:matlab2016b不能自动关联m文件! A1: (1)首先准备好工具,工具链接: pan.baidu.com/s/1t_KaFZNOFln9m57sMBTrkQ ;提取码:x49w。 (2)下载之后解压,请阅读readme,按照操作流程进行。 Note:运行reg文件的方式是,将matlab最小化(不退出),找到reg文件所在位置(就是压缩包后所在路径),双击就好了,然后关闭matlab,重启,则matlab已经关联m文件了,如果还没有成功,请关机重启电脑,再试一下,应该就能解决了。 Q2:matlab2016b配置libsvm3.23 A2: (1)还是准备好工具,libsvm3.23的安装包,获取路径有两条: 官方路径1:林教授的网站 www.csie.ntu.edu.tw/~cjlin/libsvm/ ;如图所示 往下面找,会看到一个 Download LIBSVM ;其下就有一个 zip file ,点击下载。安装时你要注意选择是要32位(x86)的还是64位(x64)的,要和电脑系统相匹配。 路径2:请直接下载 www (抱歉我懒得输入网址了,太麻烦);差点忘记给提取码了:m75k note:路径1获取的libsvm永远时最新版本的,也是最原始的版本;路径2获取的永远时libsvm3.23,但是这个版本里面的内容全部时便宜好的,同时也给出了mat格式的训练数据