1. 程式人生 > >大吉大利,今晚吃雞

大吉大利,今晚吃雞

資料集下載地址 昨天在kaggle上發現了一個比較有意思的資料集,記錄的是PUBG中65K場的比賽記錄,於是先拿來研究研究。

資料初探

import matplotlib.pyplot as plt 
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib
import warnings
import sklearn
import scipy
import numpy
import json
import csv
import sys
train = pd.read_csv("../input/PUBG/train_V2.csv")
test = pd.read_csv("../input/PUBG/test_V2.csv")
train.info()

<class ‘pandas.core.frame.DataFrame’> RangeIndex: 4446966 entries, 0 to 4446965 Data columns (total 29 columns): Id object groupId object matchId object assists int64 boosts int64 damageDealt float64 DBNOs int64 headshotKills int64 heals int64 killPlace int64 killPoints int64 kills int64 killStreaks int64 longestKill float64 matchDuration int64 matchType object maxPlace int64 numGroups int64 rankPoints int64 revives int64 rideDistance float64 roadKills int64 swimDistance float64 teamKills int64 vehicleDestroys int64 walkDistance float64 weaponsAcquired int64 winPoints int64 winPlacePerc float64 dtypes: float64(6), int64(19), object(4) memory usage: 983.9+ MB

train['matchType'].value_counts()

squad-fpp 1756186 duo-fpp 996691 squad 626526 solo-fpp 536762 duo 313591 solo 181943 normal-squad-fpp 17174 crashfpp 6287 normal-duo-fpp 5489 flaretpp 2505 normal-solo-fpp 1682 flarefpp 718 normal-squad 516 crashtpp 371 normal-solo 326 normal-duo 199 Name: matchType, dtype: int64

可以看出,共16種比賽型別(包括了限時模式如訊號槍模式等) 將比賽型別可視化出來

ax = train['matchType'].value_counts().plot.bar(
    figsize=(12, 6),
    fontsize=14
)
ax.set_title("Review of matchType", fontsize=20)
sns.despine(bottom=True, left=True)
plt.show()

在這裡插入圖片描述 接著,根據遊戲經驗將比賽型別分類: 絕地求生按視角分為第一人稱,第三人稱 組隊情況又可分為單人賽,雙人賽,四人賽 通常情況下比賽可以這麼分類: 在這裡插入圖片描述 按照這個思路,我們有:

fpp = train[train['matchType'].isin(['solo-fpp',
                                     'duo-fpp',
                                     'squad-fpp',
                                     'crashfpp',
                                     'flarefpp',
                                     'normal-solo-fpp',
                                     'normal-duo-fpp',
                                     'normal-squad-fpp'])]

tpp = train[train['matchType'].isin(['solo',
                                     'duo',
                                     'squad',
                                     'crashtpp',
                                     'flaretpp',
                                     'normal-solo',
                                     'normal-duo',
                                     'normal-squad'])]

solo = train[train['matchType'].isin(['solo',
                                     'solo-fpp',
                                     'normal-solo',
                                     'normal-solo-fpp'])]

duo = train[train['matchType'].isin(['duo',
                                    'duo-fpp',
                                    'normal-duo',
                                    'normal-duo-fpp'])]

squad = train[train['matchType'].isin(['squad',
                                      'squad-fpp',
                                      'normal-squad',
                                      'normal-squad-fpp'])]

special_event = train[train['matchType'].isin(['normal-squad-fpp',
                                               'crashfpp',
                                               'normal-duo-fpp',
                                               'flaretpp',
                                               'normal-solo-fpp',
                                               'flarefpp',
                                               'normal-squad',
                                               'crashtpp',
                                               'normal-solo',
                                               'normal-duo'])]

將中間結果列印

print(len(fpp),len(tpp),len(solo),len(duo),len(squad))

3320989 1125977 720713 1315970 2400402

然後扔進excel作圖,雖然matplotlib提供了扇形圖 但excel畫得更好看 : -) 不接受任何爭議 在這裡插入圖片描述 目測資料集並非來自亞服,感覺身邊的人其實更喜歡玩TPP模式,另外四排貌似是全球人民都喜聞樂見的比賽模式。

在這裡插入圖片描述 在這裡插入圖片描述 接下來的就是相關係數矩陣,因為要對很多不同的比賽型別進行分析,所以不妨先定義一下:

def plot_correlation_heatmap(df):
    corr = df.corr()
    sns.set(style="white")
    mask = np.zeros_like(corr, dtype=np.bool)
    mask[np.triu_indices_from(mask)] = True

    f, ax = plt.subplots(figsize=(20, 20))
    
    ax.set_title('Correlation Map',fontsize = 20)
    
    cmap = sns.diverging_palette(220, 10, as_cmap=True)

    sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,
            square=True, annot = True , linewidths=8, cbar_kws={"shrink": .5})
    plt.show()

然後瘋狂作圖…:

plot_correlation_heatmap(train)
#solo,duo,squad,fpp,tpp

在這裡插入圖片描述 可以看到,多跑路對吃雞好處最大,另外撿槍,殺人,嗑藥也很重要。 在各種模式下的相關矩陣: 在這裡插入圖片描述 在單人模式裡,由於沒有隊友的存在,因此個人能力顯得更加重要(我很好奇solo模式下怎麼還有助攻???) 目前想到的就這麼點,以後有什麼新的想法再更。