文章目录

  • 一、数据收集
    • 1.1、项目说明
    • 1.2、数据内容及变量说明
  • 二、数据处理
    • 2.1、导入数据
    • 2.2、缺失值处理
    • 2.3、Label数据(即count)异常值处理
    • 2.4、其他数据异常值处理
    • 2.5、时间型数据数据处理
  • 三、数据分析
    • 3.1 描述性分析
    • 3.2、探索性分析
      • 3.2.1、整体性分析
      • 3.2.2、相关性分析
      • 3.2.3、影响因素分析
        • 3.2.3.1、时段对租赁数量的影响
        • 3.2.3.2、温度对租赁数量的影响
        • 3.2.3.3、 湿度对租赁数量的影响
        • 3.2.3.4、年份、月份对租赁数量的影响
        • 3.2.3.5、季节对出行人数的影响
        • 3.2.3.6、天气情况对出行情况的影响
        • 3.2.3.7、风速对出行情况的影响
        • 3.2.3.8、日期对出行的影响
    • 3.3、预测性分析
      • 3.3.1、选择特征值
      • 3.3.2、训练集、测试集分离
      • 3.3.3、多余特征值舍弃
      • 3.3.4、选择模型、训练模型
      • 3.3.5、预测测试集数据

一、数据收集

1.1、项目说明

自行车共享系统是一种租赁自行车的方法,注册会员、租车、还车都将通过城市中的站点网络自动完成,通过这个系统人们可以根据需要从一个地方租赁一辆自行车然后骑到自己的目的地归还。在这次比赛中,参与者需要结合历史天气数据下的使用模式,来预测D.C.华盛顿首都自行车共享项目的自行车租赁需求。

1.2、数据内容及变量说明

比赛提供了跨越两年的每小时租赁数据,包含天气信息和日期信息,训练集由每月前19天的数据组成,测试集是每月第二十天到当月底的数据。

二、数据处理

2.1、导入数据

import matplotlib.pyplot as pltimport seaborn as sns
sns.set(style='whitegrid' , palette='tab10')train=pd.read_csv(r'D:\A\Data\ufo\train.csv',encoding='utf-8')
train.info()test=pd.read_csv(r'D:\A\Data\ufo\test.csv',encoding='utf-8')
print(test.info())

2.2、缺失值处理

#可视化查询缺失值
import missingno as msno
msno.matrix(train,figsize=(12,5))
msno.matrix(test,figsize=(12,5))


本次数据没有缺失值,不需要进行缺失值处理。

2.3、Label数据(即count)异常值处理

#观察训练集数据描述统计
train.describe().T


先从数值型数据入手,可以看出租赁额(count)数值差异大,再观察一下它们的密度分布:

#观察租赁额密度分布
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
fig.set_size_inches(6,5)sns.distplot(train['count'])
ax.set(xlabel='count',title='Distribution of count',)


发现数据密度分布的偏斜比较严重,且有一个很长的尾,所以希望能把这一列数据的长尾处理一下,先排除掉3个标准差以外的数据试一下能不能满足要求

train_WithoutOutliers = train[np.abs(train['count']-train['count'].mean())<=(3*train['count'].std())]
print(train_WithoutOutliers.shape)
train_WithoutOutliers['count'] .describe()


与处理前对比不是很明显,可视化展示对比看一下:

fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(1, 2, 2)
fig.set_size_inches(12,5)sns.distplot(train_WithoutOutliers['count'],ax=ax1)
sns.distplot(train['count'],ax=ax2)ax1.set(xlabel='count',title='Distribution of count without outliers',)
ax2.set(xlabel='registered',title='Distribution of count')


可以看到数据波动依然很大,而我们希望波动相对稳定,否则容易产生过拟合,所以希望对数据进行处理,使得数据相对稳定,此处选择对数变化,来使得数据稳定。

yLabels=train_WithoutOutliers['count']
yLabels_log=np.log(yLabels)
sns.distplot(yLabels_log)


