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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 综合教程 >内容正文

综合教程

python 科比投篮数据可视化及简单分析

發(fā)布時(shí)間:2023/12/29 综合教程 28 生活家
生活随笔 收集整理的這篇文章主要介紹了 python 科比投篮数据可视化及简单分析 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

數(shù)據(jù)來(lái)源:https://www.kaggle.com/c/kobe-bryant-shot-selection/data

參考:https://blog.csdn.net/qq_41888542/article/details/80390900

1.導(dǎo)包

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns
from pylab import mpl  

2.讀取文件

#設(shè)置字體
mpl.rcParams['font.sans-serif'] = ['SimHei'] 
#讀取csv文件
data=pd.read_csv("data.csv")
#輸出前5條數(shù)據(jù)
print(data.head())
#將shot_made_flag為空的數(shù)據(jù)清除
new_data = data[data['shot_made_flag'].notnull()]

可以看到 文件中的數(shù)據(jù)是 [5 rows x 25 columns]

action_type 進(jìn)攻方式(更具體)
combined_shot_type 進(jìn)攻方式
game_event_id 比賽時(shí)間id
game_id 比賽ID
lat 投籃點(diǎn)
loc_x 投籃點(diǎn)
loc_y 投籃點(diǎn)
lon 投籃點(diǎn)
minutes_remaining 單節(jié)剩余時(shí)間(分鐘)
period 表示第幾節(jié)
playoffs 是否是季后賽
season 賽季
seconds_remaining 剩余時(shí)間(秒)
shot_distance 投籃距離
shot_made_flag 是否進(jìn)球
shot_type 兩分球或三分球
shot_zone_area 投籃區(qū)域
shot_zone_basic 投籃區(qū)域(更具體)
shot_zone_range 投籃范圍
team_id 球隊(duì)ID
team_name 球隊(duì)名稱
game_date 比賽日期
matchup 比賽雙方
opponent 對(duì)手
shot_id 投籃ID

3.數(shù)據(jù)可視化

先來(lái)看一看科比的投籃位置,可以很明顯的看到3分線

plt.figure(figsize=(10,20))
jumpshot = new_data[new_data['combined_shot_type']=='Jump Shot']
layup = new_data[new_data['combined_shot_type']=='Layup']
dunk = new_data[new_data['combined_shot_type']=='Dunk']
tipshot = new_data[new_data['combined_shot_type']=='Tip Shot']
hookshot = new_data[new_data['combined_shot_type']=='Hook Shot']
bankshot = new_data[new_data['combined_shot_type']=='Bank Shot']

plt.scatter(jumpshot.loc_x, jumpshot.loc_y, color='grey')
plt.scatter(layup.loc_x, layup.loc_y, color='red')
plt.scatter(dunk.loc_x, dunk.loc_y, color='yellow' )
plt.scatter(tipshot.loc_x, tipshot.loc_y, color='green')
plt.scatter(hookshot.loc_x, hookshot.loc_y, color='black')
plt.scatter(bankshot.loc_x, bankshot.loc_y, color='blue')
label=['跳投','上籃','扣籃','補(bǔ)籃','勾手','擦板']
plt.legend(label,loc=7)
plt.title('投籃位置')

再來(lái)看看科比的出手方式的次數(shù),很明顯跳投最多

attack_method = new_data['combined_shot_type'].value_counts()
a = np.array([1,2,3,4,5,6])
plt.bar(a,attack_method,align = 'center')
plt.xlabel('進(jìn)攻方式')
plt.ylabel('進(jìn)攻次數(shù)')
plt.title('科比進(jìn)攻方式')
plt.grid(linestyle = '--',linewidth = 1)
plt.ylim(0,20000)
plt.xticks(a,('跳投','上籃','扣籃','補(bǔ)籃','勾手','擦板'))
plt.show()

投籃命中率上,扣籃無(wú)疑是命中率最高的

shooting = new_data[new_data['shot_made_flag']==1]['combined_shot_type'].value_counts()
list1 = attack_method.tolist()
list2 = shooting.tolist()
list3 = attack_method.tolist()
for i in range(len(list1)):
    list3[i]=list2[i]/list1[i]
