利用邮箱监督机器学习训练过程

程序说明:利用sklearn机器学习库,调用svm方法训练/预测数据结果,最后邮箱发送训练进度和结果
Note: 需要安装sklearn机器学习库, matplotlib
# coding: utf-8

# 载入数据
from sklearn import datasets
digits = datasets.load_digits()
result = 0

# 利用svm训练和预测
from sklearn import svm
clf = svm.SVC(gamma=0.001, C= 100.)
clf.fit(digits.data[:-1], digits.target[:-1])
x_data = digits.data[-1]
x = x_data.reshape(1, -1)
result = clf.predict(x)

# matplot绘图
import matplotlib.pyplot as plt
plt.figure(1, (3, 3))
plt.imshow(digits.images[-1], cmap = plt.cm.gray_r, interpolation = 'nearest')
plt.show()

# 邮件发送训练结果
output = "predict result is:" + str(result[0])

if result != 0:
    import smtplib
    from email.mime.text import MIMEText

    mailto_list = ["××××@qq.com"]
    mail_host = "smtp.126.com"  # 设置服务器
    mail_user = "××××"  # 用户名
    mail_pass = "××××××××"  # 代理登录密码
    mail_postfix = "126.com"  # 发件箱的后缀


    def send_mail(to_list, sub):
        me = "hello" + "<" + mail_user + "@" + mail_postfix + ">"
        msg = MIMEText(output, _subtype='plain', _charset='gb2312')
        msg['Subject'] = sub
        msg['From'] = me
        msg['To'] = ";".join(to_list)
        try:
            server = smtplib.SMTP()
            server.connect(mail_host)
            server.login(mail_user, mail_pass)
            server.sendmail(me, to_list, msg.as_string())
            server.close()
            return True
        except Exception:
            return False


    if __name__ == '__main__':

        if send_mail(mailto_list, "SVM训练"):
            print("发送成功")
        else:
            print("发送失败")
else:
    print('未发送')


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值