经过对数变换后数据分布更均匀,大小差异也缩小了,使用这样的标签对训练模型是有效果的。接下来对其余的数值型数据进行处理,由于其他数据同时包含在两个数据集中,为方便数据处理先将两个数据集合并。

Bike_data=pd.concat([train_WithoutOutliers,test],ignore_index=True)
#查看数据集大小
Bike_data.shape

2.4、其他数据异常值处理

fig, axes = plt.subplots(2, 2)
fig.set_size_inches(12,10)sns.distplot(Bike_data['temp'],ax=axes[0,0])
sns.distplot(Bike_data['atemp'],ax=axes[0,1])
sns.distplot(Bike_data['humidity'],ax=axes[1,0])
sns.distplot(Bike_data['windspeed'],ax=axes[1,1])axes[0,0].set(xlabel='temp',title='Distribution of temp',)
axes[0,1].set(xlabel='atemp',title='Distribution of atemp')
axes[1,0].set(xlabel='humidity',title='Distribution of humidity')
axes[1,1].set(xlabel='windspeed',title='Distribution of windspeed')


通过这个分布可以发现一些问题,比如风速为什么0的数据很多,而观察统计描述发现空缺值在1–6之间,从这里似乎可以推测,数据本身或许是有缺失值的,但是用0来填充了,但这些风速为0的数据会对预测产生干扰,希望使用随机森林根据相同的年份,月份,季节,温度,湿度等几个特征来填充一下风速的缺失值。填充之前看一下非零数据的描述统计。

Bike_data[Bike_data['windspeed']!=0]['windspeed'].describe()

from sklearn.ensemble import RandomForestRegressorBike_data["windspeed_rfr"]=Bike_data["windspeed"]
# 将数据分成风速等于0和不等于两部分
dataWind0 = Bike_data[Bike_data["windspeed_rfr"]==0]
dataWindNot0 = Bike_data[Bike_data["windspeed_rfr"]!=0]
#选定模型
rfModel_wind = RandomForestRegressor(n_estimators=1000,random_state=42)
# 选定特征值
windColumns = ["season","weather","humidity","month","temp","year","atemp"]
# 将风速不等于0的数据作为训练集,fit到RandomForestRegressor之中
rfModel_wind.fit(dataWindNot0[windColumns], dataWindNot0["windspeed_rfr"])
# 通过训练好的模型预测风速
wind0Values = rfModel_wind.predict(X= dataWind0[windColumns])
#将预测的风速填充到风速为零的数据中
dataWind0.loc[:,"windspeed_rfr"] = wind0Values
#连接两部分数据
Bike_data = dataWindNot0.append(dataWind0)
Bike_data.reset_index(inplace=True)
Bike_data.drop('index',inplace=True,axis=1)

观察随机森林填充后的密度分布情况

fig, axes = plt.subplots(2, 2)
fig.set_size_inches(12,10)sns.distplot(Bike_data['temp'],ax=axes[0,0])
sns.distplot(Bike_data['atemp'],ax=axes[0,1])
sns.distplot(Bike_data['humidity'],ax=axes[1,0])
sns.distplot(Bike_data['windspeed_rfr'],ax=axes[1,1])axes[0,0].set(xlabel='temp',title='Distribution of temp',)
axes[0,1].set(xlabel='atemp',title='Distribution of atemp')
axes[1,0].set(xlabel='humidity',title='Distribution of humidity')
axes[1,1].set(xlabel='windseed',title='Distribution of windspeed')

2.5、时间型数据数据处理

Bike_data['date']=Bike_data.datetime.apply( lambda c : c.split( )[0])
Bike_data['hour']=Bike_data.datetime.apply( lambda c : c.split( )[1].split(':')[0]).astype('int')
Bike_data['year']=Bike_data.datetime.apply( lambda c : c.split( )[0].split('/')[0]).astype('int')
Bike_data['month']=Bike_data.datetime.apply( lambda c : c.split( )[0].split('/')[1]).astype('int')
Bike_data['weekday']=Bike_data.date.apply( lambda c : datetime.strptime(c,'%Y/%m/%d').isoweekday())
Bike_data.head()

