宝塔window怎么做网站邯郸市出租房屋信息网

张小明 2026/1/9 23:36:20
宝塔window怎么做网站,邯郸市出租房屋信息网,建设网站服务器是什么,定制软件系统浙大疏锦行 一、数据准备与基线模型 # 先运行之前预处理好的代码 import pandas as pd import pandas as pd #用于数据处理和分析#xff0c;可处理表格数据。 import numpy as np #用于数值计算#xff0c;提供了高效的数组操作。 import matplotlib.pyplot as plt…浙大疏锦行一、数据准备与基线模型# 先运行之前预处理好的代码 import pandas as pd import pandas as pd #用于数据处理和分析可处理表格数据。 import numpy as np #用于数值计算提供了高效的数组操作。 import matplotlib.pyplot as plt #用于绘制各种类型的图表 import seaborn as sns #基于matplotlib的高级绘图库能绘制更美观的统计图形。 import warnings warnings.filterwarnings(ignore) # 设置中文字体解决中文显示问题 plt.rcParams[font.sans-serif] [SimHei] # Windows系统常用黑体字体 plt.rcParams[axes.unicode_minus] False # 正常显示负号 data pd.read_csv(E:\study\PythonStudy\python60-days-challenge-master\data.csv) #读取数据 # 先筛选字符串变量 discrete_features data.select_dtypes(include[object]).columns.tolist() # Home Ownership 标签编码 home_ownership_mapping { Own Home: 1, Rent: 2, Have Mortgage: 3, Home Mortgage: 4 } data[Home Ownership] data[Home Ownership].map(home_ownership_mapping) # Years in current job 标签编码 years_in_job_mapping { 1 year: 1, 1 year: 2, 2 years: 3, 3 years: 4, 4 years: 5, 5 years: 6, 6 years: 7, 7 years: 8, 8 years: 9, 9 years: 10, 10 years: 11 } data[Years in current job] data[Years in current job].map(years_in_job_mapping) # Purpose 独热编码记得需要将bool类型转换为数值 data pd.get_dummies(data, columns[Purpose]) data2 pd.read_csv(E:\study\PythonStudy\python60-days-challenge-master\data.csv) # 重新读取数据用来做列名对比 list_final [] # 新建一个空列表用于存放独热编码后新增的特征名 for i in data.columns: if i not in data2.columns: list_final.append(i) # 这里打印出来的就是独热编码后的特征名 for i in list_final: data[i] data[i].astype(int) # 这里的i就是独热编码后的特征名 # Term 0 - 1 映射 term_mapping { Short Term: 0, Long Term: 1 } data[Term] data[Term].map(term_mapping) data.rename(columns{Term: Long Term}, inplaceTrue) # 重命名列 continuous_features data.select_dtypes(include[int64, float64]).columns.tolist() #把筛选出来的列名转换成列表 # 连续特征用中位数补全 for feature in continuous_features: mode_value data[feature].mode()[0] #获取该列的众数。 data[feature].fillna(mode_value, inplaceTrue) #用众数填充该列的缺失值inplaceTrue表示直接在原数据上修改。 # 最开始也说了 很多调参函数自带交叉验证甚至是必选的参数你如果想要不交叉反而实现起来会麻烦很多 # 所以这里我们还是只划分一次数据集 from sklearn.model_selection import train_test_split X data.drop([Credit Default], axis1) # 特征axis1表示按列删除 y data[Credit Default] # 标签 # 按照8:2划分训练集和测试集 X_train, X_test, y_train, y_test train_test_split(X, y, test_size0.2, random_state42) # 80%训练集20%测试集 from sklearn.ensemble import RandomForestClassifier #随机森林分类器 from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score # 用于评估分类器性能的指标 from sklearn.metrics import classification_report, confusion_matrix #用于生成分类报告和混淆矩阵 import warnings #用于忽略警告信息 warnings.filterwarnings(ignore) # 忽略所有警告信息 # --- 1. 默认参数的随机森林 --- # 评估基准模型这里确实不需要验证集 print(--- 1. 默认参数随机森林 (训练集 - 测试集) ---) rf_model RandomForestClassifier(random_state42) rf_model.fit(X_train, y_train) # 在训练集上训练 rf_pred rf_model.predict(X_test) # 在测试集上预测 print(\n默认随机森林 在测试集上的分类报告) print(classification_report(y_test, rf_pred)) print(默认随机森林 在测试集上的混淆矩阵) print(confusion_matrix(y_test, rf_pred))二、数据层面处理方法2.1过采样方法## --- 2. 随机过采样 (Random Oversampling) --- print(\n--- 2. 随机过采样 (Random Oversampling) ---) # 导入随机过采样器 from imblearn.over_sampling import RandomOverSampler import time # 实例化随机过采样器设置 sampling_strategyminority 表示只对少数类进行采样 # random_state 用于确保结果可复现 ros RandomOverSampler(sampling_strategyminority, random_state42) # 对训练集进行过采样。注意只对训练集进行操作测试集保持不变 start_time time.time() X_resampled_ros, y_resampled_ros ros.fit_resample(X_train, y_train) end_time time.time() print(f随机过采样耗时: {end_time - start_time:.4f} 秒) # 检查采样后的类别分布 print(\n随机过采样后训练集类别分布:) print(pd.Series(y_resampled_ros).value_counts()) # 使用过采样后的数据训练随机森林模型 rf_model_ros RandomForestClassifier(random_state42) rf_model_ros.fit(X_resampled_ros, y_resampled_ros) # 在过采样后的训练集上训练 rf_pred_ros rf_model_ros.predict(X_test) # 在原始测试集上预测 print(\n随机过采样后模型 在测试集上的分类报告) print(classification_report(y_test, rf_pred_ros)) print(随机过采样后模型 在测试集上的混淆矩阵) print(confusion_matrix(y_test, rf_pred_ros)) ## --- 3. SMOTE 过采样 (Synthetic Minority Over-sampling Technique) --- print(\n--- 3. SMOTE 过采样 (Synthetic Minority Over-sampling Technique) ---) # 导入 SMOTE 过采样器 from imblearn.over_sampling import SMOTE # 实例化 SMOTE 过采样器 smote SMOTE(random_state42) # 对训练集进行 SMOTE 过采样 start_time time.time() X_resampled_smote, y_resampled_smote smote.fit_resample(X_train, y_train) end_time time.time() print(fSMOTE 过采样耗时: {end_time - start_time:.4f} 秒) # 检查采样后的类别分布 print(\nSMOTE 过采样后训练集类别分布:) print(pd.Series(y_resampled_smote).value_counts()) # 使用 SMOTE 过采样后的数据训练随机森林模型 rf_model_smote RandomForestClassifier(random_state42) rf_model_smote.fit(X_resampled_smote, y_resampled_smote) # 在过采样后的训练集上训练 rf_pred_smote rf_model_smote.predict(X_test) # 在原始测试集上预测 print(\nSMOTE 过采样后模型 在测试集上的分类报告) print(classification_report(y_test, rf_pred_smote)) print(SMOTE 过采样后模型 在测试集上的混淆矩阵) print(confusion_matrix(y_test, rf_pred_smote)) ## --- 6. 欠采样随机欠采样 (Random Under-Sampling) --- print(\n--- 6. 欠采样随机欠采样 (Random Under-Sampling) ---) # 导入随机欠采样器 from imblearn.under_sampling import RandomUnderSampler # 实例化随机欠采样器sampling_strategymajority 表示只对多数类进行采样 rus RandomUnderSampler(sampling_strategymajority, random_state42) # 对训练集进行欠采样 start_time time.time() # X_resampled_rus 和 y_resampled_rus 是欠采样后的训练集 X_resampled_rus, y_resampled_rus rus.fit_resample(X_train, y_train) end_time time.time() print(f随机欠采样耗时: {end_time - start_time:.4f} 秒) # 检查采样后的类别分布 print(\n随机欠采样后训练集类别分布:) # 欠采样后多数类样本数量将等于少数类样本数量 print(pd.Series(y_resampled_rus).value_counts()) # 使用欠采样后的数据训练随机森林模型 rf_model_rus RandomForestClassifier(random_state42) rf_model_rus.fit(X_resampled_rus, y_resampled_rus) rf_pred_rus rf_model_rus.predict(X_test) # 在原始测试集上预测 print(\n随机欠采样后模型 在测试集上的分类报告) print(classification_report(y_test, rf_pred_rus)) print(confusion_matrix(y_test, rf_pred_rus)) ## --- 7. 欠采样Edited Nearest Neighbors (ENN) --- print(\n--- 7. 欠采样Edited Nearest Neighbors (ENN) ---) from imblearn.under_sampling import EditedNearestNeighbours # 实例化 ENN (默认参数通常用于清理多数类样本) # sampling_strategyall 表示对所有类别应用规则但实际主要移除多数类中的噪声 enn EditedNearestNeighbours(sampling_strategyall, n_neighbors3, kind_selall) # 对训练集进行 ENN 欠采样数据清洗 start_time time.time() X_resampled_enn, y_resampled_enn enn.fit_resample(X_train, y_train) end_time time.time() print(fENN 欠采样耗时: {end_time - start_time:.4f} 秒) # 检查采样后的类别分布 print(\nENN 欠采样后训练集类别分布:) # 注意ENN 是数据清洗不会完全平衡数据集多数类样本会减少但仍多于少数类 print(pd.Series(y_resampled_enn).value_counts()) # 使用 ENN 欠采样后的数据训练随机森林模型 rf_model_enn RandomForestClassifier(random_state42) rf_model_enn.fit(X_resampled_enn, y_resampled_enn) rf_pred_enn rf_model_enn.predict(X_test) print(\nENN 欠采样后模型 在测试集上的分类报告) print(classification_report(y_test, rf_pred_enn)) print(confusion_matrix(y_test, rf_pred_enn)) ## --- 8. 混合采样SMOTE ENN (SMOTENN) --- print(\n--- 8. 混合采样SMOTE ENN (SMOTENN) ---) # 导入 SMOTENN from imblearn.combine import SMOTEENN # 实例化 SMOTEENN它内部集成了 SMOTE 和 ENN # random_state 用于确保结果可复现 smote_enn SMOTEENN(random_state42) # 对训练集进行混合采样 start_time time.time() # X_resampled_smotenn 和 y_resampled_smotenn 是混合采样后的训练集 X_resampled_smotenn, y_resampled_smotenn smote_enn.fit_resample(X_train, y_train) end_time time.time() print(fSMOTE ENN 混合采样耗时: {end_time - start_time:.4f} 秒) # 检查采样后的类别分布 print(\nSMOTE ENN 混合采样后训练集类别分布:) # 经过 SMOTE 和 ENN 清理后数据集通常会接近平衡但多数类会略有减少 print(pd.Series(y_resampled_smotenn).value_counts()) # 使用混合采样后的数据训练随机森林模型 rf_model_smotenn RandomForestClassifier(random_state42) rf_model_smotenn.fit(X_resampled_smotenn, y_resampled_smotenn) rf_pred_smotenn rf_model_smotenn.predict(X_test) # 在原始测试集上预测 print(\nSMOTE ENN 混合采样后模型 在测试集上的分类报告) print(classification_report(y_test, rf_pred_smotenn)) print(SMOTE ENN 混合采样后模型 在测试集上的混淆矩阵) print(confusion_matrix(y_test, rf_pred_smotenn))三.算法层面四.评估指标方面
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

