官术网_书友最值得收藏!

Handling time values

Time values play an important role in our model because time is both a feature and a target (value to be predicted) in our model. First, we need to convert the pickup and dropoff times into pandas datetime values to calculate the target value, which will be the natural log of the difference in time between dropoff and pickup in seconds:

df["trip_duration"] = np.log((df.Lpep_dropoff_datetime - df.lpep_pickup_datetime).dt.seconds + 1)

In the preceding line of code, we are adding 1 second to the trip duration to prevent an undefined error when a log transformation is applied over the value.

But why are we using natural log transformation over the trip duration? There are three reasons for this, as follows:

  • For the Kaggle competition on New York taxi trip duration prediction, the evaluation metric is defined as the Root Mean Squared Logarithmic Error (RMSLE). When log transformation is applied and the RMSE is calculated over the target values, we get the RMSLE. This helps us compare our results with the best-performing teams. 
  • Errors in log scale let us know by how many factors we were wrong, for example, whether we were 10% off from the actual values or 70% off. We will be discussing this in detail when we look at the Error metric section.
  • The log transformation over the target variable follows a perfectly normal distribution. This satisfies one of the assumptions of linear regression. The plot of the trip duration values (on a log scale) looks as follows:
主站蜘蛛池模板: 五大连池市| 峡江县| 大足县| 隆子县| 佛山市| 通海县| 宿州市| 绥中县| 拉萨市| 颍上县| 定西市| 察隅县| 松江区| 宜阳县| 邵武市| 旅游| 定南县| 英德市| 天气| 永昌县| 江川县| 本溪市| 盐边县| 玛沁县| 独山县| 永胜县| 凤山县| 邻水| 鲁山县| 郎溪县| 陈巴尔虎旗| 永济市| 海林市| 华池县| 全州县| 仙桃市| 赣榆县| 珲春市| 淳安县| 海晏县| 金沙县|