王者想必大家都玩过叭,
但不得不说我菜鸡一个,
特羡慕玩的好的大神,
那大神是怎么玩好王者的呢?
那了解英雄的血条、攻击、装备、防御等能力是必不可少的,
那么我们今天就来爬一爬各类英雄的属性,
让自己知识量满满,不求胜过大神,但求不做送血狂魔!!
有什么python相关报错解答自己不会的、或者源码资料/模块安装/
女装大佬精通技巧都可以来这里:(https://jq.qq.com/?_wv=1027&k=2Q3YTfym)或者+V:python10010问我
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.mixture import GaussianMixture
from sklearn.preprocessing import StandardScaler
from pyecharts.charts import Pie
from pyecharts import options as opts
from collections import Counter
plt.rcParams['font.sans-serif'] = ['SimHei'] # 正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 正常显示负号
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
data = pd.read_csv('/home/mw/input/hero3741/all_hero_init_attr.csv', encoding='gb18030')
feature = ['英雄名字', '生存能力', '攻击伤害', '技能效果',
'上手难度', '最大生命', '最大法力', '物理攻击',
'法术攻击', '物理防御', '物理减伤率', '法术防御',
'法术减伤率', '移速', '物理护甲穿透', '法术护甲穿透',
'攻速加成', '暴击几率', '暴击效果', '物理吸血', '法术吸血',
'冷却缩减', '攻击范围', '韧性', '生命回复', '法力回复']
data_init = data[feature]
data_init.head()
# 把空值设置为0
data_init = data_init.fillna(0)
# print(data_init.isnull().sum())
'''
正则匹配包含%%的数据
p = r'(%%)'
a = data_init['物理减伤率'].astype("object").str.extract(p)
print(a)
'''
features_remain = ['生存能力', '攻击伤害', '技能效果',
'上手难度', '最大生命', '最大法力', '物理攻击',
'法术攻击', '物理防御', '物理减伤率', '移速', '攻击范围', '生命回复', '法力回复']
data_init = data_init[features_remain]
data_init['物理减伤率'] = data_init['物理减伤率'].apply(lambda x: float(x.strip('%'))/100)
data_init['攻击范围'] = data_init['攻击范围'].map({'远程': 1, '近程': 0})
# print(data_init)
gmm = GaussianMixture(n_components=20, covariance_type='full')
gmm.fit(data_init)
prediction = gmm.predict(data_init)
# print(prediction)
data.insert(0, '分组', prediction)
data.to_csv('/home/mw/input/hero3741/all_hero_init_attr_our.csv', index=False, sep=',', encoding='gb18030')
df = data[['分组', '英雄名字']] # 获取需要的两列
grouped = df.groupby(['分组']) # 以”分组“列来进行分组
k = []
# 获取分组后的 组和值,保存为字典,放到列表中
for name, group in grouped:
k.append({name: list(group['英雄名字'].values)})
kk = []
for i in k:
for k, v in i.items():
kk.append(v)
length = []
key = []
for i in kk:
key.append(str(i))
length.append(len(i))
key, length
pie = Pie()
pie.add("", [list(z) for z in zip(key, length)],
radius=["30%", "75%"], center=["45%", "50%"], rosetype="radius",
)
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}, {d}%"))
pie.set_global_opts(
title_opts=opts.TitleOpts(title="英雄初始属性分类图"),
legend_opts=opts.LegendOpts(
type_="scroll", pos_left="80%", orient="vertical"
),
)
pie.render_notebook()
pie = Pie()
pie.add("", [list(z) for z in zip(key, length)],
radius=["30%", "75%"], center=["45%", "50%"], rosetype="radius",
)
pie.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}, {d}%"))
pie.set_global_opts(
title_opts=opts.TitleOpts(title="英雄初始属性分类图"),
legend_opts=opts.LegendOpts(
type_="scroll", pos_left="80%", orient="vertical"
),
)
pie.render_notebook()
plt.rcParams['font.sans-serif'] = ['SimHei'] # 正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 正常显示负号
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
data = pd.read_csv('/home/mw/input/hero3741/all_hero_init_attr.csv', encoding='gb18030')
data.head()
feature = ['英雄名字', '生存能力', '攻击伤害', '技能效果',
'上手难度', '最大生命', '最大法力', '物理攻击',
'法术攻击', '物理防御', '物理减伤率', '法术防御',
'法术减伤率', '移速', '物理护甲穿透', '法术护甲穿透',
'攻速加成', '暴击几率', '暴击效果', '物理吸血', '法术吸血',
'冷却缩减', '攻击范围', '韧性', '生命回复', '法力回复']
data_init = data[feature]
data_init = data_init.fillna(0)
corr = data_init[feature].corr()
plt.figure(figsize=(14, 14))
sns.heatmap(corr, annot=True)
plt.show()
、features_remain = ['生存能力', '攻击伤害', '技能效果',
'上手难度', '最大生命', '最大法力', '物理攻击',
'法术攻击', '物理防御', '物理减伤率', '移速', '攻击范围', '生命回复', '法力回复']
data_init = data_init[features_remain]
data_init.head()
data_init['物理减伤率'] = data_init['物理减伤率'].apply(lambda x: float(x.strip('%'))/100)
data_init['攻击范围'] = data_init['攻击范围'].map({'远程': 1, '近程': 0})
data_init.head()
ss = StandardScaler()
data_init = ss.fit_transform(data_init)
gmm = GaussianMixture(n_components=20, covariance_type='full')
gmm.fit(data_init)
GaussianMixture(covariance_type='full', init_params='kmeans', max_iter=100,
means_init=None, n_components=20, n_init=1,
precisions_init=None, random_state=None, reg_covar=1e-06,
tol=0.001, verbose=0, verbose_interval=10, warm_start=False,
weights_init=None)
data.insert(0, '分组', prediction)
data.to_csv('/home/mw/input/hero3741/all_hero_init_attr_our.csv', index=False, sep=',', encoding='gb18030')
pie = Pie()
pie.add("", [list(z) for z in zip(key, length)],
radius=["30%", "75%"],
center=["40%", "50%"],
rosetype="radius")
pie.set_global_opts(
title_opts=opts.TitleOpts(title="英雄聚类分布"),
legend_opts=opts.LegendOpts(
type_="scroll", pos_left="80%", orient="vertical"
),
)
pie.render_notebook()
整完这个 文章代码,
我得找大神带我一局