前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kaggle共享单车数据分析——数据可视化

Kaggle共享单车数据分析——数据可视化

作者头像
带萝卜
发布2020-10-26 14:32:35
1.3K0
发布2020-10-26 14:32:35
举报

@猴子 求第七关门票

本文数据来源于Kaggle_Bike_Sharing_Demand。主要内容为模型前期的简要数据分析及可视化。

数据总览

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
import seaborn as sns
%matplotlib inline
df = pd.read_csv('train.csv')
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10886 entries, 0 to 10885
Data columns (total 12 columns):
datetime      10886 non-null object
season        10886 non-null int64
holiday       10886 non-null int64
workingday    10886 non-null int64
weather       10886 non-null int64
temp          10886 non-null float64
atemp         10886 non-null float64
humidity      10886 non-null int64
windspeed     10886 non-null float64
casual        10886 non-null int64
registered    10886 non-null int64
count         10886 non-null int64
dtypes: float64(3), int64(8), object(1)
memory usage: 1020.6+ KB

字段描述

项目数据描述如下:

(1) datetime:日期,以年-月-日 小时的形式给出。

(2) season:季节。1 为春季, 2为夏季,3 为秋季,4 为冬季。

(3) hodliday:是否为假期。1代表是,0代表不是。

(4) workingday:是否为工作日,1代表是,0代表不是。

(5) weather:天气:

1: 天气晴朗或者少云/部分有云。 
2: 有雾和云/风等。 
3: 小雪/小雨,闪电及多云。 
4: 大雨/冰雹/闪电和大雾/大雪。

(6) temp - 摄氏温度。

(7) atemp - 人们感觉的温度。

(8) humidity - 湿度。

(9) windspeed - 风速。

(10) casual -随机预定自行车的人数

(11) registered - 登记预定自行车的人数。

(12) count - 总租车数,即casual+registered数目。

其中10~12不属于特征,12为我们需要预测的值。

各因素之间的相关性

fig = plt.figure(figsize=(15,10))
mask = np.zeros_like(df.corr())
mask[np.triu_indices_from(mask)] = True
with sns.axes_style("white"):
    sns.heatmap(df.corr(),annot = True,center=2,linewidth=.5,cmap="YlGnBu",mask=mask)

各因素之间的相关性

除registered和casual这种直接与count想关联的字段外,与count关系最密切的因素为temp和atemp,并且temp和atemp相关度极高,可以推测到:影响自行车租借量的最重要因素极有可能是气温。

另外湿度与租借量的相关度也较高,可见人们都喜欢在晴朗的天气(湿度小)中骑车。

租借时间分布

这里我们并不打算做一个时间序列模型,所以,我们不考虑时间的前后关联关系,而是把时间看成一种周期性的特征。为了更好地处理时间特征,需要将时间中的月、日和小时单独分出。

df['month'] = pd.DatetimeIndex(df.datetime).month
df['day'] = pd.DatetimeIndex(df.datetime).dayofweek
df['hour'] = pd.DatetimeIndex(df.datetime).hour
df = df.drop('datetime',axis=1)

1.租借时间总览

plt.figure(figsize=(10,5))
plt.title("Rent count in different hours")
sns.boxplot(x = 'hour',y = 'count',data=df)
<matplotlib.axes._subplots.AxesSubplot at 0x14f05ba8>

租借时间总览

2.工作日与双休日租借时间分布对比

plt.figure(figsize=(10,10))
plt.subplot(2,1,1)
plt.title("Rent Time in WeekDay")
sns.swarmplot(x = 'hour',y = 'count',data = df[df['workingday']==1])
plt.subplot(2,1,2)
plt.title("Rent Time in WeekEnd")
sns.swarmplot(x = 'hour',y = 'count',data = df[df['workingday']==1])
<matplotlib.axes._subplots.AxesSubplot at 0x129d5eb8>

工作日与双休日租借时间分布对比

可见,周一到周五骑行时间主要集中在上下班时间,主要是通勤需求;而周末骑行时间集中在中午前后,主要是出游需求。

3.不同季节的骑行量对比

plt.figure(figsize=(15,15))
plt.subplot(3,1,1)
plt.title("Rent count in different month")
sns.pointplot(x = 'month',y = 'count',data = df)
plt.subplot(3,1,2)
plt.title("Temperature in different month")
sns.barplot(x = 'month',y = 'temp',data = df)
plt.subplot(3,1,3)
plt.title("Rent count in different temperature")
df['temp'] = df['temp'].astype('int')
sns.pointplot(x = 'temp',y = 'count',data = df)
<matplotlib.axes._subplots.AxesSubplot at 0x116385c0>

不同季节的租借量

人们更倾向于在夏季骑车,在32℃时租借量达到顶点,气温下降之后,人们开始转向其他出行方式,3℃时,租借量到达谷底。

4.天气与租借量的关系

plt.figure(figsize=(15,15))
plt.subplot(3,1,1)
plt.title("Rent count in different weather")
sns.boxplot(x = 'weather',y = 'count',data = df)
plt.subplot(3,1,2)
plt.title("Rent count in different humidity")
sns.pointplot(x = 'humidity',y = 'count',data = df)
plt.subplot(3,1,3)
plt.title("Rent count in different windspeed")
sns.pointplot(x = 'windspeed',y = 'count',data = df)
<matplotlib.axes._subplots.AxesSubplot at 0x164b6908>

天气与租借量的关系

总体来说,人们更愿意在天气晴朗、湿度较小,风速正常的天气下骑车。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 数据总览
  • 字段描述
  • 各因素之间的相关性
  • 租借时间分布
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档