日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

冰与火之歌-五王之战(优达数据分析进阶项目)

發(fā)布時間:2024/3/12 编程问答 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 冰与火之歌-五王之战(优达数据分析进阶项目) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

五王之戰(zhàn)分析 - 冰與火之歌

簡介

五王之戰(zhàn)(War of the Five Kings)是著名嚴(yán)肅奇幻小說《冰與火之歌》中的著名內(nèi)戰(zhàn)。這是一場規(guī)模空前、波及七大王國的內(nèi)亂。顧名思義,前后共有五人在戰(zhàn)爭中稱王:喬佛里、史坦尼斯、藍(lán)禮均聲稱自己是鐵王座的合法繼承人。除此之外,羅柏·史塔克被北境眾封臣推選為北境之王,巴隆·葛雷喬伊亦再度掀起獨立大旗,欲擺脫鐵王座的統(tǒng)治,自稱為鐵群島之王。

本數(shù)據(jù)集(battles.csv)包含了五王之戰(zhàn)期間的戰(zhàn)爭,它是所有戰(zhàn)斗的大集合。該數(shù)據(jù)是Kaggle中Game of Thrones的一部分。

數(shù)據(jù)中的變量含義解釋:

name: 戰(zhàn)爭的名稱,字符變量。 year: 戰(zhàn)爭發(fā)生的年份,數(shù)值變量。 battle_number: 本數(shù)據(jù)中的unique id,對應(yīng)每一場獨立的戰(zhàn)役,數(shù)值變量。 attacker_king: 攻擊方的國王,"/"表示了國王的更換。例如:"Joffrey/Tommen Baratheon"意味著Tomen Baratheon繼承了Joffrey的王位,分類變量。 defender_king: 防守方的國王,分類變量。 attacker_1: 攻擊方將領(lǐng),字符變量。 attacker_2: 攻擊方將領(lǐng),字符變量。 attacker_3: 攻擊方將領(lǐng),字符變量。 attacker_4: 攻擊方將領(lǐng),字符變量。 defender_1: 防守方將領(lǐng),字符變量。 defender_2: 防守方將領(lǐng),字符變量。 defender_3: 防守方將領(lǐng),字符變量。 defender_4: 防守方將領(lǐng),字符變量。 attacker_outcome: 從攻擊方角度來看的戰(zhàn)爭結(jié)果,分別有:win, loss, draw,分類變量。 battle_type: 戰(zhàn)爭的類別。pitched_battle: 雙方軍隊在一個地點相遇并戰(zhàn)斗,這也是最基本的戰(zhàn)爭類別;ambush: 以隱身或詭計為主要攻擊手段的戰(zhàn)爭;siege: 陣地戰(zhàn);razing: 對未設(shè)防位置的攻擊。分類變量。 major_death: 是否有重要人物的死亡,二進(jìn)制變量。 major_capture: 是否有重要人物的被捕,二進(jìn)制變量。 attacker_size: 攻擊方力量的大小,并未對騎兵、步兵等士兵種類有所區(qū)分,數(shù)值變量。 defender_size: 防守方力量的大小,并未對騎兵、步兵等士兵種類有所區(qū)分,數(shù)值變量。 attacker_commander: 攻擊方的主要指揮官。指揮官的名字中并沒有包含頭銜,不同的指揮官名字用逗號隔開,字符變量。 defender_commander: 防守方的主要指揮官。指揮官的名字中并沒有包含頭銜,不同的指揮官名字用逗號隔開,字符變量。 summer: 戰(zhàn)爭是否發(fā)生于夏天,二進(jìn)制變量。 location: 戰(zhàn)爭發(fā)生的地點,字符變量。 region: 戰(zhàn)爭發(fā)生的地域,包括:Beyond the Wall, The North, The Iron Islands, The Riverlands, The Vale of Arryn, The Westerlands, The Crownlands, The Reach, The Stormlands, Dorne,分類變量。 note: 注釋,字符變量。

項目完成指南

本項目中的數(shù)據(jù)分析流程已經(jīng)給出,但代碼將完全由你自己進(jìn)行書寫,如果你無法完成本項目,說明你目前的能力并不足以完成 數(shù)據(jù)分析(進(jìn)階)納米學(xué)位,建議先進(jìn)行 數(shù)據(jù)分析(入門)納米學(xué)位的學(xué)習(xí),掌握進(jìn)階課程的先修知識。

對于數(shù)據(jù)分析過程的記錄也是數(shù)據(jù)分析報告的一個重要部分,你可以自己在需要的位置插入Markdown cell,記錄你在數(shù)據(jù)分析中的關(guān)鍵步驟和推理過程。比如:數(shù)據(jù)有什么樣的特點,統(tǒng)計數(shù)據(jù)的含義是什么,你從可視化中可以得出什么結(jié)論,下一步分析是什么,為什么執(zhí)行這種分析。如果你無法做到這一點,你也無法通過本項目。

