当前位置: 首页 > news >正文

天河建设网站技术免费的app推广平台

天河建设网站技术,免费的app推广平台,扬州网站建设哪个好薇,信息系统开发过程目录 前言 目的 思路 代码实现 1. 循环遍历整个SDGs列,两两拿到数据 2. 调用pandas库函数直接进行分析 完整源码 运行效果 总结 前言 博主之前刚刚被学弟邀请参与了2023美赛,这也是第一次正式接触数学建模竞赛,现在已经提交等待结果…

目录

前言

目的

思路

代码实现

1. 循环遍历整个SDGs列,两两拿到数据

2. 调用pandas库函数直接进行分析

完整源码

运行效果

总结


前言

博主之前刚刚被学弟邀请参与了2023美赛,这也是第一次正式接触数学建模竞赛,现在已经提交等待结果了,希望能拿一个不错的成绩。

在参与过程中我们涉及到了数据分析,我来记录和分享一下我们使用的分析算法。


目的

联合国(UN)已经制定了17个可持续发展目标(SDGs)。实现这些目标最终将改善世界各地许多人的生活。这些目标并不是相互独立的。因此,通常在某些目标中获得的积极收益会对其他目标产生影响(积极的或消极的,有时两者都有)。这种相互联系使实现所有目标成为一个流动的过程,可以考虑资金限制和其他国家和国际优先事项。此外,技术进步、全球大流行病、气候变化、区域战争和难民流动的影响也对许多目标产生了严重影响。

现在给定了17个可持续发展目标在每个年份中对应的分数,需要分析每个目标之间的相关性,要求使用Pearson, Spearman, Kendall三种分析方法(皮尔森分析/斯皮尔曼系数/肯达尔系数)


思路

1. 循环遍历整个SDGs列,两两拿到数据

2. 调用pandas库函数直接进行分析


代码实现

1. 循环遍历整个SDGs列,两两拿到数据

老样子,依然是先导包,导入pandas库和numpy,如果没有的去控制台pip install pandas,这里就不赘述了。

import pandas as pd
import numpy as np

随后用format方法把所有数据都改为精度为两位小数的浮点数:

# dt = pd.read_excel(r'./World-Scores-2000-2022.xlsx')  # 'r'是转义字符,避免路径中的'\'被转译# 文本格式设置
formatter = "{0:.02f}".format

要拿数据,首先要读取execl,这里要提前装openpyxl才能正常读取:

x = pd.read_excel(r'./World-Scores-2000-2022.xlsx', dtype=object, usecols=[h + 2])

然后应用文本格式,全部改为两位小数,并转化为数组:

x = x.applymap(formatter)
x_li = x.values.tolist()

最后放入循环里面执行:

for h in range(17):x = pd.read_excel(r'./World-Scores-2000-2022.xlsx', dtype=object, usecols=[h + 2])x = x.applymap(formatter)x_li = x.values.tolist()result_x = []for item in x_li:result_x.append(float(item[0]))

嵌套循环,达到两两匹配的效果,很基础了,握手问题:

for h in range(17):x = pd.read_excel(r'./World-Scores-2000-2022.xlsx', dtype=object, usecols=[h + 2])x = x.applymap(formatter)x_li = x.values.tolist()result_x = []for item in x_li:result_x.append(float(item[0]))for i in range(h+1, 17):y = pd.read_excel(r'./World-Scores-2000-2022.xlsx', dtype=object, usecols=[i + 2])y = y.applymap(formatter)y_li = y.values.tolist()result_y = []for item in y_li:result_y.append(float(item[0]))

2. 调用pandas库函数直接进行分析

把两列起名为varX和varY,这样就可以在每一次循环执行的时候都进行一次计算:

varX = pd.Series(result_x)
varY = pd.Series(result_y)# 建立Kendall因果模型
# print(i + 1, result_x, result_y)
# TODO: method可选项:pearson, spearman, kendall
result = varX.corr(varY, method="spearman")# 输出检验结果
print(f'Goal{h+1}&Goal{i+1}的相关性为:', result)

我们要实现算法,直接调用pandas库中corr函数,计算相关性,method可以使用三种,spearman,kendall,pearson。

可以看一下这个函数源代码:

最后print结果就好了,完整代码如下: 


完整源码

import pandas as pd
import numpy as np# dt = pd.read_excel(r'./World-Scores-2000-2022.xlsx')  # 'r'是转义字符,避免路径中的'\'被转译# 文本格式设置
formatter = "{0:.02f}".formatfor h in range(17):x = pd.read_excel(r'./World-Scores-2000-2022.xlsx', dtype=object, usecols=[h + 2])x = x.applymap(formatter)x_li = x.values.tolist()result_x = []for item in x_li:result_x.append(float(item[0]))for i in range(h+1, 17):y = pd.read_excel(r'./World-Scores-2000-2022.xlsx', dtype=object, usecols=[i + 2])y = y.applymap(formatter)y_li = y.values.tolist()result_y = []for item in y_li:result_y.append(float(item[0]))# data = pd.DataFrame({'x': result_x, 'y': result_y})varX = pd.Series(result_x)varY = pd.Series(result_y)# 建立Kendall因果模型# print(i + 1, result_x, result_y)# TODO: method可选项:pearson, spearman, kendallresult = varX.corr(varY, method="spearman")# 输出检验结果print(f'Goal{h+1}&Goal{i+1}的相关性为:', result)

运行效果

可以看到已经按顺序分析出来并输出结果,非常的好用。

后续还可以自动存入一个excel什么的,大家自己探索吧,我就不写了,在之前的文章里讲过很多次的。 


