主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python


大吉大利,準備吃雞!

你是否玩兒了好幾個月的吃雞,依舊是落地成盒?

是否常常不得知自己如何被打、莫名其妙的掛了?

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

還沒有吃過雞/(ㄒoㄒ)/~~總是不明不白的就被別的玩家殺了!!!∑(゚Д゚ノ)ノ能進前二十就已經很不錯了今天小編帶來了福利奧O(≧▽≦)O

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

大吉大利,今晚吃雞~

打人時要堅持一個原則,先打對你來說最危險的目標。(不一定是近點的目標,大部分情況是先近後遠)

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

那麼我們就用 Python 和 R 做數據分析來回答以下的靈魂發問?

首先來看下數據:

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

image

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

一、跳哪兒危險?

對於我這樣一直喜歡苟著的良心玩家,在經歷了無數次落地成河的慘痛經歷後,我是堅決不會選擇跳P城這樣樓房密集的城市,窮歸窮但保命要緊。所以我們決定統計一下到底哪些地方更容易落地成河?我們篩選出在前100秒死亡的玩家地點進行可視化分析。激情沙漠地圖的電站、皮卡多、別墅區、依波城最為危險,火車站、火電廠相對安全。絕地海島中P城、軍事基地、學校、醫院、核電站、防空洞都是絕對的危險地帶。物質豐富的G港居然相對安全。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python


主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

1 import numpy as np 2 import matplotlib.pyplot as plt 3 import pandas as pd 4 import seaborn as sns 5 from scipy.misc.pilutil import imread 6 import matplotlib.cm as cm 7 8 #導入部分數據 9deaths1 = pd.read_csv("deaths/kill_match_stats_final_0.csv") 10 deaths2 = pd.read_csv("deaths/kill_match_stats_final_1.csv") 11 12 deaths = pd.concat([deaths1, deaths2]) 13 14 #打印前5列,理解變量 15 print (deaths.head(),'\\n',len(deaths)) 16 17 #兩種地圖 18 miramar = deaths[deaths["map"] == "MIRAMAR"] 19 erangel = deaths[deaths["map"] == "ERANGEL"] 20 21 #開局前100秒死亡熱力圖22 position_data = ["killer_position_x","killer_position_y","victim_position_x","victim_position_y"] 23 for 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 30 n = 50000 31 mira_sample = miramar[miramar["time"] < 100].sample(n) 32 eran_sample = erangel[erangel["time"] < 100].sample(n) 33 34 # miramar熱力圖35bg = imread("miramar.jpg") 36 fig, ax = plt.subplots(1,1,figsize=(15,15)) 37 ax.imshow(bg) 38 sns.kdeplot(mira_sample["victim_position_x"], mira_sample["victim_position_y"],n_levels=100, cmap=cm.Reds, alpha=0.9) 39 40 # erangel熱力圖41bg = imread("erangel.jpg") 42 fig, ax = plt.subplots(1,1,figsize=(15,15)) 43 ax.imshow(bg) 44 sns.kdeplot(eran_sample["victim_position_x"], eran_sample["victim_position_y"], n_levels=100,cmap=cm.Reds, alpha=0.9)

二、苟著還是出去幹?

我到底是苟在房間裡面還是出去和敵人硬拼?這裡因為比賽的規模不一樣,這裡選取參賽人數大於90的比賽數據,然後篩選出團隊team_placement即最後成功吃雞的團隊數據:

  1. 先計算了吃雞團隊平均擊殺敵人的數量,這裡剔除了四人模式的比賽數據,因為人數太多的團隊會因為數量懸殊平均而變得沒意義;
  2. 所以我們考慮通過分組統計每一組吃雞中存活到最後的成員擊殺敵人的數量,但是這裡發現數據統計存活時間變量是按照團隊最終存活時間記錄的,所以該想法失敗;
  3. 最後統計每個吃雞團隊中擊殺人數最多的數量統計,這裡剔除了單人模式的數據,因為單人模式的數量就是每組擊殺最多的數量。最後居然發現還有擊殺數量達到60的,懷疑是否有開掛。想要吃雞還是得出去練槍法,光是苟著是不行的。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