hits_df=pd.Series(list3);
a = np.array([1,2,3,4,5,6])
plt.bar(a,hits_df,align = 'center')
plt.ylabel('命中率',fontsize=20)
plt.title('科比各種投籃方式命中率',fontsize=20)
plt.xticks(a,('跳投','上籃','扣籃','補(bǔ)籃','勾手','擦板'),fontsize=20)
plt.show()

從投籃距離上看,科比大多數(shù)是在中距離出手

area = new_data['shot_zone_basic'].value_counts()
b = np.array([0,1,2,3,4,5,6])
plt.barh(b,area,align ='center')
plt.yticks(b,('中距離','進(jìn)攻有理區(qū)','底線之外的三分','除進(jìn)攻有理區(qū)外的禁區(qū)','右邊底線三分','左邊底線三分','后場(chǎng)'))
plt.xlabel('投籃次數(shù)',fontsize=20)
plt.title('科比在各區(qū)域投籃',fontsize=20)
plt.tight_layout()# 緊湊顯示圖片,居中顯示
plt.show()

科比在每一節(jié)的出手次數(shù),其中第三節(jié)最多,第一節(jié)次之,因?yàn)?,6,7節(jié)都是加時(shí)賽,自然少很多

shot_number = new_data['period'].value_counts().sort_index()
shot_hit = new_data[new_data['shot_made_flag']==1]['period'].value_counts().sort_index()
plt.bar(shot_number.index,shot_number,align='center')
plt.ylabel('出手次數(shù)',fontsize=20)
plt.xlabel('節(jié)數(shù)',fontsize=20)
plt.show()

每一節(jié)投籃命中率 可以看出科比的投籃命中率在第四節(jié)最低,可以見得體力對(duì)科比投籃命中率也是有些影響的

list1 = shot_number.tolist()
list2 = shot_hit.tolist()
for i in range(len(list1)):
    list2[i]=list2[i]/list1[i]
shot_hit=pd.Series(list2)
c = np.array([1,2,3,4,5,6,7])
plt.bar(c,shot_hit,align = 'center')
plt.ylabel('命中率',fontsize=20)
plt.title('節(jié)數(shù)',fontsize=20)
plt.xticks(c)
plt.show()

科比在13-14賽季僅出場(chǎng)6次,從下圖可以清楚的看到

f, axarr = plt.subplots(8, figsize=(15, 25))

sns.countplot(x="combined_shot_type", hue="shot_made_flag", data=new_data, ax=axarr[0])
sns.countplot(x="season", hue="shot_made_flag", data=new_data, ax=axarr[1])
sns.countplot(x="period", hue="shot_made_flag", data=new_data, ax=axarr[2])
sns.countplot(x="playoffs", hue="shot_made_flag", data=new_data, ax=axarr[3])
sns.countplot(x="shot_type", hue="shot_made_flag", data=new_data, ax=axarr[4])
sns.countplot(x="shot_zone_area", hue="shot_made_flag", data=new_data, ax=axarr[5])
sns.countplot(x="shot_zone_basic", hue="shot_made_flag", data=new_data, ax=axarr[6])
sns.countplot(x="shot_zone_range", hue="shot_made_flag", data=new_data, ax=axarr[7])

axarr[0].set_title('投籃方式',fontsize=20)
axarr[1].set_title('生涯',fontsize=20)
axarr[2].set_title('不同節(jié)數(shù)的投籃',fontsize=20)
axarr[3].set_title('賽季',fontsize=20)
axarr[4].set_title('投籃類型',fontsize=20)
axarr[5].set_title('投籃區(qū)域',fontsize=20)
axarr[6].set_title('距離劃分投籃區(qū)域',fontsize=20)
axarr[7].set_title('投籃距離',fontsize=20)

plt.tight_layout()
plt.show()

0.0為投丟 1.0為投中

總結(jié)

以上是生活随笔為你收集整理的python 科比投篮数据可视化及简单分析的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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