如何申请免费网站微营销论文

博主介绍:✌ 专注于Java,python,✌关注✌私信我✌具体的问题,我会尽力帮助你。一、研究目的本研究旨在设计并实现一个基于Spring Boot框架的在线考试系统,以满足现代教育领域对在线考试系统的需求。具体研究目的如下:提高考试效率…

张小明 2026/1/7 17:59:46 网站建设

电商设计网站培训建设一个视频网站己18

本文来源公众号“Zilliz”,仅用于学术分享,侵权删,干货满满。 原文链接:https://mp.weixin.qq.com/s/HjV1FjpVjc6qt-ubyeAl-w 1 rerank如何影响业务表现 今天聊一聊我们如何做高质量rerank。 一个常识是,无论企业知…

张小明 2026/1/9 11:54:08 网站建设

网站图怎么做会高清国外js建设网站

D - Bus 全面概述 1. D - Bus 基础概念 D - Bus 是一种用于进程间通信(IPC)的机制,使用 D - Bus 的应用程序可分为服务器和客户端。服务器监听传入的连接,客户端则连接到服务器。一旦连接建立,消息就会以对称的方式流动,客户端和服务器的区别仅在建立连接时才有意义。 …

张小明 2025/12/31 1:47:06 网站建设

电子商务网站建设课件重庆的主要的网站

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容: 生成一份对比报告模板,展示传统手动开发STM32项目和AI辅助开发在以下方面的差异:1. 项目初始化时间 2. 外设配置效率 3. 调试耗时 4. 代码质量指标。要求包…

张小明 2025/12/31 17:04:36 网站建设

什么网站招聘外国人做兼职江门网站建设咨询

WindowResizer:打破窗口限制,重塑桌面布局体验 【免费下载链接】WindowResizer 一个可以强制调整应用程序窗口大小的工具 项目地址: https://gitcode.com/gh_mirrors/wi/WindowResizer 在数字工作环境中,你是否经常遇到无法调整大小的…

张小明 2026/1/10 14:54:58 网站建设

教你做面食的网站专业网站建设微信商城开发

RuoYi-Cloud微服务权限管理系统:从零开始快速部署完整指南 【免费下载链接】RuoYi-Cloud 🎉 基于Spring Boot、Spring Cloud & Alibaba的分布式微服务架构权限管理系统,同时提供了 Vue3 的版本 项目地址: https://gitcode.com/yangzong…

张小明 2025/12/31 17:04:38 网站建设