当前位置: 首页 > news >正文

机器学习:模型评估和模型保存

一、模型评估

from sklearn.metrics import accuracy_score, confusion_matrix, classification_report# 使用测试集进行预测
y_pred = model.predict(X_test)# 计算准确率
accuracy = accuracy_score(y_test, y_pred)
print(f"Accuracy: {accuracy*100:.2f}%")# 打印混淆矩阵
conf_matrix = confusion_matrix(y_test, y_pred)
print("Confusion Matrix:")
print(conf_matrix)# 打印分类报告,包括精确率、召回率和F1分数
class_report = classification_report(y_test, y_pred)
print("Classification Report:")
print(class_report)

二、模型保存

#使用joblib保存模型
import joblib
joblib.dump(model, "./yorelee_model.pth")
#模型的后缀名是无所谓的

三、后话

模型选择的时候,也可以使用模型融合,即结果由用不同模型的结果按比例得到。

比如pre=(pre_1*a+pre_2*b)/(a+b)。

那么我们在保存模型的时候,这两个模型要一起保存,然后之后训练就导入两个模型,pre这样算出来就行。

%%time
# 2种模型融合
def model_mix(pred_1, pred_2):result = pd.DataFrame(columns=['LinearRegression','XGBRegressor','Combine'])for a in range (80):for b in range(1,80):y_pred = (a*pred_1 + b*pred_2 ) / (a+b)mse = mean_squared_error(y_test,y_pred)mse = mean_squared_error(y_test,y_pred)new_row = pd.DataFrame([{'LinearRegression':a, 'XGBRegressor':b, 'Combine':mse}])result = pd.concat([result, new_row], ignore_index=True)return resultlinear_predict=model_linear.predict(x_test)
xgb_predict=XGBClassifier.predict(x_test)
model_combine = model_mix(linear_predict,  xgb_predict)model_combine.sort_values(by='Combine', inplace=True)
model_combine.head()
#各种比例来一份,看看mse最高分,查看 a和b的具体值

相关文章:

  • 【软考】设计模式之访问者模式
  • Redis的主从搭建
  • Linux笔记--GCC
  • 全新2.0版本极其抽象的门(Spring Security)
  • Unity RectTransform·屏幕坐标转换
  • 【研发日记】Matlab/Simulink技能解锁(三)——在Stateflow编辑窗口Debug
  • 2024目前三种有效加速国内Github
  • 算法修炼-动态规划之路径问题(1)
  • 代码随想录算法训练营第四十六天 139.单词拆分、多重背包(了解)、 背包总结
  • 类与对象的实践----日期相关函数的实现
  • 【硬件相关】IB网/以太网基础介绍及部署实践
  • cartographer ceres后端优化
  • 13. Springboot集成Protobuf
  • 【Spring连载】使用Spring Data访问 MongoDB----对象映射之对象引用
  • 文心一言 Python编程之
  • bearychat的java client
  • C# 免费离线人脸识别 2.0 Demo
  • extract-text-webpack-plugin用法
  • JS创建对象模式及其对象原型链探究(一):Object模式
  • pdf文件如何在线转换为jpg图片
  • Puppeteer:浏览器控制器
  • SpringCloud集成分布式事务LCN (一)
  • sublime配置文件
  • VirtualBox 安装过程中出现 Running VMs found 错误的解决过程
  • Vue ES6 Jade Scss Webpack Gulp
  • 个人博客开发系列:评论功能之GitHub账号OAuth授权
  • 给自己的博客网站加上酷炫的初音未来音乐游戏?
  • 前端_面试
  • ​总结MySQL 的一些知识点:MySQL 选择数据库​
  • #ifdef 的技巧用法
  • (c语言)strcpy函数用法
  • (C语言版)链表(三)——实现双向链表创建、删除、插入、释放内存等简单操作...
  • (十三)Maven插件解析运行机制
  • (转) 深度模型优化性能 调参
  • (转)c++ std::pair 与 std::make
  • (转)平衡树
  • (转)人的集合论——移山之道
  • .aanva
  • .describe() python_Python-Win32com-Excel
  • .net 4.0发布后不能正常显示图片问题
  • .NET Standard 支持的 .NET Framework 和 .NET Core
  • .NET与 java通用的3DES加密解密方法
  • .py文件应该怎样打开?
  • @31省区市高考时间表来了,祝考试成功
  • @Controller和@RestController的区别?
  • [Avalon] Avalon中的Conditional Formatting.
  • [BZOJ2208][Jsoi2010]连通数
  • [Grafana]ES数据源Alert告警发送
  • [HTML]HTML5实现可编辑表格
  • [iOS]中字体样式设置 API
  • [java]删除数组中的某一个元素
  • [MicroPython]TPYBoard v102 CAN总线通信
  • [New Portal]Windows Azure Virtual Machine (3) 在VM上挂载磁盘
  • [Oh My C++ Diary]内联函数
  • [PyQt] Pycharm 配置 PyQt 开发环境