当前位置:网站首页>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
边栏推荐
- P1451 求细胞数量/1329:【例8.2】细胞
- Machine learning notes - gray wolf optimization
- Crud of MySQL
- 计算中间件 Apache Linkis参数解读
- MySQL之CRUD
- [12 classic written questions of array and advanced pointer] these questions meet all your illusions about array and pointer, come on!
- 用 Go 跑的更快:使用 Golang 为机器学习服务
- Stm32+bh1750 photosensitive sensor obtains light intensity
- 【NVMe2.0b 14-9】NVMe SR-IOV
- Using tensorboard to visualize the training process in pytoch
猜你喜欢
如何将电脑复制的内容粘贴进MobaXterm?如何复制粘贴
Ctfshow web entry information collection
基于TI DRV10970驱动直流无刷电机
There is a powerful and good-looking language bird editor, which is better than typora and developed by Alibaba
Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
CPU设计相关笔记
数据库学习——数据库安全性
Interview shock 62: what are the precautions for group by?
MongDB学习笔记
超级哇塞的快排,你值得学会!
随机推荐
漫画:程序员不是修电脑的!
Run faster with go: use golang to serve machine learning
黑马程序员-软件测试-10阶段2-linux和数据库-44-57为什么学习数据库,数据库分类关系型数据库的说明Navicat操作数据的说明,Navicat操作数据库连接说明,Navicat的基本使用,
Type declaration of all DOM elements in TS
12 MySQL interview questions that you must chew through to enter Alibaba
1330:【例8.3】最少步数
Cartoon: programmers don't repair computers!
CPU design related notes
可转债打新在哪里操作开户是更安全可靠的呢
Reconnaissance des caractères easycr
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
PostgreSQL 13 installation
[summary of leetcode weekly competition] the 81st fortnight competition of leetcode (6.25)
Change multiple file names with one click
CPU design practice - Chapter 4 practice task 3 use pre delivery technology to solve conflicts caused by related issues
当代人的水焦虑:好水究竟在哪里?
Talk about your understanding of microservices (PHP interview theory question)
How to open an account of qiniu securities? Is it safe to open an account?
Stm32+bh1750 photosensitive sensor obtains light intensity