科比生涯数据分析——利用随机森林进行分类

1.数据读取与介绍

  • 导入相关库及模块
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import KFold
  • 利用pandas进行数据读取,通过info()函数了解该数据的大致信息
file_name='data.csv'
data=pd.read_csv(file_name)
print('****该数据的大致信息如下****')
print(data.info())

在这里插入图片描述

  • 打印前五行数据
data.head()

在这里插入图片描述

  • 获取该数据的行数与列数
print('该数据共有{}条记录,{}个特征项'.format(data.shape[0],data.shape[1]))

输出为:该数据共有30697条记录,25个特征项
通过以上结果显示,我们得到:该数据在shot_made_flag字段上缺失值较多,且该字段为标签项,0表示未射入球门,1表示摄入球门,所以需删去shot_made_flag项为NaN的记录行。

data=data[data['shot_made_flag'].notnull()]
data.info()

2.特征数据可视化展示

  • 将射球时相对于球门的位置(loc_x,loc_y),(lat,lon)在图形中展示出来
#设置画布大小
plt.figure(figsize=(12,12))
#画第一个子图
plt.subplot(121)
plt.title('the location of the shot')
plt.xlabel('loc_x')
plt.ylabel('loc_y')
plt.scatter(data['loc_x'], data['loc_y'], color='g', alpha = 0.02)
#画第二个子图
plt.subplot(122)
plt.title('the site of the shot')
plt.xlabel('longitude')#经度
plt.ylabel('latitude')#纬度
plt.scatter(data['lon']
  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值