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

宁工图书馆哪种书是关于做网站的国外的设计网站app吗

宁工图书馆哪种书是关于做网站的,国外的设计网站app吗,重庆长寿网站设计公司哪家专业,福州网站建设信息知识回顾: 1. 转化器和估计器的概念 2. 管道工程 3. ColumnTransformer和Pipeline类 作业: 整理下全部逻辑的先后顺序,看看能不能制作出适合所有机器学习的通用pipeline 一、导入数据库 import pandas as pd import numpy as np import matplo…

知识回顾:

1.  转化器和估计器的概念

2.  管道工程

3.  ColumnTransformer和Pipeline类

作业:

整理下全部逻辑的先后顺序,看看能不能制作出适合所有机器学习的通用pipeline

一、导入数据库

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import time # 导入 time 库
import warnings
warnings.filterwarnings("ignore")
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

 二、导入pipeline

from sklearn.pipeline import Pipeline 
from sklearn.compose import ColumnTransformer 
from sklearn.preprocessing import OrdinalEncoder, OneHotEncoder, StandardScaler 
from sklearn.impute import SimpleImputer 
from sklearn.ensemble import RandomForestClassifier 
from sklearn.metrics import classification_report, confusion_matrix 
data = pd.read_csv('heart.csv')
print("原始数据加载完成,形状为:", data.shape)
y = data['target'] # 标签
X = data.drop(['target'], axis=1) 
print("\n特征和标签分离完成。")
print("特征 X 的形状:", X.shape)
print("标签 y 的形状:", y.shape)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) 
print("\n数据集划分完成 (预处理之前)。")
print("X_train 形状:", X_train.shape)
print("X_test 形状:", X_test.shape)
print("y_train 形状:", y_train.shape)
print("y_test 形状:", y_test.shape)
object_cols = X.select_dtypes(include=['object']).columns.tolist()
numeric_cols = X.select_dtypes(exclude=['object']).columns.tolist()
ordinal_features = ['cp',  'restecg',  'slope', 'ca', 'thal']ordinal_categories = [[0, 1, 2, 3], # Home Ownership 的顺序 (对应1, 2, 3, 4)[0, 1, 2], # Years in current job 的顺序 (对应1-11)[0, 1, 2], # Term 的顺序 (对应0, 1)[0, 1, 2, 3, 4],[0, 1, 2, 3],
]

三、构建有序特征pipeline

ordinal_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='most_frequent')), ('encoder', OrdinalEncoder(categories=ordinal_categories, handle_unknown='use_encoded_value', unknown_value=-1)) 
])
print("有序特征处理 Pipeline 定义完成。")
nominal_features = ['sex','fbs','exang']

四、构建标称特征pipeline

nominal_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='most_frequent')), ('onehot', OneHotEncoder(handle_unknown='ignore', sparse_output=False)) 
])
print("标称特征处理 Pipeline 定义完成。")
continuous_features = [f for f in X.columns if f not in ordinal_features + nominal_features]
continuous_transformer = Pipeline(steps=[('imputer', SimpleImputer(strategy='most_frequent')),('scaler', StandardScaler()) 
print("连续特征处理 Pipeline 定义完成。")

五、串联预处理器和模型

preprocessor = ColumnTransformer(transformers=[('ordinal', ordinal_transformer, ordinal_features), ('nominal', nominal_transformer, nominal_features), ('continuous', continuous_transformer, continuous_features) ],remainder='passthrough' # 如何处理没有在上面列表中指定的列。
)
print("\nColumnTransformer (预处理器) 定义完成。")
pipeline = Pipeline(steps=[('preprocessor', preprocessor), ('classifier', RandomForestClassifier(random_state=42)) 
])
print("\n完整的 Pipeline 定义完成。")
print("\n--- 1. 默认参数随机森林 (训练集 -> 测试集) ---") 
start_time = time.time() 
pipeline.fit(X_train, y_train)
pipeline_pred = pipeline.predict(X_test)
end_time = time.time() 
print(f"训练与预测耗时: {end_time - start_time:.4f} 秒") 
print("\n默认随机森林 在测试集上的分类报告:") 
print(classification_report(y_test, pipeline_pred))
print("默认随机森林 在测试集上的混淆矩阵:") 
print(confusion_matrix(y_test, pipeline_pred))

http://www.dtcms.com/wzjs/801061.html

相关文章:

  • 商城网站后台模板建设部网站查询注册岩土工程师
  • 网站的建设费用预算策划书网页超链接到别的网站404
  • 南宁建站公司有哪些如何做一家门户网站
  • 网站管理包括哪些内容在哪个平台做网站好
  • 上海住房与建设部网站前台登录 wordpress
  • 最简约的网站网站开发需要什么关键技术
  • 可口可乐公司建设网站的目的是什么意思哪里有好看的网站
  • 东台网站制作手机设计软件免费
  • 国外的平面设计网站wordpress 如何采集
  • 上海专业网站设计制作兰州设计公司排名榜
  • ajaxjsp网站开发从入门到精通河北网站建设多少钱
  • 校园网上超市网站建设推广网站描述样本
  • 建立网站顺序中国设计网站排行榜
  • 织梦网站怎样上传到ftpwordpress友情链接推荐
  • 将网站加入小程序重庆市今天最新消息
  • 网站开发多少钱农民某购物网站开发项目
  • 广西北海市住房和建设厅网站海外网络服务器
  • 广州网站设计联系方式免费注册二级域名的网站
  • 网站服务器怎么优化网站建设费能算作广告费用吗
  • 龙岩企业网站建设制作长春网站开发报价
  • 可以左右滑动的网站怎样看一个网站做的网络广告
  • 平面设计教程网站有哪些做泥软件下载官方网站
  • 网站建设8万属于资产吗精品课程网站建设项目验收单
  • 手机h5免费模板网站代理网络手游
  • 如何自己免费制作网站官网网站开发框架
  • 网站开发验收申请报告无代码开发软件
  • 博客用来做微网站福州房地产网站建设
  • 营销策划方案网站网站开发师贴吧
  • jsp项目个人网站开发网站每个页面关键词都一样
  • 域名如何解绑一个网站新浪博客导入wordpress