预测脱碳企业的信用评级-论文代码复现
文献来源
【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 是一种广泛使用的高级、解…...
基于ASP.NET+ SQL Server实现(Web)医院信息管理系统
医院信息管理系统 1. 课程设计内容 在 visual studio 2017 平台上,开发一个“医院信息管理系统”Web 程序。 2. 课程设计目的 综合运用 c#.net 知识,在 vs 2017 平台上,进行 ASP.NET 应用程序和简易网站的开发;初步熟悉开发一…...
屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!
5月28日,中天合创屋面分布式光伏发电项目顺利并网发电,该项目位于内蒙古自治区鄂尔多斯市乌审旗,项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站,总装机容量为9.96MWp。 项目投运后,每年可节约标煤3670…...
Rapidio门铃消息FIFO溢出机制
关于RapidIO门铃消息FIFO的溢出机制及其与中断抖动的关系,以下是深入解析: 门铃FIFO溢出的本质 在RapidIO系统中,门铃消息FIFO是硬件控制器内部的缓冲区,用于临时存储接收到的门铃消息(Doorbell Message)。…...
Axure 下拉框联动
实现选省、选完省之后选对应省份下的市区...
JDK 17 序列化是怎么回事
如何序列化?其实很简单,就是根据每个类型,用工厂类调用。逐个完成。 没什么漂亮的代码,只有有效、稳定的代码。 代码中调用toJson toJson 代码 mapper.writeValueAsString ObjectMapper DefaultSerializerProvider 一堆实…...
Axure零基础跟我学:展开与收回
亲爱的小伙伴,如有帮助请订阅专栏!跟着老师每课一练,系统学习Axure交互设计课程! Axure产品经理精品视频课https://edu.csdn.net/course/detail/40420 课程主题:Axure菜单展开与收回 课程视频:...
机器学习复习3--模型评估
误差与过拟合 我们将学习器对样本的实际预测结果与样本的真实值之间的差异称为:误差(error)。 误差定义: ①在训练集上的误差称为训练误差(training error)或经验误差(empirical error&#x…...
ubuntu系统 | docker+dify+ollama+deepseek搭建本地应用
1、docker 介绍与安装 docker安装:1、Ubuntu系统安装docker_ubuntu docker run-CSDN博客 docker介绍及镜像源配置:2、ubuntu系统docker介绍及镜像源和仓库配置-CSDN博客 docker常用命令:3、ubuntu系统docker常用命令-CSDN博客 docker compose安装:4、docker compose-CS…...
小白的进阶之路系列之十四----人工智能从初步到精通pytorch综合运用的讲解第七部分
通过示例学习PyTorch 本教程通过独立的示例介绍PyTorch的基本概念。 PyTorch的核心提供了两个主要特性: 一个n维张量,类似于numpy,但可以在gpu上运行 用于构建和训练神经网络的自动微分 我们将使用一个三阶多项式来拟合问题 y = s i n ( x ) y=sin(x) y=sin(x),作为我们的…...
【NLP】 38. Agent
什么是 Agent? 一个 Agent 就是能够 理解、思考,并且进行世界交互 的模型系统,并不是纯粹的 prompt 返回器。 它可以: 读取外部数据(文件/API)使用记忆进行上下文维持用类Chain-of-Thought (CoT)方式进行…...