小貼士: 像這樣的引用部分旨在為學(xué)員提供實用指導(dǎo),幫助學(xué)員了解并使用 Jupyter notebook

提出問題

在此項目中,你將以一名數(shù)據(jù)分析師的身份執(zhí)行數(shù)據(jù)的探索性分析。你將了解數(shù)據(jù)分析過程的基本流程。在你分析數(shù)據(jù)之前,請先思考幾個你需要理解的關(guān)于這些戰(zhàn)斗的問題,例如,哪一個區(qū)域發(fā)生了最多的戰(zhàn)爭?哪一個國王獲得了最多的勝利?戰(zhàn)爭的勝利與否受那些關(guān)鍵因素的影響?

問題:請寫下你感興趣的問題,請確保這些問題能夠由現(xiàn)有的數(shù)據(jù)進(jìn)行回答。
(為了確保學(xué)習(xí)的效果,請確保你的數(shù)據(jù)分析報告中能夠包含2幅可視化和1個相關(guān)性分析。)

答案:1.那個區(qū)域發(fā)生的戰(zhàn)爭最多;
2.哪個國王勝利的次數(shù)最多;
3.戰(zhàn)爭的勝利與否受哪些關(guān)鍵因素的影響。

在提出了問題之后,我們將開始導(dǎo)入數(shù)據(jù),并對數(shù)據(jù)進(jìn)行探索性分析,來回答上面提出的問題。

小貼士: 雙擊上框,文本就會發(fā)生變化,所有格式都會被清除,以便你編輯該文本塊。該文本塊是用 Markdown編寫的,該語言使用純文本語法,能用頁眉、鏈接、斜體等來規(guī)范文本格式。在納米學(xué)位課程中,你也會用到 Markdown。編輯后,可使用 Shift + EnterShift + Return 運行上該框,使其呈現(xiàn)出編輯好的文本格式。

數(shù)據(jù)評估和清理

小貼士: 運行代碼框的方法與編輯上方的 Markdown 框的格式類似,你只需點擊代碼框,按下鍵盤快捷鍵 Shift + EnterShift + Return ,或者你也可先選擇代碼框,然后點擊工具欄的 運行 按鈕來運行代碼。運行代碼框時,相應(yīng)單元左側(cè)的信息會出現(xiàn)星號,即 In [*]:,若代碼執(zhí)行完畢,星號則會變?yōu)槟硞€數(shù)字,如 In [1]。如果代碼運行后有輸出結(jié)果,輸出將會以 Out [1]: 的形式出現(xiàn),其中的數(shù)字將與 “In” 中的數(shù)字相對應(yīng)。

# TO DO: load pacakges import pandas as pd import numpy as np % matplotlib inline # TO DO: load the dataset df = pd.read_csv("battles.csv") # 將折疊的數(shù)據(jù)展開 pd.set_option('display.max_columns',None) # 展開數(shù)據(jù)前五行進(jìn)行觀察 df.head() nameyearbattle_numberattacker_kingdefender_kingattacker_1attacker_2attacker_3attacker_4defender_1defender_2defender_3defender_4attacker_outcomebattle_typemajor_deathmajor_captureattacker_sizedefender_sizeattacker_commanderdefender_commandersummerlocationregionnote01234
Battle of the Golden Tooth2981Joffrey/Tommen BaratheonRobb StarkLannisterNaNNaNNaNTullyNaNNaNNaNwinpitched battle1.00.015000.04000.0Jaime LannisterClement Piper, Vance1.0Golden ToothThe WesterlandsNaN
Battle at the Mummer's Ford2982Joffrey/Tommen BaratheonRobb StarkLannisterNaNNaNNaNBaratheonNaNNaNNaNwinambush1.00.0NaN120.0Gregor CleganeBeric Dondarrion1.0Mummer's FordThe RiverlandsNaN
Battle of Riverrun2983Joffrey/Tommen BaratheonRobb StarkLannisterNaNNaNNaNTullyNaNNaNNaNwinpitched battle0.01.015000.010000.0Jaime Lannister, Andros BraxEdmure Tully, Tytos Blackwood1.0RiverrunThe RiverlandsNaN
Battle of the Green Fork2984Robb StarkJoffrey/Tommen BaratheonStarkNaNNaNNaNLannisterNaNNaNNaNlosspitched battle1.01.018000.020000.0Roose Bolton, Wylis Manderly, Medger Cerwyn, H...Tywin Lannister, Gregor Clegane, Kevan Lannist...1.0Green ForkThe RiverlandsNaN
Battle of the Whispering Wood2985Robb StarkJoffrey/Tommen BaratheonStarkTullyNaNNaNLannisterNaNNaNNaNwinambush1.01.01875.06000.0Robb Stark, Brynden TullyJaime Lannister1.0Whispering WoodThe RiverlandsNaN
# 查看數(shù)據(jù)集結(jié)構(gòu) df.shape (38, 25) # TO DO: check the dataset general info # 查看數(shù)據(jù)是否有缺失值 df.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 38 entries, 0 to 37 Data columns (total 25 columns): name 38 non-null object year 38 non-null int64 battle_number 38 non-null int64 attacker_king 36 non-null object defender_king 35 non-null object attacker_1 38 non-null object attacker_2 10 non-null object attacker_3 3 non-null object attacker_4 2 non-null object defender_1 37 non-null object defender_2 2 non-null object defender_3 0 non-null float64 defender_4 0 non-null float64 attacker_outcome 37 non-null object battle_type 37 non-null object major_death 37 non-null float64 major_capture 37 non-null float64 attacker_size 24 non-null float64 defender_size 19 non-null float64 attacker_commander 37 non-null object defender_commander 28 non-null object summer 37 non-null float64 location 37 non-null object region 38 non-null object note 5 non-null object dtypes: float64(7), int64(2), object(16) memory usage: 7.5+ KB ## defender_3,defender_4,這兩個字段全是空值,沒有保留的必要,將其刪除 df.drop(["defender_3","defender_4"],axis = 1,inplace= True) ## attacker_king 列,有兩行是空值,去掉空值 df["attacker_king"].dropna(inplace = True) # TO DO: clean the data (optional: only there are problems) ## fill the missing data #df.fillna(df.mean(),inplace=True) #df.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 38 entries, 0 to 37 Data columns (total 23 columns): name 38 non-null object year 38 non-null int64 battle_number 38 non-null int64 attacker_king 36 non-null object defender_king 35 non-null object attacker_1 38 non-null object attacker_2 10 non-null object attacker_3 3 non-null object attacker_4 2 non-null object defender_1 37 non-null object defender_2 2 non-null object attacker_outcome 37 non-null object battle_type 37 non-null object major_death 38 non-null float64 major_capture 38 non-null float64 attacker_size 38 non-null float64 defender_size 38 non-null float64 attacker_commander 37 non-null object defender_commander 28 non-null object summer 38 non-null float64 location 37 non-null object region 38 non-null object note 5 non-null object dtypes: float64(5), int64(2), object(16) memory usage: 6.9+ KB ## check the duplicated data sum(df.name.duplicated()) 0

數(shù)據(jù)探索分析

# In exploratory data analysis, please make sure of using statistics and visualizations ## 統(tǒng)計各個區(qū)域的戰(zhàn)爭次數(shù) df["region"].value_counts().plot(kind = "bar",colors = ["r","gray","gray","gray","gray","gray","gray"]) C:\Users\15004\Anaconda3\lib\site-packages\pandas\plotting\_core.py:194: UserWarning: 'colors' is being deprecated. Please use 'color'instead of 'colors'warnings.warn(("'colors' is being deprecated. Please use 'color'"<matplotlib.axes._subplots.AxesSubplot at 0x1dae9de3b00>

在數(shù)據(jù)的探索性分析中,請確保你對數(shù)據(jù)分析中的關(guān)鍵步驟和推理過程進(jìn)行了記錄。你可以自己插入code cell和markdown cell來組織你的報告。

#for i, v in enumerate(df.columns):# print(i, v) ## 為了節(jié)省運行時間,我們選擇“attacker_king”,"attacker_outcome"與"battle_type"字段進(jìn)行統(tǒng)計 df[["attacker_king","attacker_outcome","battle_type"]] attacker_kingattacker_outcomebattle_type012345678910111213141516171819202122232425262728293031323334353637
Joffrey/Tommen Baratheonwinpitched battle
Joffrey/Tommen Baratheonwinambush
Joffrey/Tommen Baratheonwinpitched battle
Robb Starklosspitched battle
Robb Starkwinambush
Robb Starkwinambush
Joffrey/Tommen Baratheonwinpitched battle
Balon/Euron Greyjoywinpitched battle
Balon/Euron Greyjoywinsiege
Balon/Euron Greyjoywinambush
Robb Starkwinpitched battle
Balon/Euron Greyjoywinambush
Balon/Euron Greyjoywinsiege
Joffrey/Tommen Baratheonwinambush
Robb Starkwinambush
Stannis Baratheonwinsiege
Joffrey/Tommen Baratheonlosspitched battle
Robb Starkwinambush
Robb Starkwinambush
Stannis Baratheonlosspitched battle
Robb Starkwinsiege
Robb Starklosspitched battle
NaNwinpitched battle
Joffrey/Tommen Baratheonwinpitched battle
Joffrey/Tommen Baratheonwinpitched battle
Joffrey/Tommen Baratheonwinambush
Robb Starkwinsiege
Stannis Baratheonlosssiege
Joffrey/Tommen Baratheonwinsiege
NaNwinrazing
Stannis Baratheonwinpitched battle
Balon/Euron Greyjoywinpitched battle
Balon/Euron Greyjoywinrazing
Joffrey/Tommen Baratheonwinsiege
Joffrey/Tommen Baratheonwinsiege
Joffrey/Tommen Baratheonwinsiege
Joffrey/Tommen Baratheonwinsiege
Stannis BaratheonNaNNaN
## 從攻擊方角度將,對不同國王勝利次數(shù)進(jìn)行統(tǒng)計 df.groupby("attacker_king").attacker_outcome.value_counts().unstack().plot(kind="bar") <matplotlib.axes._subplots.AxesSubplot at 0x1dae9dc8a90>

