当前位置:网站首页>2020 数学建模之旅
2020 数学建模之旅
2022-07-30 05:50:00 【HW-Header】
在三天的数学建模比赛中,本人是第二天中午才过去参加比赛(其实就是帮另外一个没有去的学长顶包)。在此之前,还没有过一次实战的经验,不过庆幸的是,有两个强大的队友,还有指导老师和学长的细心指导,勉强获得了市级二等奖,从此开启了我的数学建模之旅。
赛题
我们团队选择的C题,C题主要是通过对原始数据的清洗整理,建立预测模型,再把需要预测的数据扔入预测模型中预测信誉等级,最后根据每个企业的信誉等级给出银行对这些企业的信贷策略,从而获取最终的求解。
数据的整理
本题的数据量是相当大的,总共的数据条数已超百万。如果说在哪个时候最后体会出电脑配置跟不上上,那肯定就是对数据进行分类汇总时,我还深深地记得,在对数据第一次按企业代号
分类时,速度还算快,五分钟分钟左右就好了,但在第一次分类汇总的基础上,再按发票状态
进行分类汇总时,要跑半个小时以上,而且电脑明显卡顿,什么事情都不敢做。
在分类汇总过程中,速度特别慢,而且经常卡死,无奈之后,用上了老师的企业级服务器。不得不说服务器就是好,速度明显快很多,而且不存在突然卡死的情况。在一天的反复折腾下,突然完成了数据的整理。
题2:预测模型的建立
我们团队主要是采用了CatBoost算法,它是俄罗斯的搜索巨头Y andex在2017年开源的机器学习库,也是Boosting族算法的一种。基于 CatBoost 中的多分类方法将 70%的数据放入训练集中,30%的数据放入验证集中,对附件一的原始数据进行整理得到 money、void_radio、negative_radio、breach_of_contract、emergencies、credit_rank 这个六个属性,并建立预测模型。
from catboost import CatBoostClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
X_train, X_validation, y_train, y_validation = train_test_split(in_df.iloc[:,:-1], in_df["credit_rank"],test_size=0.3 , random_state=1234)
categorical_features_indices = np.where(X_train.dtypes != np.float)[0]
model = CatBoostClassifier(iterations=100, depth=7,cat_features=categorical_features_indices, learning_rate=0.1, loss_function='MultiClass',logging_level='Verbose')
model.fit(X_train, y_train, eval_set=(X_validation, y_validation), plot=True) # 进行训练
# 评估
print('accuracy:', model.score(X_train, y_train))
# 保存模型
model.save_model("D:/111/2catboostmodel.model")
# 分析各因素的重要比重
fea_ = model.feature_importances_
fea_name = model.feature_names_
plt.figure(figsize=(10, 10))
plt.barh(fea_name,fea_,height =0.5)
基于 CatBoost 算法的信贷决策模型预测出 money、void_radio、negative_radio、breach_of_contract、emergencies 对 credit_rank 的影响程度,如下图所示:
题2:预测信誉等级
from catboost import CatBoostClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
# 加载模型
model = CatBoostClassifier()
model.load_model('D:/111/2catboostmodel.model')
in_df = pd.read_excel("D:/111/2附件2:302家无信贷记录企业的相关数据.xlsx", sheet_name="分析表")
dataList = in_df.iloc[:, :-1].values
credit_rank_list = []
# 把数据数组中的数据全部转为字符性数据
for i in range(len(dataList)):
# 预测信誉等级
credit_rank = model.predict([str(dataList[i][0]), str(dataList[i][1]), str(dataList[i][2]), str(dataList[i][3]), str(dataList[i][4]), str(dataList[i][5])])[0] # in_df.iloc[:,:-1].values[1]
credit_rank_list.append(credit_rank)
data = pd.DataFrame(credit_rank_list)
data.to_csv("d://111/2credit_rank.csv",index=True,sep=',')
题3:预测模型的建立
在问题二的模型基础上,新增产业类别,将其数值化,变量值分别设为 2、3,同时考虑重大突发事件带来的影响,将变量值设为 0、1(0 表示无影响,1 表示有影响),因为附件二中并未给出是否违的情况,所以将 breach_of_contract 的变量值置为 1。将 money、void_radio、negative_radio、breach_of_contract、emergencies、industry_type 这六个属性做为模型输入,建立预测模型,预测这六个属性对信誉等级的影响程度。
from catboost import CatBoostClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
in_df = pd.read_excel("D:/111/3附件1:123家有信贷记录企业的相关数据.xlsx", sheet_name="分析表")
X_train, X_validation, y_train, y_validation = train_test_split(in_df.iloc[:,:-1], in_df["credit_rank"],test_size=0.3 , random_state=1234)
categorical_features_indices = np.where(X_train.dtypes != np.float)[0]
model = CatBoostClassifier(iterations=100, depth=7,cat_features=categorical_features_indices, learning_rate=0.1, loss_function='MultiClass',logging_level='Verbose')
model.fit(X_train, y_train, eval_set=(X_validation, y_validation), plot=True) # 进行训练
# 评估
print('accuracy:', model.score(X_train, y_train))
# 保存模型
model.save_model("D:/111/3catboostmodel.model")
# 分析各因素的重要比重
fea_ = model.feature_importances_
fea_name = model.feature_names_
plt.figure(figsize=(10, 10))
plt.barh(fea_name,fea_,height =0.5)
将 money、void_radio、negative_radio、breach_of_contract、emergencies、industry_type 这六个属性放入模型中进行预测,预测这六个属性对信誉等级的影响程度。
题3:预测信誉等级
from catboost import CatBoostClassifier
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
# 加载模型
model = CatBoostClassifier()
model.load_model('D:/111/3catboostmodel.model')
in_df = pd.read_excel("D:/111/3附件2:302家无信贷记录企业的相关数据.xlsx", sheet_name="分析表")
dataList = in_df.iloc[:, :-1].values
credit_rank_list = []
# 把数据数组中的数据全部转为字符性数据
for i in range(len(dataList)):
# 预测信誉等级
credit_rank = model.predict([str(dataList[i][0]), str(dataList[i][1]), str(dataList[i][2]), str(dataList[i][3]), str(dataList[i][4]), str(dataList[i][5])])[0] # in_df.iloc[:,:-1].values[1]
credit_rank_list.append(credit_rank)
data = pd.DataFrame(credit_rank_list)
data.to_csv("d://111/3credit_rank.csv",index=True,sep=',')
最终预测的结果
题2:
题3:
根据预测的荣誉等级制定信贷策略
题2:在原有 A、B、C、D 四个信誉等级(上面预测信誉等级数字化过:ABCD等级分别为1234)的基础上进一步细分为 AA、A、BB、B、C、DD、D 这 7 个信誉等级。细分标准为:因为附件二中并未给出是否违约的情况,所以直接考虑第二因素 money,如果 money 相同,则考虑 negative_radio,以此类推,将 302 家企业进行排序并进行等级划分,其中 AA、A、BB、B、C 五个等级分别占 14.24%,DD 等级占 14.9%,D 等级占 13.9%。
题3:因为新增了产业类别,以及考虑重大突发事件带来的影响,所以对企业的信誉评级进行重新评估,细分标准为:在未给出是否违约的情况,直接考虑因素 money,如果 money 相同,则考虑 void_radio,以此类推,将 302 家企业重新进行综合排序以及等级划分。并作出如下决策:
总结
这一次数学建模过程中,短短的二天半时间,让我学习到了很多东西,瞬间对数学建模有了一个比较清晰的认识,提高了自身的建模能力,越发地爱上了数学建模。感谢我那辛勤努力的二位小姐姐,在我最开始没有来之前,她们二个人非常辛苦,也感谢我的指导老师和学长的细心指导,让我们能有一个正确的方向。希望自己以本次数学建模为基础,继续努力,争取在下一次数学建模中,拿到更好的结果。
边栏推荐
- debian problem
- STL源码剖析:bound friend template friend代码测试和理解
- idea built-in translation plugin
- RAID磁盘阵列
- What happens when @Bean and @Component are used on the same class?
- 人工肌肉智能材料新突破
- New material under the plastic restriction order - polylactic acid (PLA)
- 软件测试开发:发送第一封测试报告邮件
- 舒尔补(schur completement)
- 阿里一面:多线程顺序运行有多少种方法?
猜你喜欢
idea built-in translation plugin
MySQL什么时候用表锁,什么时候用行锁?
Network Protocol 03 - Routing and NAT
How to understand plucker coordinates (geometric understanding)
Network Protocol 01 - Basic Concepts
Required request body is missing 问题解决
引导过程与服务控制
Distance calculation from space vertex to straight line and its source code
向量三重积的等式推导证明
和AI一起玩儿剧本杀:居然比我还入戏
随机推荐
LVM和磁盘配额
What new materials are used in the large aircraft C919?
prometheus-basic_auth加密配置
Test Development Engineer Growth Diary 003 - Interface Automation Framework Construction
debian problem
阿里二面:列出 Api 接口优化的几个技巧
MySQL什么时候用表锁,什么时候用行锁?
Required request body is missing 问题解决
手机端滚动至页面指定位置
schur completement
删除openstack中的僵尸实例
Multithreading basics (multithreaded memory, security, communication, thread pools and blocking queues)
How to use Swagger, say goodbye to postman
Proof of distance calculation from space vertex to plane and its source code
预测人们对你的第一印象,“AI颜狗”的诞生
软件测试开发:发送第一封测试报告邮件
Let the "label" content in Baidu map generator expand--solution
舒尔补(schur completement)
STL源码剖析:class template explicit specialization代码测试和理解
Test Development Engineer Growth Diary 015 - Top 20 Test Interview Questions