# Is linear regression fit for this data

I am predicting number of vehicles in 4 traffic junctions.

So, I have following columns in my dataset :

1. DateTime
2. Junction_ID
3. Number_of_vehicles

At the first glance , this problem may look like Time series regression. But, the data given seems like Linear Regression problem.

So, I have applied linear regression in the following manner :

• Used get_dummies extensively for all the columns. I used dummy variables for 31 days,24 hours ,7 days of weeks and 4 Junction Ids.
• Then applied Linear Regression model

from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(train_data,train_vehicles)

clf.fit(x_train,y_train)

import math

pred=clf.predict(x_test)

pred.shape #got result as (12030,)

result = []
for x in pred:
result.append(math.ceil(x))

from sklearn.metrics import mean_squared_error

score=mean_squared_error(y_test, result)
rmse=math.sqrt(score)
print('RMSE is :', rmse)


I am getting RMSE value as 10.636853077462394

My questions are :

• Since RMSE value is on lower side , can I say this model is decent ?
• Is there any other approach which I can use on this dataset ?
• Do I need to check for colinearity ?
• How can I check if multiple variables are interrelated ?
• Should I go for non-linear regression on this dataset ?
• Why do you say that the given data indicates regression and not time series? These are not exclusive categories.
– Paul
Feb 12, 2018 at 22:05
• hi @Paul : Since RMSE value is quite lower for Linear Regression , I am assuming this is Linear Regression data. Please correct me , if I am wrong. Feb 12, 2018 at 22:58

For the first question, it is important to recall that RMSE has the same unit as the dependent variable. It means that there is no absolute good or bad threshold, however you can define it based on your DV. For a datum which ranges from 0 to 1000, an RMSE of 0.7 is small, but if the range goes from 0 to 1, it is not small.

I would do some feature engineering (Create more variables: Time of Day, Day of Week, Month etc...) and run it through a Neural Network and then check for accuracy. You may want to check if there is any correlation between the 4 junctions as well but if you run a NN, you don't have to.

• Is the target variable likely to be linearly, or additively dependent on the inputs? This means Monday will always have, say 10 more vehicles than Tuesday. If it is more intuitive to say that Monday will have 10% more vehicles than Tuesday, you can consider a log-linear model: transform the target variable by taking a log.
• In addition to measuring RMSE, you may want to visualize the data and predictions. Plot the actual and predicted vehicles on y-axis and date on x-axis, separately for each junction. This should tell you something about how good your model is, and potentially where it is going wrong.
• Based on the method of defining the time variables, the features are not likely to correlated to each other.

There is a misconception about RMSE and other measurements for prediction quality, if you look at them standalone. In statistics you actually work with different models to compare RMSE's (using other approaches or other input variables) to have insights about prediction quality.

Moreover, to conclude if a model is appropiate given your data you test the model assumptions. In linear Regression:

• Estimation Error follows a Normal distribution with E(mean) = 0, and sigma²
• Errors and input data are not autocorrelated (Find Beusch Godfrey - test, or ACF-Plot)
• No multicollinearity (Your dependent variables are not too strongly correlated - Pearson Correlation)
• Homoscedasticity (implied by normal distribution and independent error - Find White's test)

However, good estimation doesn't necessarily lead to better predictions

Welcome to the site! You could also ask yourself, "Is data science fit for this data?"

Not all datasets require some sort of algorithmic approach. Depending on what you're going after, this may not be a data science problem. In traffic studies, a good number of problems are solved with "plain" statistics. For example, you could use the Poisson Distribution to solve any number of issues with your current dataset and that can be very effective even though it has relatively little to do with data science.