Policy Information
Kaggle比赛之根据城市自行车共享系统数据预测在某个时间段自行车被租出去的个数
目录
- -meta">先把数据读进来
- import pandas as pd
- -class">data = pd.read_csv('F:/File_Python/Resources/data_csv_xls/kaggle_bike_competition_train.csv', header = 0, error_bad_lines=False)
-
- -meta">查看数据字段
- -class">data.head()
- -meta">datetime小时计数、season季节、holiday是否假期、workingday工作日、weather天气、temp华氏温度、atemp、humidity湿度、windspeed风速、
- -meta">casual非注册租车人数、registered注册租车人数
- -meta"> 处理时间字段:把datetime域切成日期、时间两个字段。
- temp = pd.DatetimeIndex(-class">data['datetime'])
- -class">data['date'] = temp.date
- -class">data['time'] = temp.time
- -class">data.head()
- 特征向量化
- 打算用scikit-learn来建模。对于pandas的dataframe我们有方法/函数可以直接转成python中的dict
- 还要对离散值和连续值特征区分一下了,以便之后分开做不同的特征处理。
-
- from sklearn.feature_extraction import DictVectorizer
-
-
- 我们把连续值的属性放入一个dict中
- featureConCols = ['temp','atemp','humidity','windspeed','dateDays','hour']
- dataFeatureCon = dataRel[featureConCols]
- dataFeatureCon = dataFeatureCon.fillna( 'NA' ) in case I missed any
- X_dictCon = dataFeatureCon.T.to_dict().values()
-
- 把离散值的属性放到另外一个dict中
- featureCatCols = ['season','holiday','workingday','weather','Saturday', 'Sunday']
- dataFeatureCat = dataRel[featureCatCols]
- dataFeatureCat = dataFeatureCat.fillna( 'NA' ) in case I missed any
- X_dictCat = dataFeatureCat.T.to_dict().values()
-
- 向量化特征
- vec = DictVectorizer(sparse = False)
- X_vec_cat = vec.fit_transform(X_dictCat)
- X_vec_con = vec.fit_transform(X_dictCon)
评论