三、数据分析

3.1 描述性分析

train.describe().T


温度, 体表温度, 相对湿度, 风速均近似对称分布, 而非注册用户, 注册用户,以及总数均右边分布。

for i in range(5, 12):name = train.columns[i]print('{0}偏态系数为 {1}, 峰态系数为 {2}'.format(name, train[name].skew(), train[name].kurt()))


temp, atemp, humidity低度偏态, windspeed中度偏态, casual, registered, count高度偏态;
temp, atemp, humidity为平峰分布, windspeed,casual, registered, count为尖峰分布。

3.2、探索性分析

3.2.1、整体性分析

sns.pairplot(Bike_data ,x_vars=['holiday','workingday','weather','season','weekday','hour','windspeed_rfr','humidity','temp','atemp'] ,y_vars=['casual','registered','count'] , plot_kws={'alpha': 0.1})


大致可以看出:

  1. 会员在工作日出行多,节假日出行少,临时用户则相反;
  2. 一季度出行人数总体偏少;
  3. 租赁数量随天气等级上升而减少;
  4. 小时数对租赁情况影响明显,会员呈现两个高峰,非会员呈现一个正态分布;
  5. 租赁数量随风速增大而减少;
  6. 温度、湿度对非会员影响比较大,对会员影响较小。

3.2.2、相关性分析

查看各个特征与每小时租车总量(count)的相关性

correlation = Bike_data.corr()
mask = np.array(correlation)
mask[np.tril_indices_from(mask)] = False
fig,ax= plt.subplots()
fig.set_size_inches(20,10)
sns.heatmap(correlation, mask=mask,vmax=.8, square=True,annot=True)plt.show()


count 和 registered、casual高度正相关,相关系数分别为0.7 与0.97。因为 count = casual + registered ,所以这个正相关和预期相符。count 和 temp 正相关,相关系数为 0.39。一般来说,气温过低人们不愿意骑车出行。count 和 humidity(湿度)负相关,湿度过大的天气不适宜骑车。当然考虑湿度的同时也应该考虑温度。windspeed似乎对租车人数影响不大(0.1),但我们也应该考虑到极端大风天气出现频率应该不高。风速在正常范围内波动应该对人们租车影响不大。可以看出特征值对租赁数量的影响力度为,时段>温度>湿度>年份>月份>季节>天气等级>风速>星期几>是否工作日>是否假日

3.2.3、影响因素分析

3.2.3.1、时段对租赁数量的影响

workingday_df=Bike_data[Bike_data['workingday']==1]
workingday_df = workingday_df.groupby(['hour'], as_index=True).agg({'casual':'mean','registered':'mean','count':'mean'})nworkingday_df=Bike_data[Bike_data['workingday']==0]
nworkingday_df = nworkingday_df.groupby(['hour'], as_index=True).agg({'casual':'mean','registered':'mean', 'count':'mean'})
fig, axes = plt.subplots(1, 2,sharey = True)workingday_df.plot(figsize=(15,5),title = 'The average number of rentals initiated per hour in the working day',ax=axes[0])
nworkingday_df.plot(figsize=(15,5),title = 'The average number of rentals initiated per hour in the nonworkdays',ax=axes[1])


通过对比可以看出:

  1. 工作日对于会员用户上下班时间是两个用车高峰,而中午也会有一个小高峰,猜测可能是外出午餐的人;
  2. 而对临时用户起伏比较平缓,高峰期在17点左右;
  3. 并且会员用户的用车数量远超过临时用户。
  4. 对非工作日而言租赁数量随时间呈现一个正态分布,高峰在14点左右,低谷在4点左右,且分布比较均匀。

3.2.3.2、温度对租赁数量的影响