image

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

1 library(dplyr) 2 library(tidyverse) 3 library(data.table) 4 library(ggplot2) 5 pubg_full % filter(team_placement==1&party_size<4&game_size>90) 9 detach(pubg_full) 10 team_killed % filter(pubg_full$team_placement==1) %>% group_by(match_id,team_id) 17 attach(pubg_winner) 18 eam_leader % filter(pubg_full$team_placement==1&pubg_full$party_size>1) 23 attach(pubg_winner) 24 team_leader

三、哪一種武器幹掉的玩家多?

運氣好挑到好武器的時候,你是否猶豫選擇哪一件?從圖上來看,M416和SCAR是不錯的武器,也是相對容易能撿到的武器,大家公認Kar98k是能一槍斃命的好槍,它排名比較靠後的原因也是因為這把槍在比賽比較難得,而且一下擊中敵人也是需要實力的,像我這種撿到98k還裝上8倍鏡但沒捂熱乎1分鐘的玩家是不配得到它的。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

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

四、隊友的助攻是否助我吃雞?

有時候一不留神就被擊倒了,還好我爬得快讓隊友救我。這裡選擇成功吃雞的隊伍,最終接受1次幫助的成員所在的團隊吃雞的概率為29%,所以說隊友助攻還是很重要的(再不要罵我豬隊友了,我也可以選擇不救你。)竟然還有讓隊友救9次的,你也是個人才。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

1 library(dplyr) 2 library(tidyverse) 3 library(data.table) 4 library(ggplot2) 5 pubg_full % filter(team_placement==1) 8 detach(pubg_full) 9 ggplot(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") 11 ggplot(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")

五、 敵人離我越近越危險?

對數據中的killer_position和victim_position變量進行歐式距離計算,查看兩者的直線距離跟被擊倒的分佈情況,呈現一個明顯的右偏分佈,看來還是需要隨時觀察到附近的敵情,以免到淘汰都不知道敵人在哪兒。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

1 # python代碼:殺人和距離的關係 2 import 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 13 df_dist = pd.DataFrame.from_dict({'dist(m)': get_dist(erangel)}) 14 df_dist.index = erangel.index 15 16 erangel_dist = pd.concat([erangel,df_dist], axis=1) 17 18 df_dist = pd.DataFrame.from_dict({'dist(m)': get_dist(miramar)}) 19 df_dist.index = miramar.index 20 21 miramar_dist = pd.concat([miramar,df_dist], axis=1) 22 23 f, axes = plt.subplots(1, 2, figsize=(30, 10)) 24plot_dist = 150 25 26 axes[0].set_title('Engagement Dist. : Erangel') 27 axes[1].set_title('Engagement Dist.: Miramar') 28 29 plot_dist_er = erangel_dist[erangel_dist['dist(m)'] <= plot_dist] 30 plot_dist_mr = miramar_dist[miramar_dist['dist(m)'] <= plot_dist] 31 32 sns.distplot(plot_dist_er['dist(m)'], ax=axes[0]) 33 sns.distplot(plot_dist_mr['dist(m)'], ax=axes[1])

六、團隊人越多我活得越久?

對數據中的party_size變量進行生存分析,可以看到在同一生存率下,四人團隊的生存時間高於兩人團隊,再是單人模式,所以人多力量大這句話不是沒有道理的。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

七、乘車是否活得更久?

對死因分析中發現,也有不少玩家死於Bluezone,大家天真的以為撿繃帶就能跑毒。對數據中的player_dist_ride變量進行生存分析,可以看到在同一生存率下,有開車經歷的玩家生存時間高於只走路的玩家,光靠腿你是跑不過毒的。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

八、小島上人越多我活得更久?

