2 Star 1 Fork 1

mayanhui/smoke_recognition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
algo_SVM.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
lancezhange 提交于 2015-12-08 21:50 . first commit
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: lancezhange
# @Date: 2015-08-21 11:12:11
# @Last Modified by: lancezhange
# @Last Modified time: 2015-08-21 11:14:12
from sklearn import grid_search
from sklearn import svm
from sklearn import metrics
def getModel(x_train, x_test, y_train, y_test, print_metrics=True):
'''
Trains a classifier. Here we use SVM.
Args:
x_train (array of array): feature arrays of training data.
x_test (array of array): feature arrays of testing data.
y_train (array ): label arrays of training data.
y_test (array ): label arrays of testing data.
Returns:
A classifier (sklearn.svm.SVC).
'''
# define the parameter search space
parameters = {'kernel': ['linear', 'rbf'], 'C': [1, 10, 100, 1000],
'gamma': [0.01, 0.001, 0.0001]}
# search for the best classifier within the search space and return it
clf = grid_search.GridSearchCV(svm.SVC(), parameters).fit(x_train, y_train)
classifier = clf.best_estimator_
if print_metrics:
print('Parameters:', clf.best_params_)
print('Best classifier score')
print(metrics.classification_report(y_test,
classifier.predict(x_test)))
return classifier
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/TimVerion/smoke_recognition.git
git@gitee.com:TimVerion/smoke_recognition.git
TimVerion
smoke_recognition
smoke_recognition
master

搜索帮助