先观察温度的走势

#数据按小时统计展示起来太麻烦,希望能够按天汇总取一天的气温中位数
temp_df = Bike_data.groupby(['date','weekday'], as_index=False).agg({'year':'mean','month':'mean','temp':'median'})#由于测试数据集中没有租赁信息,会导致折线图有断裂,所以将缺失的数据丢弃
temp_df.dropna ( axis = 0 , how ='any', inplace = True )
#预计按天统计的波动仍然很大,再按月取日平均值
temp_month = temp_df.groupby(['year','month'], as_index=False).agg({'weekday':'min','temp':'median'})
#将按天求和统计数据的日期转换成datetime格式
temp_df['date']=pd.to_datetime(temp_df['date'])#将按月统计数据设置一列时间序列
temp_month.rename(columns={'weekday':'day'},inplace=True)
temp_month['date']=pd.to_datetime(temp_month[['year','month','day']])#设置画框尺寸
fig = plt.figure(figsize=(18,6))
ax = fig.add_subplot(1,1,1)#使用折线图展示总体租赁情况(count)随时间的走势
plt.plot(temp_df['date'] , temp_df['temp'] , linewidth=1.3 , label='Daily average')
ax.set_title('Change trend of average temperature per day in two years')
plt.plot(temp_month['date'] , temp_month['temp'] , marker='o', linewidth=1.3 ,label='Monthly average')
ax.legend()                                                                  


可以看出每年的气温趋势相同随月份变化,在7月份气温最高,1月份气温最低,再看一下每小时平均租赁数量随温度变化的趋势。

#按温度取租赁额平均值
temp_rentals = Bike_data.groupby(['temp'], as_index=True).agg({'casual':'mean', 'registered':'mean','count':'mean'})
temp_rentals .plot(title = 'The average number of rentals initiated per hour changes with the temperature')


可观察到随气温上升租车数量总体呈现上升趋势,但在气温超过35时开始下降,在气温4度时达到最低点。

3.2.3.3、 湿度对租赁数量的影响

先观察湿度的走势:

4humidity_df = Bike_data.groupby('date', as_index=False).agg({'humidity':'mean'})
humidity_df['date']=pd.to_datetime(humidity_df['date'])
#将日期设置为时间索引
humidity_df=humidity_df.set_index('date')humidity_month = Bike_data.groupby(['year','month'], as_index=False).agg({'weekday':'min','humidity':'mean'})
humidity_month.rename(columns={'weekday':'day'},inplace=True)
humidity_month['date']=pd.to_datetime(humidity_month[['year','month','day']])fig = plt.figure(figsize=(18,6))
ax = fig.add_subplot(1,1,1)
plt.plot(humidity_df.index , humidity_df['humidity'] , linewidth=1.3,label='Daily average')
plt.plot(humidity_month['date'], humidity_month['humidity'] ,marker='o', linewidth=1.3,label='Monthly average')
ax.legend()
ax.set_title('Change trend of average humidity per day in two years')


湿度的变化幅度不是很大,多数围绕60上下浮动,本次数据范围内峰值为80。

humidity_rentals = Bike_data.groupby(['humidity'], as_index=True).agg({'casual':'mean','registered':'mean','count':'mean'})
humidity_rentals .plot (title = 'Average number of rentals initiated per hour in different humidity')


可以观察到在湿度20左右租赁数量迅速达到高峰值,此后缓慢递减。

3.2.3.4、年份、月份对租赁数量的影响

观察两年时间里,总租车数量随时间变化的趋势

