def execute(ifn, ofn, label, tunner):
ofh = open(ofn, "w+")
list_data, list_target = load_data(ifn, tunner)
ofh.write("all:%d\n" % len(list_data))
list_c=[0.5, 1, 2, 5]
for float_c in list_c:
ofh.write(".......%f\n" % float_c)
clf = svm.SVC(kernel='linear', C=float_c)
data_train = pandas.DataFrame(list_data, columns=list_key)
sores = cross_validation.cross_val_score(clf, data_train[list_train], list_target, cv=3)
ofh.write("%s\n" % ",".join(map(str, sores)))
list_train_data, list_test_data, list_train_target, list_test_target = train_test_split(list_data, list_target, test_size=0.3)
ofh.write("train:%d, test:%d\n" % (len(list_train_data), len(list_test_target)))
data_train = pandas.DataFrame(list_train_data, columns=list_key)
data_test = pandas.DataFrame(list_test_data, columns=list_key)
clf.fit(data_train[list_train], list_train_target)
# joblib.dump(clf, 'filename.pkl%s.%s' % (str(float_c), label))
res = clf.predict(data_test[list_train])
total = len(res)
right = 0
for l,r in zip(res, list_test_target):
if l == r:
right += 1
ofh.write("total:%f right:%f radio:%f\n" % (total, right, float(right) * 100 /total))
ofh.write("[\n")
list_coef = clf.coef_.tolist()
ofh.write("%s\n" % "\n".join(map(str, [-1 * item for item in list_coef[0]])))
ofh.write("]\n")
ofh.write("...................\n")
ofh.close()
相关推荐
Python编写的SVM算法,SVM算法的实现,适合直接使用,开放源代码,Supported Vector Machine。 (Python code SVM algorithm,SVM algorithm realizition,easy to use,open source,Supported Vector Machine。)
python支持向量机做的人脸识别程序,可自动下载图片库
python svm手写识别算法代码
代码配套教程:... 提供给有需要的朋友,主要是用Python SVM 手写数字识别,这是Jupyter Notebook格式,需要读者自行安装Jupyter Notebook进行upload文件直接运行。
svm算法python代码,用于了解学习svm算法
This document contains a general overview in the first few sections as well as a more detailed reference in later sections for SVMpython. If you re already familiar with SVMpython, it s possible to ...
基于python的svm分类学习。线性可分svm,非线性svm。 对花卉(花蕾)进行分类,并可视化
科研上用来进行基于SVM方法的多分类的程序
该代码利用SVM方法对数据进行分类,在python环境下可运行
python利用支持向量机SVM进行时间序列预测(数据+源码)
python SVM算法的一个案例,用以训练SVM。
这里面有一些tmsvm的程序参数可供大家参考
版本3.22于2016年12月22日发布。它进行了一些小的修复。 LIBSVM工具提供了许多 LIBSVM的扩展。如果您需要LIBSVM中不支持的某些功能,请检查它。...要使用这个工具,你还需要安装python 和 gnuplot。
一款不错的支持向量机程序,程序执行效率很高!
基于python的svm与word2vec文本情感分析设计与实现
python 自定义生成多核svm进行分类
Python实现SVM分类器算法
SVM鸢尾花分类Python实现 基于SVM算法实现鸢尾花数据集分类 包括混淆矩阵输出
没有调包,单纯用Python程序实现svm,更加易懂明了,能更好地理解公式推导以及svm的实现,并打印机器对每个点的操作和参数的变化。