# 教你用Python解锁“吃鸡”的正确姿势！

``` 1import numpy as np
2import matplotlib.pyplot as plt
3import pandas as pd
4import seaborn as sns
6import matplotlib.cm as cm
7
8#导入部分数据
11
12deaths = pd.concat([deaths1, deaths2])
13
14#打印前5列，理解变量
16
17#两种地图
18miramar = deaths[deaths["map"] == "MIRAMAR"]
19erangel = deaths[deaths["map"] == "ERANGEL"]
20
21#开局前100秒死亡热力图
22position_data = ["killer_position_x","killer_position_y","victim_position_x","victim_position_y"]
23for position in position_data:
24    miramar[position] = miramar[position].apply(lambda x: x*1000/800000)
25    miramar = miramar[miramar[position] != 0]
26
27    erangel[position] = erangel[position].apply(lambda x: x*4096/800000)
28    erangel = erangel[erangel[position] != 0]
29
30n = 50000
31mira_sample = miramar[miramar["time"] < 100].sample(n)
32eran_sample = erangel[erangel["time"] < 100].sample(n)
33
34# miramar热力图
36fig, ax = plt.subplots(1,1,figsize=(15,15))
37ax.imshow(bg)
38sns.kdeplot(mira_sample["victim_position_x"], mira_sample["victim_position_y"],n_levels=100, cmap=cm.Reds, alpha=0.9)
39
40# erangel热力图
42fig, ax = plt.subplots(1,1,figsize=(15,15))
43ax.imshow(bg)
44sns.kdeplot(eran_sample["victim_position_x"], eran_sample["victim_position_y"], n_levels=100,cmap=cm.Reds, alpha=0.9)```

1. 先计算了吃鸡团队平均击杀敌人的数量，这里剔除了四人模式的比赛数据，因为人数太多的团队会因为数量悬殊平均而变得没意义；
2. 所以我们考虑通过分组统计每一组吃鸡中存活到最后的成员击杀敌人的数量，但是这里发现数据统计存活时间变量是按照团队最终存活时间记录的，所以该想法失败；
3. 最后统计每个吃鸡团队中击杀人数最多的数量统计，这里剔除了单人模式的数据，因为单人模式的数量就是每组击杀最多的数量。最后居然发现还有击杀数量达到60的，怀疑是否有开挂。想要吃鸡还是得出去练枪法，光是苟着是不行的。
``` 1library(dplyr)
2library(tidyverse)
3library(data.table)
4library(ggplot2)
6# 吃鸡团队平均击杀敌人的数量
7attach(pubg_full)
8pubg_winner <- pubg_full %>% filter(team_placement==1&party_size<4&game_size>90)
9detach(pubg_full)
10team_killed <- aggregate(pubg_winner\$player_kills, by=list(pubg_winner\$match_id,pubg_winner\$team_id), FUN="mean")
11team_killed\$death_num <- ceiling(team_killed\$x)
12ggplot(data = team_killed) + geom_bar(mapping = aes(x = death_num, y = ..count..), color="steelblue") +
13  xlim(0,70) + labs(title = "Number of Death that PUBG Winner team Killed", x="Number of death")
14
15# 吃鸡团队最后存活的玩家击杀数量
16pubg_winner <- pubg_full %>% filter(pubg_full\$team_placement==1) %>% group_by(match_id,team_id)
17attach(pubg_winner)
18team_leader <- aggregate(player_survive_time~player_kills, data = pubg_winner, FUN="max")
19detach(pubg_winner)
20
21# 吃鸡团队中击杀敌人最多的数量
22pubg_winner <- pubg_full %>% filter(pubg_full\$team_placement==1&pubg_full\$party_size>1)
23attach(pubg_winner)
25detach(pubg_winner)
26ggplot(data = team_leader) + geom_bar(mapping = aes(x = x, y = ..count..), color="steelblue") +
27  xlim(0,70) + labs(title = "Number of Death that PUBG Winner Killed", x="Number of death")
28```