#数据按小时统计展示起来太麻烦,希望能够按天汇总
count_df = Bike_data.groupby(['date','weekday'], as_index=False).agg({'year':'mean','month':'mean','casual':'sum','registered':'sum','count':'sum'})
#由于测试数据集中没有租赁信息,会导致折线图有断裂,所以将缺失的数据丢弃
count_df.dropna ( axis = 0 , how ='any', inplace = True )#预计按天统计的波动仍然很大,再按月取日平均值
count_month = count_df.groupby(['year','month'], as_index=False).agg({'weekday':'min','casual':'mean', 'registered':'mean','count':'mean'})#将按天求和统计数据的日期转换成datetime格式
count_df['date']=pd.to_datetime(count_df['date'])#将按月统计数据设置一列时间序列
count_month.rename(columns={'weekday':'day'},inplace=True)
count_month['date']=pd.to_datetime(count_month[['year','month','day']])#设置画框尺寸
fig = plt.figure(figsize=(18,6))
ax = fig.add_subplot(1,1,1)#使用折线图展示总体租赁情况(count)随时间的走势
plt.plot(count_df['date'] , count_df['count'] , linewidth=1.3 , label='Daily average')
ax.set_title('Change trend of average number of rentals initiated  per day in two years')
plt.plot(count_month['date'] , count_month['count'] , marker='o', linewidth=1.3 , label='Monthly average')
ax.legend()


可以看出:

  1. 共享单车的租赁情况2012年整体是比2011年有增涨的;
  2. 租赁情况随月份波动明显;
  3. 数据在2011年9到12月,2012年3到9月间波动剧烈;
  4. 有很多局部波谷值。

3.2.3.5、季节对出行人数的影响

在对年份月份因素的数据分析图中发现存在很多局部低谷,所以将租赁数量按季节取中位数展示,同时观察季节的温度变化

day_df=Bike_data.groupby('date').agg({'year':'mean','season':'mean','casual':'sum', 'registered':'sum','count':'sum','temp':'mean','atemp':'mean'})season_df = day_df.groupby(['year','season'], as_index=True).agg({'casual':'mean', 'registered':'mean','count':'mean'})season_df .plot(figsize=(18,6),title = 'The trend of average number of rentals initiated per day changes with season')

temp_df = day_df.groupby(['year','season'], as_index=True).agg({'temp':'mean', 'atemp':'mean'})
temp_df.plot(figsize=(18,6),title = 'The trend of average temperature per day changes with season')


可以看出无论是临时用户还是会员用户用车的数量都在秋季迎来高峰,而春季度用户数量最低。

3.2.3.6、天气情况对出行情况的影响

考虑到不同天气的天数不同,例如非常糟糕的天气(4)会很少出现,查看一下不同天气等级的数据条数,再对租赁数量按天气等级取每小时平均值。

count_weather = Bike_data.groupby('weather')
count_weather[['casual','registered','count']].count()

weather_df = Bike_data.groupby('weather', as_index=True).agg({'casual':'mean','registered':'mean'})
weather_df.plot.bar(stacked=True,title = 'Average number of rentals initiated per hour in different weather')


此处存在不合理数据:天气等级4的时候出行人数并不少,尤其是会员出行人数甚至比天气等级2的平均值还高,按理说4等级的应该是最少的,将天气等级4的数据打印出来找一下原因:

Bike_data[Bike_data['weather']==4]


观察可知该数据是在上下班高峰期产生的,所以该数据是个异常数据。不具有代表性。

3.2.3.7、风速对出行情况的影响

两年时间内风速的变化趋势

windspeed_df = Bike_data.groupby('date', as_index=False).agg({'windspeed_rfr':'mean'})
windspeed_df['date']=pd.to_datetime(windspeed_df['date'])
#将日期设置为时间索引
windspeed_df=windspeed_df.set_index('date')windspeed_month = Bike_data.groupby(['year','month'], as_index=False).agg({'weekday':'min','windspeed_rfr':'mean'})
windspeed_month.rename(columns={'weekday':'day'},inplace=True)
windspeed_month['date']=pd.to_datetime(windspeed_month[['year','month','day']])fig = plt.figure(figsize=(18,6))
ax = fig.add_subplot(1,1,1)
plt.plot(windspeed_df.index , windspeed_df['windspeed_rfr'] , linewidth=1.3,label='Daily average')
plt.plot(windspeed_month['date'], windspeed_month['windspeed_rfr'] ,marker='o', linewidth=1.3,label='Monthly average')
ax.legend()
ax.set_title('Change trend of average number of windspeed  per day in two years')


