共享单车--数据分析

共享单车EDA与模型选择

import pandas as pd 
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
from datetime import datetime
import os
import  warnings
warnings.filterwarnings(action = 'ignore')

Kaggle-competition-bike-sharing-demand

EDA

data items

  1. Numerical type: (use directly)

    • temp: actual temperature
    • atemp: body temperature
    • humidity: humidity
    • windspeed: wind speed
    • casual: the number of bikes rented by unregistered users
    • registered: Number of registered users rented bikes
    • count: total number of rental bikes
  2. Time series:
    datetime: Change to a single year, month, day, hour, and week

  3. Categorized data: (create dummies )

    • season: season. 1: Spring; 2: Summer; 3: Autumn; 4: Winter
    • holiday: Whether it is a holiday. 0: No; 1: Yes
    • workingday: Whether it is a working day. 0: No; 1: Yes
    • weather: weather. 1: sunny; 2: cloudy; 3: light rain or snow; 4: severe weather

** 目标:通过将历史使用情况与天气数据相结合,预测华盛顿共享单车的租赁需求,从而预测自行车租赁需求

导入数据

# import data
 
df = pd.read_csv('train.csv')
print(df.head(),'\n','df.shape: {}'.format(df.shape))
              datetime  season  holiday  workingday  weather  temp   atemp  \
0  2011-01-01 00:00:00       1        0           0        1  9.84  14.395   
1  2011-01-01 01:00:00       1        0           0        1  9.02  13.635   
2  2011-01-01 02:00:00       1        0           0        1  9.02  13.635   
3  2011-01-01 03:00:00       1        0           0        1  9.84  14.395   
4  2011-01-01 04:00:00       1        0           0        1  9.84  14.395   

   humidity  windspeed  casual  registered  count  
0        81        0.0       3          13     16  
1        80        0.0       8          32     40  
2        80        0.0       5          27     32  
3        75        0.0       3          10     13  
4        75        0.0       0           1      1   
 df.shape: (10886, 12)
df.describe()
season holiday workingday weather temp atemp humidity windspeed casual registered count
count 10886.000000 10886.000000 10886.000000 10886.000000 10886.00000 10886.000000 10886.000000 10886.000000 10886.000000 10886.000000 10886.000000
mean 2.506614 0.028569 0.680875 1.418427 20.23086 23.655084 61.886460 12.799395 36.021955 155.552177 191.574132
std 1.116174 0.166599 0.466159 0.633839 7.79159 8.474601 19.245033 8.164537 49.960477 151.039033 181.144454
min 1.000000 0.000000 0.000000 1.000000 0.82000 0.760000 0.000000 0.000000 0.000000 0.000000 1.000000
25% 2.000000 0.000000 0.000000 1.000000 13.94000 16.665000 47.000000 7.001500 4.000000 36.000000 42.000000
50% 3.000000 0.000000 1.000000 1.000000 20.50000 24.240000 62.000000 12.998000 17.000000 118.000000 145.000000
75% 4.000000 0.000000 1.000000 2.000000 26.24000 31.060000 77.000000 16.997900 49.000000 222.000000 284.000000
max 4.000000 1.000000 1.000000 4.000000 41.00000 45.455000 100.000000 56.996900 367.000000 886.000000 977.000000
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10886 entries, 0 to 10885
Data columns (total 12 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   datetime    10886 non-null  object 
 1   season      10886 non-null  int64  
 2   holiday     10886 non-null  int64  
 3   workingday  10886 non-null  int64  
 4   weather     10886 non-null  int64  
 5   temp        10886 non-null  float64
 6   atemp       10886 non-null  float64
 7   humidity    10886 non-null  int64  
 8   windspeed   10886 non-null  float64
 9   casual      10886 non-null  int64  
 10  registered  10886 non-null  int64  
 11  count       10886 non-null  int64  
dtypes: float64(3), int64(8), object(1)
memory usage: 1020.7+ KB

缺失值分析

df.isnull().sum()
datetime      0
season        0
holiday       0
workingday    0
weather       0
temp          0
atemp         0
humidity      0
windspeed     0
casual        0
registered    0
count         0
dtype: int64
labels = df[:100]['datetime'].astype('str').
labels
  File "<ipython-input-6-ffccf8289615>", line 1
    labels = df[:100]['datetime'].astype('str').
                                                ^
SyntaxError: invalid syntax
plt.style
  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Cyclistic 是一家虚构的公司,提供自行车共享设施。该公司有两大类骑手:休闲骑手和年度会员。休闲骑手是使用单程通行证和全天通行证的人。年度会员有一年的通行证可以使用自行车。 描述性分析 我已经分别使用每个月的数据透视表进行了初步分析。 数据透视表 1:这描述了每个工作日的骑行次数和平均骑行时长。 数据透视表 2:这分析了每种可骑行类型(即停放自行车、经典自行车和电动自行车)的骑行次数和平均骑行长度。 数据透视表 3:它比较了每个成员类型(即休闲和年度)的乘车次数和平均乘车时间。 数据透视表 4:这显示了整个月的平均和最大骑行长度。 数据透视表 5:该表记录了每个起点站的骑行次数和平均骑行长度。 我已经整理了每个月的这些摘要,并放在一个电子表格中,以确定每月和季节性的分析。我发现的一些有趣的事实和趋势如下: 最长的骑行发生在 2021 年 6 月至 7 月,创下大约 38 天的记录! 一年中的几个月,即 5 月到 9 月,自行车骑行的次数很高,7 月本身记录了 822k 的峰值。 11 月至 2 月见证了低乘车人数。2 月创下了最低的降幅,仅有 5 万次骑行。 Streeter Dr & Grand Ave 是最受欢迎的起点站,一个月内乘坐次数高达 15,000 次。 每月比较 其他一些重要的观察结果是: 经典自行车是最受欢迎的选择,每 3 次骑行中就有 2 次使用经典自行车。 停放自行车是骑行超过 1 小时的人的最爱。 休闲骑手的平均骑行长度高于年度会员。几乎是后者的两倍。 周六和周日的骑行次数最多。这两天的平均骑行时间也创下了历史新高。 使用 SQL 进行年视图分析 我将使用 SQL 合并所有的月度数据来做一个整体的年度分析。我将使用 Microsoft SQL Server 来执行所有数据库操作。 所有分步查询都可以在这里找到bikesharecasestudy.sql。请务必查看bikeShareCaseStudyReport.docx以查看所有重要数据和输出。 该分析揭示了年度会员和休闲骑手之间的一些有趣趋势。以下是分析。 年末会员的乘车份额增加(超过 50%),加上临时会员的乘车份额下降。最大值记录在 1 月 (80%)。 休闲骑手的平均骑行时长是年度骑手的两倍多。 年度会员在一年内记录的乘车次数多于休闲骑手。 周六的骑行次数和平均骑行时长最高,其次是周六和周五。周末生意兴隆。 经典自行车是这两种骑手中最喜欢的类型。停靠自行车是最不受欢迎的。此外,休闲会员选择经典自行车进行长途骑行。 临时会员通常更喜欢周末而不是工作日。年度车手则相反,他们在所有日子里的人数都很高,周日大幅下降。 使用 R 进行年视图分析 对于使用 R 的分析,我使用了 4 个季度的数据 - 2019 年的 Q2、Q3、Q4 和 2020 年的 Q1 。可以在此处找到用于清理、合并、分析和可视化的脚本R_script.R。 分享 此阶段是将要向利益相关者展示的重要和相关信息可视化。 年度会员和休闲骑手之间最显着的区别之一是他们在工作日的运营模式。 有报告

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值