当前位置:网站首页>Calculate weight and comprehensive score by R entropy weight method
Calculate weight and comprehensive score by R entropy weight method
2022-07-05 15:04:00 【See the sea for the first time】
In recent work, we need to calculate intelligently according to big data , Predict or recommend supply chain payment priority / Power comes back , In the past, it was a priority to make payment manually according to factors such as supplier relationship , It cannot objectively distribute payment strategies to other suppliers , Now it is calculated objectively according to big data , Make a note of
1, get data
Get data from starRocks,
library(RMySQL)
library(tibble)
library(dplyr)
criterions_cite <- function(){
# Establishing a connection ,project_name Represents the name of the project database
conn <- dbConnect(MySQL(), dbname = 'ods', username = 'pxxx', password = 'xxx', host = 'xx.xx.xx.xx', port = 9030)
# If there is Chinese garbled in the table , You can add the following code
#dbSendQuery(conn, 'SET NAMES GBK')
#sheet_name Indicates the name of the table to be read
filter_statements <- paste0('SELECT * FROM ods_fkyc_local')
# Filtering data
res <- dbSendQuery(conn, filter_statements)
# Extract the data ,-1 It means extract all ,3 It means taking three rows of data
dat <- dbFetch(res, -1)
# close RMySQL Data set in
dbClearResult(dbListResults(conn)[[1]])
# Close the connection
dbDisconnect(conn)
return(dat)
}
# Get the data set from the database
mydt <- criterions_cite()
tb.mydt <- as_tibble(mydt)
2, Specify the positive , Negative indicators
Like sales , The larger the negative selling amount, the better it can be specified as a positive indicator
Like defective inventory , Unsalable inventory , Amount in arrears This kind of index is about as few as possible, and it is designated as a negative index
# 1, normalization , Positive indicators
min_max_norm <- function(x) {
(x - min(x)) / (max(x) - min(x))
}
# Negative indicators
max_min_norm <- function(x) {
(max(x) - x) / (max(x) - min(x))
}
# normalization , First deal with positive indicators
min_max_norm_mydt <- tb.mydt %>% mutate(across(c(9,13,14), min_max_norm))
# Then deal with the negative indicators first
max_min_norm_mydt <- min_max_norm_mydt %>% mutate(across(c(10,11,12), max_min_norm))
3, Calculate the index after normalization
p_value <- function(x){
x / sum(x)
}
p_mydt <- max_min_norm_mydt %>% mutate(across(c(9:14), p_value))
## Calculate the entropy
entropy <- function(x){
n <- length(x)
(-1 / log2(n)) * (sum( x * ifelse(log2(x)==-Inf, 0, log2(x)) ))
}
e_mydt <- p_mydt %>% summarise(across(c(9:14), entropy))
e_mydt
d_mydt = 1-e_mydt
d_mydt
w = d_mydt/sum(d_mydt)
w
w And is the weight
4, Then calculate the comprehensive score and rank , Then export
fscore <- function(x, y){
sum(x*y)
}
old_data <- rename(tb.mydt[,9:14],c(old_ZPO_K001_sum="ZPO_K001_sum",old_zpo_k006_sum="zpo_k006_sum",old_zx0030_sum="zx0030_sum",old_fyjj201to03_sum="fyjj201to03_sum",old_wpfm_sum="wpfm_sum",old_total_amount="total_amount"))
result_data=cbind(max_min_norm_mydt,old_data)
mydt3 <- result_data %>% group_by(1:n()) %>% mutate(score = fscore(c_across(9:14), w)) %>% arrange(-score) %>% ungroup() %>% select("com_code","organization_name","lifnr","name1","dept_no","dept_name","brand_code","brand_name","ZPO_K001_sum","zpo_k006_sum","zx0030_sum","fyjj201to03_sum","wpfm_sum","total_amount","old_ZPO_K001_sum","old_zpo_k006_sum","old_zx0030_sum","old_fyjj201to03_sum","old_wpfm_sum","old_total_amount","score")
write.table(mydt3, file = "/app/bigdata_app/data/fkyc/MyData.csv",quote = FALSE,row.names=FALSE, col.names=FALSE)
Export the calculated data csv file , and streamload Into the starRocks in
边栏推荐
- useMemo,memo,useRef等相关hooks详解
- Coding devsecops helps financial enterprises run out of digital acceleration
- maxcompute有没有能查询 表当前存储容量的大小(kb) 的sql?
- [detailed explanation of Huawei machine test] happy weekend
- Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
- Machine learning notes - gray wolf optimization
- Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de
- Long list optimized virtual scrolling
- [summary of leetcode weekly competition] the 81st fortnight competition of leetcode (6.25)
- Isn't it right to put money into the external market? How can we ensure safety?
猜你喜欢
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
Fr exercise topic --- comprehensive question
CODING DevSecOps 助力金融企业跑出数字加速度
Crud of MySQL
数据库学习——数据库安全性
Coding devsecops helps financial enterprises run out of digital acceleration
MySQL之CRUD
华为哈勃化身硬科技IPO收割机
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
随机推荐
安装配置Jenkins
Using tensorboard to visualize the training process in pytoch
PyTorch二分类时BCELoss,CrossEntropyLoss,Sigmoid等的选择和使用
sql server学习笔记
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
Super wow fast row, you are worth learning!
Stm32+bh1750 photosensitive sensor obtains light intensity
CODING DevSecOps 助力金融企业跑出数字加速度
计算中间件 Apache Linkis参数解读
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
华为哈勃化身硬科技IPO收割机
手写promise与async await
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
外盘入金都不是对公转吗,那怎么保障安全?
[detailed explanation of Huawei machine test] character statistics and rearrangement
浅谈Dataset和Dataloader在加载数据时如何调用到__getitem__()函数