可以看出风速在2011年9月份和2011年12月到2012年3月份间波动和大,观察一下租赁人数随风速变化趋势,考虑到风速特别大的时候很少,如果取平均值会出现异常,所以按风速对租赁数量取最大值。


windspeed_rentals = Bike_data.groupby(['windspeed'], as_index=True).agg({'casual':'max', 'registered':'max','count':'max'})
windspeed_rentals .plot(title = 'Max number of rentals initiated per hour in different windspeed')


可以看到租赁数量随风速越大租赁数量越少,在风速超过30的时候明显减少,但风速在风速40左右却有一次反弹,打印数据找一下反弹原因:

df2=Bike_data[Bike_data['windspeed']>40]
df2=df2[df2['count']>400]
df2


该条数据产生在上下班高峰期时期,所以也是个异常值,不具有代表性。

3.2.3.8、日期对出行的影响

考虑到相同日期是否工作日,星期几,以及所属年份等信息是一样的,把租赁数据按天求和,其它日期类数据取平均值


day_df = Bike_data.groupby(['date'], as_index=False).agg({'casual':'sum','registered':'sum','count':'sum', 'workingday':'mean','weekday':'mean','holiday':'mean','year':'mean'})
day_df.head()

6number_pei=day_df[['casual','registered']].mean()
number_pei

plt.axes(aspect='equal')
plt.pie(number_pei, labels=['casual','registered'], autopct='%1.1f%%', pctdistance=0.6 , labeldistance=1.05 , radius=1 )
plt.title('Casual or registered in the total lease')


工作日
由于工作日和休息日的天数差别,对工作日和非工作日租赁数量取了平均值,对一周中每天的租赁数量求和

workingday_df=day_df.groupby(['workingday'], as_index=True).agg({'casual':'mean', 'registered':'mean'})
workingday_df_0 = workingday_df.loc[0]
workingday_df_1 = workingday_df.loc[1]# plt.axes(aspect='equal')
fig = plt.figure(figsize=(8,6))
plt.subplots_adjust(hspace=0.5, wspace=0.2)     #设置子图表间隔
grid = plt.GridSpec(2, 2, wspace=0.5, hspace=0.5)   #设置子图表坐标轴 对齐plt.subplot2grid((2,2),(1,0), rowspan=2)
width = 0.3       # 设置条宽p1 = plt.bar(workingday_df.index,workingday_df['casual'], width)
p2 = plt.bar(workingday_df.index,workingday_df['registered'], width,bottom=workingday_df['casual'])
plt.title('Average number of rentals initiated per day')
plt.xticks([0,1], ('nonworking day', 'working day'),rotation=20)
plt.legend((p1[0], p2[0]), ('casual', 'registered'))plt.subplot2grid((2,2),(0,0))
plt.pie(workingday_df_0, labels=['casual','registered'], autopct='%1.1f%%', pctdistance=0.6 , labeldistance=1.35 , radius=1.3)
plt.axis('equal')
plt.title('nonworking day')plt.subplot2grid((2,2),(0,1))
plt.pie(workingday_df_1, labels=['casual','registered'], autopct='%1.1f%%', pctdistance=0.6 , labeldistance=1.35 , radius=1.3)
plt.title('working day')
plt.axis('equal') 

weekday_df= day_df.groupby(['weekday'], as_index=True).agg({'casual':'mean', 'registered':'mean'})
weekday_df.plot.bar(stacked=True , title = 'Average number of rentals initiated per day by weekday')


对比图可发现:

  1. 工作日会员用户出行数量较多,临时用户出行数量较少;
  2. 周末会员用户租赁数量降低,临时用户租赁数量增加。

