3
$\begingroup$

I'm a beginner in machine learning and I want to build a model to predict the price of houses. I prepared a dataset by crawling a local housing website and it consists 1000 samples and only 4 features (latitude, longitude, area and number of rooms).

I tried RandomForestRegressorand LinearSVR models in sklearn, but I can't train the model properly and the MSE is super high.

MSE almost equals 90,000,000 (the true values of prices' range are between 5,000,000 - 900,000,000)

Here is my code:

import numpy as np
from sklearn.svm import LinearSVR
import pandas as pd
import csv
from sklearn.preprocessing import normalize
from sklearn.model_selection import train_test_split

df = pd.read_csv('dataset.csv', index_col=False)
X = df.drop('price', axis=1)

X_data = X.values
Y_data = df.price.values
X_train, X_test, Y_train, Y_test = train_test_split(X_data, Y_data, test_size=0.2, random_state=5)

rgr = RandomForestRegressor(n_estimators=100)
svr = LinearSVR()

rgr.fit(X_train, Y_train)
svr.fit(X_train, Y_train)

MSEs = cross_val_score(estimator=rgr,
                         X=X_train,
                         y=Y_train,
                         scoring='mean_squared_error',
                         cv=5)

MSEsSVR = cross_val_score(estimator=svr,
                         X=X_train,
                         y=Y_train,
                         scoring='mean_squared_error',
                         cv=5)

MSEs *= -1
RMSEs = np.sqrt(MSEs)

print("Root mean squared error with 95% confidence interval:")
print("{:.3f} (+/- {:.3f})".format(RMSEs.mean(), RMSEs.std()*2))
print("")

Is the problem with my dataset and count of features? How can I build a prediction model with this type of dataset?

$\endgroup$
6
  • $\begingroup$ The latitude, longitude, area and number of rooms might not be sufficient enough to predict the prices. If you have another features like the m2 of the house, number of baths etc, you should better add them.(For you to understand the importance of the features you can also try to exclude the number of rooms and see that MSE will be much higher). Also, think about that latitude, longitude and area can be correlated. $\endgroup$
    – kkk
    Jun 10, 2017 at 19:58
  • $\begingroup$ I've prepared this dataset by crawling a housing ads site and unfortunately I can't access any more features. I want to build the most accurate model that is possible with this kind of dataset. @JekaterinaKokatjuhha $\endgroup$ Jun 11, 2017 at 4:52
  • $\begingroup$ Try Linear Regression but maybe you have reached the the max accuracy $\endgroup$
    – kkk
    Jun 11, 2017 at 8:36
  • $\begingroup$ I tried the Linear Regression and the MSE is less than before (15.000.000). Is this the most accurate model that I can build with this dataset? @JekaterinaKokatjuhha $\endgroup$ Jun 11, 2017 at 15:18
  • $\begingroup$ Have a look what overfitting means and how to deal with it and try it out, you might get a better mse. $\endgroup$
    – kkk
    Jun 11, 2017 at 19:31

2 Answers 2

1
$\begingroup$

that's possibly due to poor parameter tuning.
Try reducing C for SVR and increasing n_estimators for RFR.

A nice approach is to gridsearch through the parameter, and plot the metric result.

Another thing that might help is to normalize the parameters (sklearn.preprocessing.StandardScaler) and to remove the skew from the target (usually log transform or 1/target transform works better)

$\endgroup$
1
  • $\begingroup$ reducing C for SVR and increasing n_estimators for RFR improved the score by almost 2 percent. At least I learned some thing new from your points. $\endgroup$ Jun 15, 2017 at 13:16
1
$\begingroup$

I removed 20 percent of most expensive houses from dataset and divided the prices by 1.000.000 and the result got much better.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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