栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

科比投篮预测,可视化与探索性数据分析(二)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

科比投篮预测,可视化与探索性数据分析(二)

第一关:

import pandas as pd
import matplotlib.pyplot as plt
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)


def student():
    # ********** Begin ********** #
    data = pd.read_csv("./data.csv").dropna()
    plt.figure(figsize=(10,10))
    d = data["shot_made_flag"].groupby(data["action_type"]).mean()
    x = []
    y = []
    for i in d.index:
        if list(data["action_type"].values).count(i)>20:
            y.append(i)
            x.append(d[i])
    asd = pd.DataFrame([x,y]).T
    asd.sort_values(by = [0],inplace = True)
    plt.scatter(asd[0], asd[1])
    plt.title("Accuracy by shot type")
    plt.xlabel("Accuracy")
    plt.savefig("Task4/img/T1.png")
    
    # ********** End ********** #

第二关:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)
def student():
    # ********** Begin ********** #
    data = pd.read_csv("./data.csv")
    plt.figure(figsize=(16,8))
    plt.subplot(1,3,1)
    x = data["shot_made_flag"].groupby(data["season"]).mean()
    plt.plot(x.index, x.values, marker='o')
    plt.title("Accuracy by season")
    plt.xticks(rotation = 70)
    plt.ylabel("Accuracy")
    plt.xlabel("Season")
    plt.subplot(1, 3, 2)
    y = data[data["playoffs"] == 1]["shot_made_flag"].groupby(data["season"]).mean()
    y1 = data[data["playoffs"] == 0]["shot_made_flag"].groupby(data["season"]).mean()
    plt.plot(y1.index, y1.values,marker='o', label="RegularSeason")
    plt.plot(y.index, y.values,marker='o', label="Playoff")
    plt.xticks(y1.index, rotation=70)
    plt.title("Accuracy by season Playoff and Regular Season")
    plt.ylabel("Accuracy")
    plt.xlabel("Season")
    plt.legend()
    plt.subplot(1, 3, 3)
    y = data[data["shot_type"] == "2PT Field Goal"]["shot_made_flag"].groupby(data["season"]).mean()
    y1 = data[data["shot_type"] == "3PT Field Goal"]["shot_made_flag"].groupby(data["season"]).mean()
    plt.plot(y1.index, y1.values,marker='o', label="ThreePoint")
    plt.plot(y.index, y.values,marker='o', label="TwoPoint")
    plt.xticks(y1.index, rotation=70)
    plt.ylabel("Accuracy")
    plt.xlabel("Season")
    plt.legend()
    plt.title("Accuracy by season 2PT Field Goal and 3PT Field Goal")
    plt.savefig("Task5/img/T1.png")
    # ********** End ********** #

第三关:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import matplotlib.cm as cm
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)

def student():
    # ********** Begin ********** #
    data = pd.read_csv("./data.csv")
    y = data["shot_made_flag"].groupby(data["shot_distance"]).mean()
    y = y[:45]
    plt.plot(y.index, y.values, marker='o')
    plt.title("Accuracy by shot distance")
    plt.ylabel("Accuracy")
    plt.xlabel("Shot distance(ft.)")
    plt.savefig("Task6/img/T1.png")
    # ********** End ********** #

第四关:

import pandas as pd
import matplotlib.pyplot as plt
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)

def student():
    # ********** Begin ********** #
    data = pd.read_csv("./data.csv")
    y = data["shot_made_flag"].groupby(data["minutes_remaining"]).mean()
    x = data["shot_made_flag"].groupby(data["seconds_remaining"]).mean()
    plt.figure(figsize=(10, 5))
    plt.subplot(1, 2, 1)
    plt.bar(y.index, y.values)
    plt.title("Accuracy by minutes_remaining")
    plt.ylabel("Accuracy")
    plt.xlabel("Minutes_remaining")
    plt.subplot(1, 2, 2)
    plt.bar(x.index, x.values)
    plt.title("Accuracy by seconds_remaining")
    plt.ylabel("Accuracy")
    plt.xlabel("Seconds_remaining")
    plt.savefig("Task7/img/T1.png")
    # ********** End ********** #

第五关:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import matplotlib.cm as cm
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)

def student():
    # ********** Begin ********** #
    data = pd.read_csv("./data.csv")
    y = data["shot_made_flag"].groupby(data["opponent"]).mean()
    y = pd.DataFrame(y)
    y.sort_values(by = ["shot_made_flag"], inplace = True, ascending = False)
    x = data[data["shot_type"] == "2PT Field Goal"]["shot_made_flag"].groupby(data["opponent"]).mean()
    x1 = data[data["shot_type"] == "3PT Field Goal"]["shot_made_flag"].groupby(data["opponent"]).mean()
    plt.figure(figsize = (10, 6))
    plt.subplot(1, 2, 1)
    plt.bar(y.index, y["shot_made_flag"])
    plt.xticks(rotation = 70)
    plt.title("Accuracy by opponent")
    plt.ylabel("Accuracy")
    plt.xlabel("Opponent")
    plt.subplot(1, 2, 2)
    plt.plot(x.index, x.values, marker = 'o', label = "TwoPoint")
    plt.plot(x1.index, x1.values, marker = 'o', label = "ThreePoint")
    plt.xticks(x.index, rotation = 70)
    plt.title("Accuracy by opponent")
    plt.ylabel("Accuracy")
    plt.xlabel("Opponent")
    plt.legend()
    plt.savefig("Task8/img/T1.png")
    # ********** End ********** #

第六关:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)
pd.set_option('display.max_colwidth', 1000)

def student():
    # ********** Begin ********** #
    data = pd.read_csv("./data.csv").dropna()
    y = data["shot_made_flag"].groupby(data["period"]).mean()
    y = pd.DataFrame(y)
    plt.figure(figsize=(10, 6))
    plt.bar(y.index,y["shot_made_flag"], )
    plt.title("Accuracy by period")
    plt.ylabel("Accuracy")
    plt.xlabel("Period")
    plt.savefig("Task9/img/T1.png")
    # ********** End ********** #

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/935529.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号