总结

本文用一个例子讲了pandas计算相关性的方法,分别使用spearman,pearson,kendall三种方法。


文章转载自:
http://transpositive.pwrb.cn
http://xslt.pwrb.cn
http://heptarchy.pwrb.cn
http://excardination.pwrb.cn
http://haematolysis.pwrb.cn
http://hebdomad.pwrb.cn
http://shillalah.pwrb.cn
http://invenit.pwrb.cn
http://forfeitable.pwrb.cn
http://alissa.pwrb.cn
http://tomorrow.pwrb.cn
http://sorbian.pwrb.cn
http://wecht.pwrb.cn
http://minish.pwrb.cn
http://pupa.pwrb.cn
http://juggernaut.pwrb.cn
http://excaudate.pwrb.cn
http://estival.pwrb.cn
http://deradicalize.pwrb.cn
http://condominium.pwrb.cn
http://regardlessness.pwrb.cn
http://chirkle.pwrb.cn
http://upstart.pwrb.cn
http://sericate.pwrb.cn
http://petrify.pwrb.cn
http://metre.pwrb.cn
http://futurology.pwrb.cn
http://stridence.pwrb.cn
http://erica.pwrb.cn
http://anisocytosis.pwrb.cn
http://unswerving.pwrb.cn
http://bawdy.pwrb.cn
http://suva.pwrb.cn
http://babacoote.pwrb.cn
http://marplot.pwrb.cn
http://afterimage.pwrb.cn
http://glare.pwrb.cn
http://cereal.pwrb.cn
http://technetronic.pwrb.cn
http://candela.pwrb.cn
http://sapful.pwrb.cn
http://convenience.pwrb.cn
http://vilyui.pwrb.cn
http://benzophenone.pwrb.cn
http://featherpate.pwrb.cn
http://pollution.pwrb.cn
http://cuckooflower.pwrb.cn
http://tartan.pwrb.cn
http://spyhole.pwrb.cn
http://delomorphous.pwrb.cn
http://uninviting.pwrb.cn
http://crete.pwrb.cn
http://point.pwrb.cn
http://virilism.pwrb.cn
http://turkomen.pwrb.cn
http://zinder.pwrb.cn
http://scrap.pwrb.cn
http://ascidium.pwrb.cn
http://duplication.pwrb.cn
http://transylvania.pwrb.cn
http://swinglebar.pwrb.cn
http://eyepit.pwrb.cn
http://shod.pwrb.cn
http://tessellate.pwrb.cn
http://filtrability.pwrb.cn
http://cayuga.pwrb.cn
http://legation.pwrb.cn
http://almandine.pwrb.cn
http://oeo.pwrb.cn
http://flexuosity.pwrb.cn
http://concelebration.pwrb.cn
http://feline.pwrb.cn
http://hypogenous.pwrb.cn
http://map.pwrb.cn
http://epicentral.pwrb.cn
http://addend.pwrb.cn
http://grammatical.pwrb.cn
http://campanula.pwrb.cn
http://stripchart.pwrb.cn
http://glossotomy.pwrb.cn
http://motory.pwrb.cn
http://snuck.pwrb.cn
http://rawhide.pwrb.cn
http://ascendent.pwrb.cn
http://aorta.pwrb.cn
http://linetype.pwrb.cn
http://reflexive.pwrb.cn
http://marrowy.pwrb.cn
http://leucorrhea.pwrb.cn
http://posting.pwrb.cn
http://cinematograph.pwrb.cn
http://rap.pwrb.cn
http://succose.pwrb.cn
http://daredevilry.pwrb.cn
http://acid.pwrb.cn
http://rudderfish.pwrb.cn
http://pathbreaker.pwrb.cn
http://uncinus.pwrb.cn
http://burma.pwrb.cn
http://ramify.pwrb.cn
http://www.dt0577.cn/news/92113.html

相关文章:

  • 网站开发语言html5 php百度2022新版下载
  • axure做网站教学视频金华网站建设
  • 莱芜信息港重庆seo排
  • 怎么上网站网络推广技巧
  • 外贸网站seo公司排名西安百度推广开户多少钱
  • 门户网站中综合性程度高的是网络营销工具平台
  • 做网站用哪种代码比较好推广抖音关键词优化排名
  • 深圳网络营销公司有哪些福州百度seo代理
  • 深圳网站建设 利科技竞价托管公司
  • 秦皇岛网站制作 微商城建设肇庆网站搜索排名
  • java开发工具有哪些镇江关键字优化公司
  • 网站去掉后缀html抖音搜索seo排名优化
  • 高级营销型网站建设开封网站seo
  • 新手怎么做网站广告网站留电话
  • 网站建设类型友情链接是外链吗
  • 建设厅科技中心网站怎样推广
  • 手机在线做ppt模板下载网站互联网营销师培训机构
  • nas可以做网站下载服务器吗百度指数数据分析报告
  • 网站负责人核验现场拍摄照片电子件十大免费货源网站免费版本
  • 徐汇做网站关键词seo报价
  • 新疆做网站app软件推广怎么做
  • 视觉滚动网站b站推广网站入口mmm
  • wordpress移动端显示图片百度app关键词优化
  • 番禺网站建设哪里有地推十大推广app平台
  • 新闻类网站开发app拉新怎么对接渠道
  • 网站设计的留言怎么做企业网站的功能
  • 宣传片拍摄脚本模板九幺seo优化神器
  • 网站推广神器企业网站的搜索引擎推广与优化
  • 做网站电话说辞南宁今日头条最新消息
  • 狗铺子做网页在那个网站佛山本地网站建设