节假日
由于节假日在一年中数量占比非常少,先来看一每年的节假日下有几天:

holiday_coun=day_df.groupby('year', as_index=True).agg({'holiday':'sum'})
holiday_coun


假期的天数占一年天数的份额十分少,所以对假期和非假期取日平均值

holiday_df = day_df.groupby('holiday', as_index=True).agg({'casual':'mean', 'registered':'mean'})
holiday_df.plot.bar(stacked=True , title = 'Average number of rentals initiated per day by holiday or not')


节假日会员或非会员使用量都比非节假日多,符合规律。

3.3、预测性分析

3.3.1、选择特征值

根据前面的观察,决定将时段(hour)、温度(temp)、湿度(humidity)、年份(year)、月份(month)、季节(season)、天气等级(weather)、风速(windspeed_rfr)、星期几(weekday)、是否工作日(workingday)、是否假日(holiday),11项作为特征值。由于CART决策树使用二分类,所以将多类别型数据使用one-hot转化成多个二分型类别

dummies_month = pd.get_dummies(Bike_data['month'], prefix= 'month')
dummies_season=pd.get_dummies(Bike_data['season'],prefix='season')
dummies_weather=pd.get_dummies(Bike_data['weather'],prefix='weather')
dummies_year=pd.get_dummies(Bike_data['year'],prefix='year')
#把5个新的DF和原来的表连接起来
Bike_data=pd.concat([Bike_data,dummies_month,dummies_season,dummies_weather,dummies_year],axis=1)

3.3.2、训练集、测试集分离

dataTrain = Bike_data[pd.notnull(Bike_data['count'])]
dataTest= Bike_data[~pd.notnull(Bike_data['count'])].sort_values(by=['datetime'])
datetimecol = dataTest['datetime']
yLabels=dataTrain['count']
yLabels_log=np.log(yLabels)

3.3.3、多余特征值舍弃


dropFeatures = ['casual' , 'count' , 'datetime' , 'date' , 'registered' ,'windspeed' , 'atemp' , 'month','season','weather', 'year' ]dataTrain = dataTrain.drop(dropFeatures , axis=1)
dataTest = dataTest.drop(dropFeatures , axis=1)

3.3.4、选择模型、训练模型

rfModel = RandomForestRegressor(n_estimators=1000 , random_state = 42)rfModel.fit(dataTrain , yLabels_log)preds = rfModel.predict( X = dataTrain)

3.3.5、预测测试集数据

predsTest= rfModel.predict(X = dataTest)submission=pd.DataFrame({'datetime':datetimecol , 'count':[max(0,x) for x in np.exp(predsTest)]})submission.to_csv(r'D:\A\Data\ufo\/bike_predictions.csv',index=False)

