程序说明:利用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('未发送')
利用邮箱监督机器学习训练过程
最新推荐文章于 2024-07-08 17:33:44 发布