``` 1#杀人武器排名
2death_causes = deaths['killed_by'].value_counts()
3
4sns.set_context('talk')
5fig = plt.figure(figsize=(30, 10))
6ax = sns.barplot(x=death_causes.index, y=[v / sum(death_causes) for v in death_causes.values])
7ax.set_title('Rate of Death Causes')
8ax.set_xticklabels(death_causes.index, rotation=90)
9
10#排名前20的武器
11rank = 20
12fig = plt.figure(figsize=(20, 10))
13ax = sns.barplot(x=death_causes[:rank].index, y=[v / sum(death_causes) for v in death_causes[:rank].values])
14ax.set_title('Rate of Death Causes')
15ax.set_xticklabels(death_causes.index, rotation=90)
16
17#两个地图分开取
18f, axes = plt.subplots(1, 2, figsize=(30, 10))
19axes[0].set_title('Death Causes Rate: Erangel (Top {})'.format(rank))
20axes[1].set_title('Death Causes Rate: Miramar (Top {})'.format(rank))
21
22counts_er = erangel['killed_by'].value_counts()
23counts_mr = miramar['killed_by'].value_counts()
24
25sns.barplot(x=counts_er[:rank].index, y=[v / sum(counts_er) for v in counts_er.values][:rank], ax=axes[0] )
26sns.barplot(x=counts_mr[:rank].index, y=[v / sum(counts_mr) for v in counts_mr.values][:rank], ax=axes[1] )
27axes[0].set_ylim((0, 0.20))
28axes[0].set_xticklabels(counts_er.index, rotation=90)
29axes[1].set_ylim((0, 0.20))
30axes[1].set_xticklabels(counts_mr.index, rotation=90)
31
32#吃鸡和武器的关系
33win = deaths[deaths["killer_placement"] == 1.0]
34win_causes = win['killed_by'].value_counts()
35
36sns.set_context('talk')
37fig = plt.figure(figsize=(20, 10))
38ax = sns.barplot(x=win_causes[:20].index, y=[v / sum(win_causes) for v in win_causes[:20].values])
39ax.set_title('Rate of Death Causes of Win')
40ax.set_xticklabels(win_causes.index, rotation=90)```

``` 1library(dplyr)
2library(tidyverse)
3library(data.table)
4library(ggplot2)
6attach(pubg_full)
7pubg_winner <- pubg_full %>% filter(team_placement==1)
8detach(pubg_full)
9ggplot(data = pubg_winner) + geom_bar(mapping = aes(x = player_assists, y = ..count..), fill="#E69F00") +
10  xlim(0,10) + labs(title = "Number of Player assisted", x="Number of death")
11ggplot(data = pubg_winner) + geom_bar(mapping = aes(x = player_assists, y = ..prop..), fill="#56B4E9") +
12  xlim(0,10) + labs(title = "Number of Player assisted", x="Number of death")```

``` 1# python代码：杀人和距离的关系
2import math
3def get_dist(df): #距离函数
4    dist = []
5   for row in df.itertuples():
6        subset = (row.killer_position_x - row.victim_position_x)**2 + (row.killer_position_y - row.victim_position_y)**2
7        if subset > 0:
8            dist.append(math.sqrt(subset) / 100)
9         else:
10            dist.append(0)
11    return dist
12
13df_dist = pd.DataFrame.from_dict({'dist(m)': get_dist(erangel)})
14df_dist.index = erangel.index
15
16erangel_dist = pd.concat([erangel,df_dist], axis=1)
17
18df_dist = pd.DataFrame.from_dict({'dist(m)': get_dist(miramar)})
19df_dist.index = miramar.index
20
21miramar_dist = pd.concat([miramar,df_dist], axis=1)
22
23f, axes = plt.subplots(1, 2, figsize=(30, 10))
24plot_dist = 150
25
26axes[0].set_title('Engagement Dist. : Erangel')
27axes[1].set_title('Engagement Dist.: Miramar')
28
29plot_dist_er = erangel_dist[erangel_dist['dist(m)'] <= plot_dist]
30plot_dist_mr = miramar_dist[miramar_dist['dist(m)'] <= plot_dist]
31
32sns.distplot(plot_dist_er['dist(m)'], ax=axes[0])
33sns.distplot(plot_dist_mr['dist(m)'], ax=axes[1])```

