# Predicting number of cars

I am predicting the number of cars from a traffic dataset.

Here is my data dictionary:

The ‘Traffic-Major-Roads(kilometres)’ file contains the following variables (variable names are in bold):

• Year - Traffic volumes are shown for each year from 2000 onwards.
• ONS GOR Name – the former Government Office Region that the CP sits within.
• ONS LA Name – the local authority that the CP sits within.
• Road – this is the road name (for instance M25 or A3).
• RCat – the classification of the road type (see data definitions for the full list).
• S Ref E – Easting coordinates of the CP location.
• S Ref N – Easting coordinates of the CP location.
• A-Junction – The road name of the start junction of the link
• B-Junction – The road name of the end junction of the link
• LenNet – Total length of the network road link for that CP (in kilometres).
• PC – Traffic volume (in thousands of vehicle kilometres) for pedal cycles.
• 2WMV – Traffic volume (in thousands of vehicle kilometres) for two-wheeled motor vehicles.
• Car - Traffic volume (in thousands of vehicle kilometres) for Cars and Taxis.
• Bus – Traffic volume (in thousands of vehicle kilometres) for Buses and Coaches
• LGV – Traffic volume (in thousands of vehicle kilometres) for LGVs.
• HGVR2 – Traffic volume (in thousands of vehicle kilometres) for two-rigid axle HGVs.
• HGVR3 – Traffic volume (in thousands of vehicle kilometres) for three-rigid axle HGVs.
• HGVR4 – Traffic volume (in thousands of vehicle kilometres) for four or more rigid axle HGVs.
• HGVA3 – Traffic volume (in thousands of vehicle kilometres) for three or fourarticulated axle HGVs.
• HGVA5 – Traffic volume (in thousands of vehicle kilometres) for five-articulated axle HGVs.
• HGVA6 – Traffic volume (in thousands of vehicle kilometres) for six-articulated axle HGVs.
• HGV – Traffic volume (in thousands of vehicle kilometres) for all HGVs.
• AMV – Traffic volume (in thousands of vehicle kilometres) for all motor vehicles.

I need to predict the variable AMV.

So, I have one-hot encoded Road, and kept date, time in my features. But, number of Roads being very large. I have too many features.

Can you please suggest how should I proceed?

I am having too many features.

No, you don't :).

First of all, it is highly likely that not all of them are important for the prediction that you want to make.

I would highly recommend using a CART Random Forest for regression of the variable of interest. It literally requires minimal coding if you choose to do it in python using the RF algorithm from the sklearn package.

It's big advantage is that it is straightforward to use and understand and, moreover, it provides you with the learnt feature_importances_ of all inputs after training, so that you can exclude the least important ones and speed up the inference/training in the future.

-EDIT-

To understand the difference between Classification and Regression Decision trees, check this helpful link.

The decision tree implementations for regression are commonly the C4.5, the C5.0 or the CART algorithm. The one that is used by sklearn is CART, please take a look at section 1.10.6 in this link.

A good example of how to use the sklearn Decision Tree for regression is this.

• hi @pcko1 , thanks for your reply. I have one more doubt. I thought Random Forest is used in classification problems, but this is a regression problem . How can I use it ? Should I look for PCA ? – DukeLover Jul 2 '18 at 18:13
• I edited my answer, kindly check :) – pcko1 Jul 2 '18 at 19:15
• hi @pcko1 , thanks for really insightful and valuable answer. I applied RandomForestRegressor which gave me a significantly lower RMSE. But , I am not sure how to discard the insignificant features. Can you please help me ? Here is my link to kernel : Predicting car count – DukeLover Jul 3 '18 at 10:12
• it is really simple. Check the example in the middle of this page: scikit-learn.org/stable/modules/generated/…. After you print the feature importances (as shown in the example), you will have an understanding of which features are the least important (lowest importance values). Then you can manually exclude them from the next training of your algorithm. – pcko1 Jul 3 '18 at 10:52

From what I understand, your question is regarding feature selection. If that is the case, you could try lasso regression, which is a regularization technique that shrink coefficients of the predictors, thereby helping with feature selection. Hope that helps.

Even I agree that the number of features is less.