I am trying to create a regression model using scikit-learn for predicting car price. The input data are, car model(trim), kilometers used, past resale price of similar car and age of used car. I am trying to predict the future resale price of the car.

I have done the preprocessing of data. I have tried using ARDRegression, RandomForestRegressor and finally MLPRegressor. But the prediction model doesn't seem to predict well, the prediction results seem to fall outside the range of training data.

Example: if the Actual value(actual selling price) is 748077.0 but predicted value is 1352960

Probably I have done some mistake but I am not able to figure out what it is. I have simplified the code to focus on prediction part and have shared the link.

Could someone please guide me.

This is the google colab notebook link

Update: Inverting the index of the dataframe iresults in total change of prediction.


I don't use Python so I can't tell you exactly what is going on but I had a quick look at your data:

data points showing relevant features

A few remarks:

  • it looks like the vast majority of the points are created artificially by interpolation. Why not, but that's unlikely to reflect the reality of the price changes: I would expect much more variation/noise in a real dataset about car prices.
  • there's no need to add so many points to the dataset anyway. With all this data there's not even a need to train a model, since virtually every possible instance is already in the data.
  • It seems to me that there's something weird with the prediction year: normally the higher the prediction year the more the price decreases right? here year 0 has no decrease at all, year 1 has the highest decrease,..., and year 4 has little to no decrease. That could confuse the model.
  • because it's mostly an artificial dataset the relation is very simple: a basic regression future_price = past_price * a + b would already give quite good results, and the relation can be learned perfectly when adding the prediction_year feature. At least MLP and random forest should give near perfect results.
  • From a quick look at the code, I suspect that the problem has to do with the scaling. I'm not sure what is supposed to happen there since I'm not familiar with these functions: it might be that the predicted values need to be "un-scaled" at the end maybe? Anyway I don't think scaling it's needed at all here.

For the record the graph was done with R like this:

  • $\begingroup$ I interpolated the data to make sure there isn't any issue in the input data itself. Year denotes age of car. usually car difference between cost of new and one year old car would be higher than the cost difference between 15 and 16 year old car. $\endgroup$ – Yoganand.N Oct 28 '19 at 14:56
  • $\begingroup$ Ok but for instance if the past price is 1000000, a 2 yo car future price is less than 900000 whereas a 3 yo car is more than 900000. It's strange that an older car would be more expensive for the same past price. $\endgroup$ – Erwan Oct 28 '19 at 15:33
  • $\begingroup$ But I don't see any such data, did you check if the kilometers used was same for both 2 year old and 3 year old? $\endgroup$ – Yoganand.N Oct 28 '19 at 16:12
  • $\begingroup$ Oh you're right, it's because of the different kms_used. So this shouldn't be an issue then, but still the graph I obtain is a bit strange: it looks as if the price can be determined without using kms_used. Maybe there's also the problem that the original data didn't have enough points? $\endgroup$ – Erwan Oct 28 '19 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.