``` 1# R语言代码如下：
2library(magrittr)
3library(dplyr)
4library(survival)
5library(tidyverse)
6library(data.table)
7library(ggplot2)
8library(survminer)
10# 数据预处理，将连续变量划为分类变量
11pubg_sub <- pubg_full %>%
12  filter(player_survive_time<2100) %>%
13  mutate(drive = ifelse(player_dist_ride>0, 1, 0)) %>%
14  mutate(size = ifelse(game_size<33, 1,ifelse(game_size>=33 &game_size<66,2,3)))
15# 创建生存对象
16surv_object <- Surv(time = pubg_sub\$player_survive_time)
17fit1 <- survfit(surv_object~party_size,data = pubg_sub)
18# 可视化生存率
19ggsurvplot(fit1, data = pubg_sub, pval = TRUE, xlab="Playing time [s]", surv.median.line="hv",
21fit2 <- survfit(surv_object~drive,data=pubg_sub)
22ggsurvplot(fit2, data = pubg_sub, pval = TRUE, xlab="Playing time [s]", surv.median.line="hv",
23           legend.labs=c("walk","walk&drive"), ggtheme = theme_light(),risk.table="percentage")
24fit3 <- survfit(surv_object~size,data=pubg_sub)
25ggsurvplot(fit3, data = pubg_sub, pval = TRUE, xlab="Playing time [s]", surv.median.line="hv",
26           legend.labs=c("small","medium","big"), ggtheme = theme_light(),risk.table="percentage")```

``` 1#最后毒圈位置
2import matplotlib.pyplot as plt
3import pandas as pd
4import seaborn as sns
6import matplotlib.cm as cm
7
8#导入部分数据
10#导入aggregate数据
13#找出最后三人死亡的位置
14
15team_win = aggregate[aggregate["team_placement"]==1] #排名第一的队伍
16#找出每次比赛第一名队伍活的最久的那个player
17grouped = team_win.groupby('match_id').apply(lambda t: t[t.player_survive_time==t.player_survive_time.max()])
18
19deaths_solo = deaths[deaths['match_id'].isin(grouped['match_id'].values)]
20deaths_solo_er = deaths_solo[deaths_solo['map'] == 'ERANGEL']
21deaths_solo_mr = deaths_solo[deaths_solo['map'] == 'MIRAMAR']
22
23df_second_er = deaths_solo_er[(deaths_solo_er['victim_placement'] == 2)].dropna()
24df_second_mr = deaths_solo_mr[(deaths_solo_mr['victim_placement'] == 2)].dropna()
25print (df_second_er)
26
27position_data = ["killer_position_x","killer_position_y","victim_position_x","victim_position_y"]
28for position in position_data:
29    df_second_mr[position] = df_second_mr[position].apply(lambda x: x*1000/800000)
30    df_second_mr = df_second_mr[df_second_mr[position] != 0]
31
32    df_second_er[position] = df_second_er[position].apply(lambda x: x*4096/800000)
33    df_second_er = df_second_er[df_second_er[position] != 0]
34
35df_second_er=df_second_er
36# erangel热力图
37sns.set_context('talk')
39fig, ax = plt.subplots(1,1,figsize=(15,15))
40ax.imshow(bg)
42
43# miramar热力图
45fig, ax = plt.subplots(1,1,figsize=(15,15))
46ax.imshow(bg)

https://www.kaggle.com/skihikingkevin/pubg-match-deaths#aggregate.zip

578 篇文章112 人订阅

0 条评论

## 相关文章

33050

### 从“London”出发，8步搞定自然语言处理（Python代码）

【新智元导读】自然语言处理是AI的一个子领域，从人们日常沟通所用的非结构化文本信息中提取结构化数据，以便计算机理解。本文用通俗易懂的语言深入浅出的介绍了自然语言...

8520

### 谷歌「机弦」有何玄机？

11月15日北京开始冬季供暖那天，谷歌科研博客发布了开源软件SLING，又一个号称能让计算机更容易看懂人话的技术。 SLING: A Natural Langu...

41050

### 科学瞎想系列之七十二 电机设计宝典（中学版）

【图片来自网络如有侵权敬请邮箱联系。欢迎原文转发到朋友圈，未经许可的媒体平台谢绝转载，如需转载或合作请邮件联系。联系邮箱laolicsiem@126.com】 ...

24840

### 【干货】台大李宏毅两个小时带你纵览自然语言处理和语音内容机器理解，附全程视频PPT下载

【导读】李宏毅11月25日在Dosudo硅谷工程师读书会上两个办小时的演讲。 在这次演讲中李宏毅老师以语音机器理解为例纵览自然语言处理各种最新技术。李宏毅老师演...

1.5K50

37950

18040

15620

11220

15130