kaggle共享单车数据分析及预测(随机森林)相关推荐

  1. 数据分析:基于随机森林(RFC)对酒店预订分析预测

    数据分析:基于随机森林(RFC)对酒店预订分析预测 文章目录 数据分析:基于随机森林(RFC)对酒店预订分析预测 1.前言 2.数据探索 3.数据可视化分析 3.1酒店预订量和取消量 3.2酒店各月份 ...

  2. sql date类型_共享单车数据分析的SQL数据库设计

    SQL,发音为" sequel"(或SQL,如果愿意的话),是数据科学家的重要工具.实际上,它可以说是获取数据工作中最重要的语言.在共享单车数据分析的SQL设计中,我们将从入门者的 ...

  3. 摩拜共享单车数据分析项目报告

    文章目录 项目背景 数据探索 数据挖掘 数据分析 时间维度 空间维度 用户维度 项目背景 随着智能手机的普及和手机用户的激增,共享单车作为城市交通系统的一个重要组成部分,以绿色环保.便捷高效.经济环保 ...

  4. 毕业设计 题目:基于大数据的共享单车数据分析

    文章目录 0 前言 1 项目背景 2 项目分析思维导图 3 项目分析具体步骤 3.1 读取数据 3.2 数据分析 3.1.1 数据预处理--每日使用量分析 3.1.2 连续7天的单日使用分析结论 3. ...

  5. 共享单车数据分析的SQL数据库设计

    SQL,发音为" sequel"(或SQL,如果愿意的话),是数据科学家的重要工具.实际上,它可以说是获取数据工作中最重要的语言.在共享单车数据分析的SQL设计中,我们将从入门者的 ...

  6. kaggle 共享单车项目数据分析和单车租赁数预测

    项目背景 自行车共享系统是租用自行车的一种方式,在这里,通过遍布城市的信息亭网络,可以自动获得会员资格.租赁和自行车归还.使用这些系统,人们可以从一个地方租一辆自行车,并根据需要将其送回另一个地方.目 ...

  7. 机器学习实战(入门级) ------ Kaggle 泰坦尼克号幸存者预测 (随机森林,KNN,SVM)

    文章目录 前言 数据集介绍 gender_submision.csv: train.csv: test.csv 数据清洗 数据预处理 缺失值填充 数据优化 训练过程 SVM 完整代码 KNN K-Me ...

  8. 大数据分析案例-基于随机森林模型对北京房价进行预测

    目录 1.项目背景 2.项目简介 2.1数据说明 2.2技术工具 3.算法原理 4.项目实施步骤 4.1理解数据 4.2数据预处理 4.2.1缺失值处理 4.2.2重复值处理 4.2.3异常值处理 4 ...

  9. 数据分析案例-基于随机森林算法的商品评价情感分析

    目录 1.挖掘目标 2.分析方法与过程 2.1总体流程 2.2具体步骤 2.3结果分析 3.结论 摘 要:随着我国的信息化发展速度的加快,时代科技技术的进步以及我国联网设施不断完善.不断普及,网民人数 ...

最新文章

  1. 测试TI高速MOS驱动芯片 TPS28225 伴随着MOS半桥
  2. jQuery操作标签--样式、文本、属性操作, 文档处理
  3. 李连杰年度巨作霍元甲主题曲:周杰伦唱
  4. X264代码中一些参数的意义
  5. 稳定和性能如何兼顾?58大数据平台的技术演进与实践
  6. hun 暑期实训之打牌 cin与scanf的输入
  7. 某大型银行深化系统技术方案之八:核心层之异步流程控制机制
  8. 概率编程语言(Probabilistic Programming Languages)库 —— edward
  9. 1. golang 接入Discord做消息推送
  10. 计算机无法找到wifi,笔记本无线网络找不到,教您怎么解决笔记本找不到无线网络...
  11. raster包—projectRaster函数
  12. 阿里云gpu服务器计算性能,gpu服务器价格(最新收费标准)
  13. 糅合了《魔兽》和《第二人生》优点的新式游戏闪亮登场!
  14. 大学考试计算机基础应用试题及答案,大学计算机应用基础期末考试试卷及答案C...
  15. Python自动化之Excel去除相同数据
  16. 金蝶K3案例教程采购管理前台操作
  17. ROS入门——胡春旭老师《机器人开发实践》在ROS-Melodic下的编译
  18. prism 搭建prism项目
  19. 大数据常见应用场景及架构改进
  20. AI艺术奇幻之旅的诞生

热门文章

  1. 47.leetcode36_valid_suduko
  2. Weex 解决Print: Entry, :CFBundleIdentifier, Does Not Exist 错误方法
  3. 让窗体接受拖放, 并获取拖过来的文件信息 - 回复 海浪问 的问题
  4. memcmp()库函数实现
  5. 快两年的时间,我都干了啥
  6. 单片机检测220V交流电通断电路
  7. Linux kernel 同步机制(下篇)
  8. i=1,为什么 (++i)+(++i)=6?
  9. 单片机中通用的类型别名
  10. 基于深度学习模型的花卉图像分类代码_华为不止有鸿蒙!教你快速入门华为免编程深度学习神器ModelArts...