预测脱碳企业的信用评级-论文代码复现
文献来源
【Forecasting credit ratings of decarbonized firms: Comparative assessmentof machine learning models】
文章有代码复现有两个基本工作,1.是提取每个算法的重要性;2.计算每个算法的评价指标
算法有 CRT 分类决策树 ANN 人工神经网络 RFE 随机森林 SVM支持向量机
评价指标有F1 Score ;Specificity ;Accuracy
1.准备数据
分类标签【信誉等级CR1-CR7】和特征向量【变量】
[特征-变量]Probability of Default违约概率
Coverages覆盖范围
Capital Structure资本结构
Liquidity流动性
Profitability盈利能力
Operating Efficiency运营效率
Scale, Scope, and Diversity规模、范围和多样性
Competitive Advantage竞争优势
Fiscal Strength and Credit Conditions财政实力和信用状况
Systemic Governance and Effectiveness系统治理和有效性
Economic Strength经济实力
from sklearn.model_selection import train_test_split
from sklearn.metrics import f1_score, accuracy_score, confusion_matrix
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn.neural_network import MLPClassifier# Regenerating the dataset with binary classification
num_companies = 500
features = {'Probability_of_Default': np.random.uniform(0, 1, num_companies),'Coverages': np.random.uniform(0, 1, num_companies),'Capital_Structure': np.random.uniform(0, 1, num_companies),'Liquidity': np.random.uniform(0, 1, num_companies),'Profitability': np.random.uniform(0, 1, num_companies),'Operating_Efficiency': np.random.uniform(0, 1, num_companies),'Scale_Scope_and_Diversity': np.random.uniform(0, 1, num_companies),'Competitive_Advantage': np.random.uniform(0, 1, num_companies),'Fiscal_Strength_and_Credit_Conditions': np.random.uniform(0, 1, num_companies),'Systemic_Governance_and_Effectiveness': np.random.uniform(0, 1, num_companies),'Economic_Strength': np.random.uniform(0, 1, num_companies),
}
features['Rating'] = np.random.choice([1, 2], num_companies)# Create a DataFrame
df = pd.DataFrame(features)# Preview the data
df.head()
df.to_excel(r'C:\Users\12810\Desktop\组会\组会记录\2024-0103寒假集训材料\看论文任务\要讲的\模拟数据.xlsx')
df.head()
| Probability_of_Default | Coverages | Capital_Structure | Liquidity | Profitability | Operating_Efficiency | Scale_Scope_and_Diversity | Competitive_Advantage | Fiscal_Strength_and_Credit_Conditions | Systemic_Governance_and_Effectiveness | Economic_Strength | Rating | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.298531 | 0.328423 | 0.665525 | 0.985169 | 0.107456 | 0.933863 | 0.714293 | 0.681608 | 0.508398 | 0.472675 | 0.508559 | 2 |
| 1 | 0.841430 | 0.736388 | 0.999020 | 0.689946 | 0.348265 | 0.929935 | 0.066077 | 0.609516 | 0.797929 | 0.048373 | 0.424858 | 2 |
| 2 | 0.462897 | 0.105783 | 0.716292 | 0.912855 | 0.564482 | 0.850507 | 0.774066 | 0.880007 | 0.737817 | 0.729397 | 0.283405 | 2 |
| 3 | 0.062724 | 0.073537 | 0.611761 | 0.213703 | 0.483220 | 0.668749 | 0.052895 | 0.924532 | 0.134043 | 0.126261 | 0.910167 | 1 |
| 4 | 0.242200 | 0.089723 | 0.874793 | 0.659927 | 0.159241 | 0.348462 | 0.828590 | 0.273572 | 0.117796 | 0.154820 | 0.324018 | 2 |
from sklearn.tree import DecisionTreeClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn.metrics import classification_report, accuracy_score
from sklearn.model_selection import train_test_split# Define features and labels
X = df.drop('Rating', axis=1)
y = df['Rating']# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# Initialize the classifiers
classifiers = {'CRT': DecisionTreeClassifier(random_state=42),'ANN': MLPClassifier(random_state=42, max_iter=1000),'RFE': RandomForestClassifier(random_state=42),'SVM': SVC(random_state=42)
}# Dictionary to store models' performance metrics
performance_metrics = {}# Training and evaluating classifiers
for name, clf in classifiers.items():clf.fit(X_train, y_train) # Train the modely_pred = clf.predict(X_test) # Predict on test set# Calculate performance metricsperformance_metrics[name] = classification_report(y_test, y_pred, output_dict=True)performance_metrics[name]['accuracy'] = accuracy_score(y_test, y_pred)# Since ANN and SVM don't provide a direct method for feature importance, we will skip that part as per user's instructions.performance_metrics# ... (previous code to generate data and split sets)# Initialize classifiers
decision_tree = DecisionTreeClassifier(random_state=42)
random_forest = RandomForestClassifier(random_state=42)
ann = MLPClassifier(random_state=42, max_iter=1000)
svm = SVC(random_state=42)# Train and predict using each classifier
for clf in [decision_tree, random_forest, ann, svm]:clf.fit(X_train, y_train)y_pred = clf.predict(X_test)print(f"{clf.__class__.__name__} metrics:")print(classification_report(y_test, y_pred))print(f"Accuracy: {accuracy_score(y_test, y_pred)}\n")# Feature importance for Decision Tree and Random Forest
print(f"Decision Tree Feature Importance: {decision_tree.feature_importances_}")
print(f"Random Forest Feature Importance: {random_forest.feature_importances_}")
D:\install_file\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (1000) reached and the optimization hasn't converged yet.warnings.warn(DecisionTreeClassifier metrics:precision recall f1-score support1 0.36 0.38 0.37 452 0.47 0.45 0.46 55accuracy 0.42 100macro avg 0.42 0.42 0.42 100
weighted avg 0.42 0.42 0.42 100Accuracy: 0.42RandomForestClassifier metrics:precision recall f1-score support1 0.39 0.40 0.40 452 0.50 0.49 0.50 55accuracy 0.45 100macro avg 0.45 0.45 0.45 100
weighted avg 0.45 0.45 0.45 100Accuracy: 0.45MLPClassifier metrics:precision recall f1-score support1 0.40 0.44 0.42 452 0.50 0.45 0.48 55accuracy 0.45 100macro avg 0.45 0.45 0.45 100
weighted avg 0.46 0.45 0.45 100Accuracy: 0.45SVC metrics:precision recall f1-score support1 0.45 0.42 0.44 452 0.55 0.58 0.57 55accuracy 0.51 100macro avg 0.50 0.50 0.50 100
weighted avg 0.51 0.51 0.51 100Accuracy: 0.51Decision Tree Feature Importance: [0.1373407 0.1034318 0.09762338 0.047583 0.13000749 0.047780610.04700612 0.09306039 0.13848067 0.05285945 0.1048264 ]
Random Forest Feature Importance: [0.09758143 0.09809294 0.09033973 0.08525976 0.09331244 0.082810670.094648 0.10032612 0.08863182 0.08533643 0.08366067]D:\install_file\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (1000) reached and the optimization hasn't converged yet.warnings.warn(
from sklearn.inspection import permutation_importance# For ANN
ann.fit(X_train, y_train)
perm_importance_ann = permutation_importance(ann, X_test, y_test, n_repeats=30, random_state=42)# For SVM
svm.fit(X_train, y_train)
perm_importance_svm = permutation_importance(svm, X_test, y_test, n_repeats=30, random_state=42)# Store the permutation importances in a dictionary or DataFrame
feature_importances_ann = perm_importance_ann.importances_mean
feature_importances_svm = perm_importance_svm.importances_mean# You can then display these importances or further analyze them
print("Feature importances from ANN:", feature_importances_ann)
print("Feature importances from SVM:", feature_importances_svm)
D:\install_file\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (1000) reached and the optimization hasn't converged yet.warnings.warn(Feature importances from ANN: [-0.04366667 -0.04866667 -0.06166667 -0.01633333 -0.06166667 -0.069-0.059 -0.07333333 -0.02866667 -0.041 -0.04266667]
Feature importances from SVM: [-0.002 -0.00633333 0.019 0.035 0.00666667 0.00233333-0.00233333 -0.01466667 -0.02 0.00833333 0.02 ]
相关文章:
预测脱碳企业的信用评级-论文代码复现
文献来源 【Forecasting credit ratings of decarbonized firms: Comparative assessmentof machine learning models】 文章有代码复现有两个基本工作,1.是提取每个算法的重要性;2.计算每个算法的评价指标 算法有 CRT 分类决策树 ANN 人工神经网络 R…...
目标检测——KITTI目标跟踪数据集
KITTI目标跟踪数据集是由德国卡尔斯鲁厄理工学院和丰田美国技术研究院联合创建的一个大规模自动驾驶场景下的计算机视觉算法评测数据集。这个数据集主要用于评估立体图像、光流、视觉测距、3D物体检测和3D跟踪等计算机视觉技术在车载环境下的性能这个数据集包含了在市区、乡村和…...
25-k8s集群中-RBAC用户角色资源权限
一、RBAC概述 1,k8s集群的交互逻辑(简单了解) 我们通过k8s各组件架构,知道各个组件之间是使用https进行数据加密及交互的,那么同理,我们作为“使用”k8s的各种资源的使用者,也是通过https进行数…...
Android 面试问题 2024 版(其二)
Android 面试问题 2024 版(其二) 六、多线程和并发七、性能优化八、测试九、安全十、Material设计和 **UX/UI** 六、多线程和并发 Android 中的进程和线程有什么区别? 答:进程是在自己的内存空间中运行的应用程序的单独实例&…...
SpringMVC的异常处理
异常分类 : 预期异常(检查型异常)和运行时异常 1、使用@ExceptionHandle注解处理异常 @ExceptionHandle(value={***.class} 异常类型) public modelandview handelException(){} 仅限当前类使用 2、全局处理方式 @ControllerAdvice + @ExceptionHandle 新建类 @Cont…...
【计算机网络】1 因特网概述
一.网络、互联网和因特网 1.网络(network),由若干结点(node)和连接这些结点的链路(link)组成。 2.多个网络还可以通过路由器互联起来,这样就构成了一个覆盖范围更大的网络…...
【Ubuntu】Anaconda的安装和使用
目录 1 安装 2 使用 1 安装 (1)下载安装包 官网地址:Unleash AI Innovation and Value | Anaconda 点击Free Download 按键。 然后 点击下图中的Download开始下载安装包。 (2)安装 在安装包路径下打开终端&#…...
OpenAI推出首个AI视频模型Sora:重塑视频创作与体验
链接:华为OD机考原题附代码 Sora - 探索AI视频模型的无限可能 随着人工智能技术的飞速发展,AI视频模型已成为科技领域的新热点。而在这个浪潮中,OpenAI推出的首个AI视频模型Sora,以其卓越的性能和前瞻性的技术,引领着…...
mybatis总结传参三
十、(不推荐)多个参数-按位置传参 参数位置从 0 开始, 引用参数语法 #{ arg 位置 } , 第一个参数是 #{arg0}, 第二个是 #{arg1} 注意: mybatis-3.3 版本和之前的版本使用 #{0},#{1} 方式, 从 myba…...
JSONVUE
1.JSON学习 1.概念: JSON是把JS对象变成字符串. 2.作用: 多用于网络中数据传输. JavaScript对象 let person{name:"张三",age:18}//将JS对象转换为 JSON数据let person2JSON{"name":"张三","age":18}; 3.JS对象与JSON字符串转换…...
OSCP靶机--Medjed
OSCP靶机–Medjed 考点:(1.ftp文件上传 2.sql注入写shell 3.第三软件提权) 1.nmap ┌──(root㉿kali)-[~/Desktop] └─# nmap 192.168.200.127 -sV -sC -p- --min-rate 5000 Starting Nmap 7.92 ( https://nmap.org ) at 2024-02-25 19:42 EST Nmap scan repo…...
【Unity】Unity与安卓交互
问题描述 Unity和安卓手机进行交互,是我们开发游戏中最常见的场景。本教程将从一个简单的例子来演示一下。 本教程需要用到Android Studio2021.1.1 1.Android Studio新建一个工程 2.选择Empty Activity 然后点击Next 3.点击Finish完成创建 4.选择File-New-New Mo…...
QYFB-02 无线风力报警仪 风速风向超限声光报警
产品概述 无线风力报警仪是由测控报警仪、无线风速风向传感器和太阳能供电盒组成,可观测大气中的瞬时风速,具有风速报警设定和报警输出控制功能;风力报警仪采用无线信号传输、显示屏输出,风速显示采用高亮LED数码管显示ÿ…...
css知识:盒模型盒子塌陷BFC
1. css盒模型 标准盒子模型,content-box 设置宽度即content的宽度 width content 总宽度content(width设定值) padding border IE/怪异盒子模型,border-box width content border padding 总宽度 width设定值 2. 如何…...
Nginx的反向代理:实现灵活的请求转发和内容缓存
一、引言:代理服务器的简介 本节介绍代理服务器的基本配置。学习如何通过不同协议将 NGINX 请求传递给代理的服务器,修改发送到代理服务器的客户端请求标头,以及配置来自代理服务器的响应缓冲。 代理通常用于在多个服务器之间分配负载&…...
免费享受企业级安全:雷池社区版WAF,高效专业的Web安全的方案
网站安全成为了每个企业及个人不可忽视的重要议题。 随着网络攻击手段日益狡猾和复杂,选择一个强大的安全防护平台变得尤为关键。 推荐的雷池社区版——一个为网站提供全面安全防护解决方案的平台,它不仅具备高效的安全防护能力,还让网站安…...
基于SpringBoot的航班进出港管理系统
文章目录 项目介绍主要功能截图:部分代码展示设计总结项目获取方式 🍅 作者主页:超级无敌暴龙战士塔塔开 🍅 简介:Java领域优质创作者🏆、 简历模板、学习资料、面试题库【关注我,都给你】 &…...
Odoo系统安装部署并结合内网穿透实现固定域名访问本地ERP系统
文章目录 前言1. 下载安装Odoo:2. 实现公网访问Odoo本地系统:3. 固定域名访问Odoo本地系统 前言 Odoo是全球流行的开源企业管理套件,是一个一站式全功能ERP及电商平台。 开源性质:Odoo是一个开源的ERP软件,这意味着企…...
幻兽帕鲁(Palworld 1.4.1)私有服务器搭建(docker版)
文章目录 说明客户端安装服务器部署1Panel安装和配置docker服务初始化设置设置开机自启动设置镜像加速 游戏服务端部署游戏服务端参数可视化配置 Palworld连接服务器问题总结 说明 服务器硬件要求:Linux系统/Window系统(x86架构,armbian架构…...
好书推荐丨细说Python编程:从入门到科学计算
文章目录 写在前面Python简介推荐图书内容简介编辑推荐作者简介 推荐理由粉丝福利写在最后 写在前面 本期博主给大家推荐一本Python基础入门的全新正版书籍,对Python、机器学习、人工智能感兴趣的小伙伴们快来看看吧~ Python简介 Python 是一种广泛使用的高级、解…...
以下是对华为 HarmonyOS NETX 5属性动画(ArkTS)文档的结构化整理,通过层级标题、表格和代码块提升可读性:
一、属性动画概述NETX 作用:实现组件通用属性的渐变过渡效果,提升用户体验。支持属性:width、height、backgroundColor、opacity、scale、rotate、translate等。注意事项: 布局类属性(如宽高)变化时&#…...
376. Wiggle Subsequence
376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...
postgresql|数据库|只读用户的创建和删除(备忘)
CREATE USER read_only WITH PASSWORD 密码 -- 连接到xxx数据库 \c xxx -- 授予对xxx数据库的只读权限 GRANT CONNECT ON DATABASE xxx TO read_only; GRANT USAGE ON SCHEMA public TO read_only; GRANT SELECT ON ALL TABLES IN SCHEMA public TO read_only; GRANT EXECUTE O…...
【C++从零实现Json-Rpc框架】第六弹 —— 服务端模块划分
一、项目背景回顾 前五弹完成了Json-Rpc协议解析、请求处理、客户端调用等基础模块搭建。 本弹重点聚焦于服务端的模块划分与架构设计,提升代码结构的可维护性与扩展性。 二、服务端模块设计目标 高内聚低耦合:各模块职责清晰,便于独立开发…...
有限自动机到正规文法转换器v1.0
1 项目简介 这是一个功能强大的有限自动机(Finite Automaton, FA)到正规文法(Regular Grammar)转换器,它配备了一个直观且完整的图形用户界面,使用户能够轻松地进行操作和观察。该程序基于编译原理中的经典…...
HarmonyOS运动开发:如何用mpchart绘制运动配速图表
##鸿蒙核心技术##运动开发##Sensor Service Kit(传感器服务)# 前言 在运动类应用中,运动数据的可视化是提升用户体验的重要环节。通过直观的图表展示运动过程中的关键数据,如配速、距离、卡路里消耗等,用户可以更清晰…...
JS设计模式(4):观察者模式
JS设计模式(4):观察者模式 一、引入 在开发中,我们经常会遇到这样的场景:一个对象的状态变化需要自动通知其他对象,比如: 电商平台中,商品库存变化时需要通知所有订阅该商品的用户;新闻网站中࿰…...
Linux 内存管理实战精讲:核心原理与面试常考点全解析
Linux 内存管理实战精讲:核心原理与面试常考点全解析 Linux 内核内存管理是系统设计中最复杂但也最核心的模块之一。它不仅支撑着虚拟内存机制、物理内存分配、进程隔离与资源复用,还直接决定系统运行的性能与稳定性。无论你是嵌入式开发者、内核调试工…...
LangChain知识库管理后端接口:数据库操作详解—— 构建本地知识库系统的基础《二》
这段 Python 代码是一个完整的 知识库数据库操作模块,用于对本地知识库系统中的知识库进行增删改查(CRUD)操作。它基于 SQLAlchemy ORM 框架 和一个自定义的装饰器 with_session 实现数据库会话管理。 📘 一、整体功能概述 该模块…...
使用LangGraph和LangSmith构建多智能体人工智能系统
现在,通过组合几个较小的子智能体来创建一个强大的人工智能智能体正成为一种趋势。但这也带来了一些挑战,比如减少幻觉、管理对话流程、在测试期间留意智能体的工作方式、允许人工介入以及评估其性能。你需要进行大量的反复试验。 在这篇博客〔原作者&a…...
