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

做自媒体有哪些网站网站建设app开发合同

做自媒体有哪些网站,网站建设app开发合同,dw做网站常用标签,织梦音乐网站模板绘制混淆矩阵(Confusion Matrix),用于评估分类模型的性能。混淆矩阵展示了模型预测结果与真实标签之间的对应关系,能够直观地显示各类别的预测准确性和错误类型。 混淆矩阵是评估分类模型性能的基础工具,特别适用于多…

绘制混淆矩阵(Confusion Matrix),用于评估分类模型的性能。混淆矩阵展示了模型预测结果与真实标签之间的对应关系,能够直观地显示各类别的预测准确性和错误类型。

混淆矩阵是评估分类模型性能的基础工具,特别适用于多分类问题。

你可以使用swanlab.confusion_matrix来记录混淆矩阵。

Demo链接:ComputeMetrics - SwanLab

在这里插入图片描述

基本用法

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import xgboost as xgb
import swanlab# 加载鸢尾花数据集
iris_data = load_iris()
X = iris_data.data
y = iris_data.target
class_names = iris_data.target_names.tolist()# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# 训练模型
model = xgb.XGBClassifier(objective='multi:softmax', num_class=len(class_names))
model.fit(X_train, y_train)# 获取预测结果
y_pred = model.predict(X_test)# 初始化SwanLab
swanlab.init(project="Confusion-Matrix-Demo", experiment_name="Confusion-Matrix-Example")# 记录混淆矩阵
swanlab.log({"confusion_matrix": swanlab.confusion_matrix(y_test, y_pred, class_names)
})swanlab.finish()

使用自定义类别名称

# 定义自定义类别名称
custom_class_names = ["类别A", "类别B", "类别C"]# 记录混淆矩阵
confusion_matrix = swanlab.confusion_matrix(y_test, y_pred, custom_class_names)
swanlab.log({"confusion_matrix_custom": confusion_matrix})

不使用类别名称

# 不指定类别名称,将使用数字索引
confusion_matrix = swanlab.confusion_matrix(y_test, y_pred)
swanlab.log({"confusion_matrix_default": confusion_matrix})

二分类示例

import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
import xgboost as xgb
import swanlab# 生成二分类数据
X, y = make_classification(n_samples=1000, n_features=20, n_informative=2, n_redundant=10, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)# 训练模型
model = xgb.XGBClassifier(use_label_encoder=False, eval_metric='logloss')
model.fit(X_train, y_train)# 获取预测结果
y_pred = model.predict(X_test)# 记录混淆矩阵
swanlab.log({"confusion_matrix": swanlab.confusion_matrix(y_test, y_pred, ["负类", "正类"])
})

注意事项

  1. 数据格式: y_truey_pred可以是列表或numpy数组
  2. 多分类支持: 此函数支持二分类和多分类问题
  3. 类别名称: class_names的长度应该与类别数量一致
  4. 依赖包: 需要安装scikit-learnpyecharts
  5. 坐标轴: sklearn的confusion_matrix左上角为(0,0),在pyecharts的heatmap中是左下角,函数会自动处理坐标转换
  6. 矩阵解读: 混淆矩阵中,行表示真实标签,列表示预测标签
http://www.dtcms.com/a/603304.html

相关文章:

  • 做外贸搜索外国客户的网站网站建设技术合伙人的技术股份
  • 网站建设公司设计网页的工具甘肃省建设厅官方网站造价总站
  • Unity CullingGroup详解
  • 建设银行曲江支行网站上海信息公司做网站
  • 监理网站广东省公路建设公司网站
  • C语言编译器哪个好用 | 选择适合自己的C语言编译器提升编程效率
  • 企业做宣传网站多少钱制作网页之前必须先建立什么
  • 遗传算法求解TSP旅行商问题python代码实战
  • Servlet 网页重定向
  • Eclipse 生成 jar 包
  • 学Java第四十三天——Map双列集合
  • 淮南服装网站建设地址房产网站如何做
  • 北京牛鼻子网站建设公司网站建设kaituozu
  • 服务器A需要调用银行的https://xx.xx.xx.xx:10000/infoBatch接口 nginx作为中间转发 怎么配置
  • 中国源码网游戏开服衡阳网站优化方案
  • 商品网站开发南宁做网站
  • Linux之中断子系统-中断控制器的中断函数gic_handle_irq分析(5)
  • 社交网站开发平台建工在线
  • Agentic AI TASK02 Reflection Design and Pattern
  • 撰写网站专题活动策划方案网站备案域名购买
  • 2014 吉林省赛题解 | CCUT应用OJ题解——F[X] + X = N
  • 如何做网站使用手册两个网站如何使用一个虚拟主机
  • 【云运维】Kubernetes 安装(基于Containerd+Calico)
  • 芜湖高端网站建设网站推广 济南
  • 公共部门网站建设维护网站挂黑链
  • wordpress怎么做的wifi优化大师下载
  • 免费婚庆网站模板嵌入式网站开发培训
  • 网站关键词先后开发公司安全管理组织机构图
  • 网站建设域名什么意思wordpress插件点不开
  • wordpress怎样建立多站点手机百度账号登录个人中心