python 机器学习 svm

源码地址:https://github.com/yicaifenchen8/learning.git

1.定义训练集合测试集

X = [[i, i] for i in range(20)]  # training samples
# X = [[0, 0],[0, 0], [0, 1], [1, 0]]  # training samples

# y = [i%2 for i in range(20)]  # training target
y = [i > 2 and '0' or '1' for i in range(20)]  # training target

2.训练模型

clf = svm.SVC()  # class

clf.fit(X, y)  # training the svc model

3.预测

print(clf.predict([[i, i] for i in range(20)]))

4.保存模型...

# 保存模型
joblib.dump(clf, '../res/rf.model')

# 加载模型
RF = joblib.load('../res/rf.model')

# 应用模型进行预测
result = RF.predict([[i, i] for i in range(20)])
print("result:",result)

a = 'ad' + 'bdd' + [555].__str__()+{'k':True}.__str__()
print(a)

源码地址:https://github.com/yicaifenchen8/learning.git

 

发布了48 篇原创文章 · 获赞 0 · 访问量 7869
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览