對game_size變量進行生存分析發現還是小規模的比賽比較容易存活。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

1 # R語言代碼如下: 2 library(magrittr) 3 library(dplyr) 4 library(survival) 5 library(tidyverse) 6 library(data.table) 7 library(ggplot2) 8 library(survminer) 9 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 # 創建生存對象 16 surv_object

九、最後毒圈有可能出現的地點?

面對有本事能苟到最後的我,怎麼樣預測最後的毒圈出現在什麼位置。從表agg_match_stats數據找出排名第一的隊伍,然後按照match_id分組,找出分組數據裡面player_survive_time最大的值,然後據此匹配表格kill_match_stats_final裡面的數據,這些數據裡面取第二名死亡的位置,作圖發現激情沙漠的毒圈明顯更集中一些,大概率出現在皮卡多、聖馬丁和別墅區。絕地海島的就比較隨機了,但是還是能看出軍事基地和山脈的地方更有可能是最後的毒圈。

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

1 #最後毒圈位置 2 import matplotlib.pyplot as plt 3 import pandas as pd 4 import seaborn as sns 5 from scipy.misc.pilutil import imread 6 import matplotlib.cm as cm 7 8 #導入部分數據 9 deaths = pd.read_csv("deaths/kill_match_stats_final_0.csv") 10 #導入aggregate數據 11 aggregate = pd.read_csv("aggregate/agg_match_stats_0.csv") 12 print(aggregate.head()) 13 #找出最後三人死亡的位置 14 15 team_win = aggregate[aggregate["team_placement"]==1] #排名第一的隊伍 16 #找出每次比賽第一名隊伍活的最久的那個player 17 grouped = team_win.groupby('match_id').apply(lambda t: t[t.player_survive_time==t.player_survive_time.max()]) 18 19 deaths_solo = deaths[deaths['match_id'].isin(grouped['match_id'].values)] 20 deaths_solo_er = deaths_solo[deaths_solo['map'] == 'ERANGEL'] 21 deaths_solo_mr = deaths_solo[deaths_solo['map'] == 'MIRAMAR'] 22 23 df_second_er = deaths_solo_er[(deaths_solo_er['victim_placement'] == 2)].dropna() 24 df_second_mr = deaths_solo_mr[(deaths_solo_mr['victim_placement'] == 2)].dropna() 25 print (df_second_er) 26 27 position_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 35 df_second_er=df_second_er 36 # erangel熱力圖 37 sns.set_context('talk') 38 bg = imread("erangel.jpg") 39 fig, ax = plt.subplots(1,1,figsize=(15,15)) 40 ax.imshow(bg) 41 sns.kdeplot(df_second_er["victim_position_x"], df_second_er["victim_position_y"], cmap=cm.Blues, alpha=0.7,shade=True) 42 43 # miramar熱力圖 44 bg = imread("miramar.jpg") 45 fig, ax = plt.subplots(1,1,figsize=(15,15)) 46 ax.imshow(bg) 47 sns.kdeplot(df_second_mr["victim_position_x"], df_second_mr["victim_position_y"], cmap=cm.Blues,alpha=0.8,shade=True)

下面還為大家準備了


主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

2020年最新人工智能python教程和各種電子書

如果你看好人工智能產業,處於想學python或者找不到合適的入門教程,那麼趕快來領取吧

獲取方式:

1.轉發此文+關注

2.私信小編關鍵詞 “ 資料 ”,即可免費獲取哦!

還不會私信的小夥伴,可以按照以下步驟操作:

1、打開頭條,點擊右下角“我的”

2、在個人界面點擊“關注”,當然這需要你先關注小編

3、在關注中找到小編,點擊小編的頭像進入他的個人界面,隨後點擊“私信” 

4、隨後進入私信發送界面,這樣就可以愉快的私信聊天了;

主播用幾百行代碼,輕鬆“吃雞”月入過萬!竟然是靠Python

大吉大利 晚上吃雞


分享到:


相關文章: