概览
五王之战(War of the Five Kings)是著名严肃奇幻小说《冰与火之歌》中的著名内战。本项目使用了五王之战期间的战争的数据集,它是所有战斗的大集合。
五王之战分析 - 冰与火之歌
简介
五王之战(War of the Five Kings)是著名严肃奇幻小说《冰与火之歌》中的著名内战。这是一场规模空前、波及七大王国的内乱。顾名思义,前后共有五人在战争中称王:乔佛里、史坦尼斯、蓝礼均声称自己是铁王座的合法继承人。除此之外,罗柏·史塔克被北境众封臣推选为北境之王,巴隆·葛雷乔伊亦再度掀起独立大旗,欲摆脱铁王座的统治,自称为铁群岛之王。
本数据集(battles.csv)包含了五王之战期间的战争,它是所有战斗的大集合。该数据是Kaggle中Game of Thrones的一部分。
数据中的变量含义解释:
name: 战争的名称,字符变量。
year: 战争发生的年份,数值变量。
battle_number: 本数据中的unique id,对应每一场独立的战役,数值变量。
attacker_king: 攻击方的国王,"/"表示了国王的更换。例如:"Joffrey/Tommen Baratheon"意味着Tomen Baratheon继承了Joffrey的王位,分类变量。
defender_king: 防守方的国王,分类变量。
attacker_1: 攻击方将领,字符变量。
attacker_2: 攻击方将领,字符变量。
attacker_3: 攻击方将领,字符变量。
attacker_4: 攻击方将领,字符变量。
defender_1: 防守方将领,字符变量。
defender_2: 防守方将领,字符变量。
defender_3: 防守方将领,字符变量。
defender_4: 防守方将领,字符变量。
attacker_outcome: 从攻击方角度来看的战争结果,分别有:win, loss, draw,分类变量。
battle_type: 战争的类别。pitched_battle: 双方军队在一个地点相遇并战斗,这也是最基本的战争类别;ambush: 以隐身或诡计为主要攻击手段的战争;siege: 阵地战;razing: 对未设防位置的攻击。分类变量。
major_death: 是否有重要人物的死亡,二进制变量。
major_capture: 是否有重要人物的被捕,二进制变量。
attacker_size: 攻击方力量的大小,并未对骑兵、步兵等士兵种类有所区分,数值变量。
defender_size: 防守方力量的大小,并未对骑兵、步兵等士兵种类有所区分,数值变量。
attacker_commander: 攻击方的主要指挥官。指挥官的名字中并没有包含头衔,不同的指挥官名字用逗号隔开,字符变量。
defender_commander: 防守方的主要指挥官。指挥官的名字中并没有包含头衔,不同的指挥官名字用逗号隔开,字符变量。
summer: 战争是否发生于夏天,二进制变量。
location: 战争发生的地点,字符变量。
region: 战争发生的地域,包括:Beyond the Wall, The North, The Iron Islands, The Riverlands, The Vale of Arryn, The Westerlands, The Crownlands, The Reach, The Stormlands, Dorne,分类变量。
note: 注释,字符变量。
提出问题
1.战役类型和攻守双方战力对比与战役胜率之间的关系?
2.哪位好战分子出场率最高?
数据评估和清理
# TO DO: load pacakges
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import *
import seaborn as sns
sns.set_style("white")
%matplotlib inline
# TO DO: load the dataset
battles=pd.read_csv('battles.csv')
pd.options.display.max_columns=1000 #显示全部列
battles.sample(5)
# TO DO: check the dataset general info
battles.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
#检查各列缺失值大概数量
battles.isnull().sum().plot(kind="barh",color='gre