加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
2_Train_SVM.py 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Hans Ren 提交于 2019-04-30 13:42 . Give out a hint
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 15 16:38:03 2017
@author: hans
"""
import sklearn.svm as ssv
from sklearn.externals import joblib
import glob
import os
import time
if __name__ == "__main__":
model_path = './models/svm.model'
train_feat_path = './features/train'
fds = []
labels = []
num=0
for feat_path in glob.glob(os.path.join(train_feat_path, '*.feat')):
num += 1
data = joblib.load(feat_path)
fds.append(data[:-1])
labels.append(data[-1])
print "%d Dealing with %s" %(num,feat_path)
t0 = time.time()
#------------------------SVM--------------------------------------------------
clf = ssv.SVC(kernel='rbf') # for training initial model
# clf = ssv.SVC(kernel='rbf', C=17.255220940030252, gamma=1.2943653125547475e-06) # for training svm_pso.model(origin model)
print "Training a SVM Classifier."
clf.fit(fds, labels)
joblib.dump(clf, model_path)
#------------------------SVM--------------------------------------------------
t1 = time.time()
print "Classifier saved to {}".format(model_path)
print 'The cast of time is :%f seconds' % (t1-t0)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化