## 對于運用不同的作戰(zhàn)方式而獲勝的次數(shù)進(jìn)行統(tǒng)計 df.groupby("battle_type").attacker_outcome.value_counts().unstack().plot(kind="bar") <matplotlib.axes._subplots.AxesSubplot at 0x1dae9eab898>

得出結(jié)論

問題:上面的分析能夠回答你提出的問題?通過這些分析你能夠得出哪些結(jié)論?

答案:1.從數(shù)據(jù)探索第一階段得出的數(shù)據(jù),可以看出,在The Riverlands地區(qū)發(fā)生的戰(zhàn)爭次數(shù)最多。 2.從攻擊方的角度來講,Joffrey/Tommen Baratheon(Tomen Baratheon繼承了Joffrey的王位)獲勝次數(shù)最多。 3.從戰(zhàn)爭類型來看,采用ambusy與siege類型的戰(zhàn)役獲勝次數(shù)要多于其他兩種。從現(xiàn)有數(shù)據(jù)量來看的話,在戰(zhàn)爭中運用這兩種類型獲勝的可能行要更大。是否采用這兩種類型,與能否獲勝有一定的相關(guān)性。

反思

問題:在你的分析和總結(jié)過程中是否存在邏輯嚴(yán)謹(jǐn)。是否有改進(jìn)的空間? 你可以從下面的一些角度進(jìn)行思考:

  • 數(shù)據(jù)集是否完整,包含所有想要分析的數(shù)據(jù)?
  • 在對數(shù)據(jù)進(jìn)行處理的時候,你的操作(例如刪除/填充缺失值)是否可能影響結(jié)論?
  • 是否還有其他變量(本數(shù)據(jù)中沒有)能夠?qū)δ愕姆治鲇袔椭?#xff1f;
  • 在得出結(jié)論時,你是否混淆了相關(guān)性和因果性?
  • 答案:1.現(xiàn)有數(shù)據(jù)量不是很完整。 2.由于統(tǒng)計需要,對attacker_king列中的空值進(jìn)行了2行刪除操作,對結(jié)論的影響很小。 3.在思考有戰(zhàn)爭獲勝有關(guān)的因素時,如果能再加一點天氣的因素在里邊就更完美了。 4.沒有混淆相關(guān)性與因果性,在未通過統(tǒng)計學(xué)驗證及機(jī)器學(xué)習(xí)的支持下,只能初步得出:是否采用ambusy與siege類型,與能否獲勝有一定的相關(guān)性。

    恭喜你完成了此項目!這只是數(shù)據(jù)分析過程的一個樣本:從生成問題、整理數(shù)據(jù)、探索數(shù)據(jù)到得出結(jié)論。在數(shù)據(jù)分析(進(jìn)階)納米學(xué)位中,你將會學(xué)到更多高級的數(shù)據(jù)分析方法和技術(shù),如果你感興趣的話,我們鼓勵你繼續(xù)學(xué)習(xí)后續(xù)的課程,掌握更多的數(shù)據(jù)分析的高級技能!

    若想與他人分享我們的分析結(jié)果,除了向他們提供 jupyter Notebook (.ipynb) 文件的副本外,我們還可以將 Notebook 輸出導(dǎo)出為一種甚至那些未安裝 Python 的人都能打開的形式。從左上方的“文件”菜單,前往“下載為”子菜單。然后你可以選擇一個可以更普遍查看的格式,例如 HTML (.html) 。你可能需要額外軟件包或軟件來執(zhí)行這些導(dǎo)出。

    總結(jié)

    以上是生活随笔為你收集整理的冰与火之歌-五王之战(优达数据分析进阶项目)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。