If I have a dataset like this:
ID beg_lng beg_lat end_lng end_lat start_timestamp Time (sec)
0 -74.009087 40.713818 -74.004326 40.719986 1420950819 10
1 -73.971176 40.762428 -74.004181 40.742653 1420950819 1120
2 -73.994957 40.745079 -73.999939 40.73465 1421377541 321
Think of it a grocery shopping details of a delivery person. It has the starting lat/long where it starts and ending lat/long of destination. It also has the corresponding time it took in seconds (Time). start_timestamp is epoch in seconds of starting time.
Now if I want to build a regression model to predict the grocery delivery trip time, I tried first a basic crude method of linear regression with elastic net and put in all the above features (after standardizing them). I used the lat/long as given and didn't do much transformation.
However I get a very bad fit.
The mean train scores are [ 0.08447384 0.08447416 0.08447448 0.0844748 0.08447511 0.08448194
0.08448468 0.08448715 0.08448937 0.08449133 0.08453318 0.08451306
0.08446719 0.08439527 0.08429637 0.08253336 0.07888605 0.07359639
0.06619284 0.0578421 0.00454754 -0.00018343 -0.00018343 -0.00018343
-0.00018343]
The mean validation scores are [ 0.08389243 0.08389275 0.08389305 0.08389336 0.08389367 0.08390072
0.08390336 0.08390575 0.08390787 0.08390974 0.08395386 0.08393282
0.08388601 0.08381316 0.08371341 0.08197247 0.07835721 0.07306636
0.06565797 0.05737215 0.00448677 -0.00021397 -0.00021397 -0.00021397
-0.00021397]
The score on held out data is: 0.08395386395024673
Hyper-Parameters for Best Score : {'l1_ratio': 0.15, 'alpha': 0.01}
The R2 Score of sgd_regressor on test data is: 0.0864573982691922
The mse of sgd_regressor on test data is: 469651.012051
The mean absolute error of sgd_regressor on test data is: 422.247732739
Here is the Grid search code
def grid_search(self):
"""This function does Cross Validation using Grid Search
"""
from sklearn.model_selection import GridSearchCV
self.g_cv = GridSearchCV(estimator=self.estimator,param_grid=self.param_grid,cv=5)
self.g_cv.fit(self.train_X,self.train_Y)
And code to check the error:
def test_performance(self,name):
"""This method checks the performance of each algorithm on test data."""
from sklearn.metrics import mean_squared_error, mean_absolute_error
#
print("The R2 Score of "+ name + " on test data is: {}\n".format(self.g_cv.best_estimator_.score(self.test_X,self.test_Y)))
print ("The mse of "+ name + " on test data is:",\
mean_squared_error(test_Y, self.g_cv.best_estimator_.predict(self.test_X)))
print ("The mean absolute error of "+ name + " on test data is:",\
mean_absolute_error(test_Y, self.g_cv.best_estimator_.predict(self.test_X)))
Why am I getting such a bad R2 and errors? Any idea where I can be going wrong?