Model and Accuracy
As we have to train the model to determine the continuous values, so we will be using these regression models.
- SVM-Support Vector Machine
- Random Forest Regressor
- Linear Regressor
And To calculate loss we will be using the mean_absolute_percentage_error module. It can easily be imported by using sklearn library. The formula for Mean Absolute Error :
SVM – Support vector Machine
SVM can be used for both regression and classification model. It finds the hyperplane in the n-dimensional plane. To read more about svm refer this.
Python3
from sklearn import svm from sklearn.svm import SVC from sklearn.metrics import mean_absolute_percentage_error model_SVR = svm.SVR() model_SVR.fit(X_train,Y_train) Y_pred = model_SVR.predict(X_valid) print (mean_absolute_percentage_error(Y_valid, Y_pred)) |
Output :
0.18705129
Random Forest Regression
Random Forest is an ensemble technique that uses multiple of decision trees and can be used for both regression and classification tasks. To read more about random forests refer this.
Python3
from sklearn.ensemble import RandomForestRegressor model_RFR = RandomForestRegressor(n_estimators = 10 ) model_RFR.fit(X_train, Y_train) Y_pred = model_RFR.predict(X_valid) mean_absolute_percentage_error(Y_valid, Y_pred) |
Output :
0.1929469
Linear Regression
Linear Regression predicts the final output-dependent value based on the given independent features. Like, here we have to predict SalePrice depending on features like MSSubClass, YearBuilt, BldgType, Exterior1st etc. To read more about Linear Regression refer this.
Python3
from sklearn.linear_model import LinearRegression model_LR = LinearRegression() model_LR.fit(X_train, Y_train) Y_pred = model_LR.predict(X_valid) print (mean_absolute_percentage_error(Y_valid, Y_pred)) |
Output :
0.187416838
CatBoost Classifier
CatBoost is a machine learning algorithm implemented by Yandex and is open-source. It is simple to interface with deep learning frameworks such as Apple’s Core ML and Google’s TensorFlow. Performance, ease-of-use, and robustness are the main advantages of the CatBoost library. To read more about CatBoost refer this.
Python3
# This code is contributed by @amartajisce from catboost import CatBoostRegressor cb_model = CatBoostRegressor() cb_model.fit(X_train, y_train) preds = cb_model.predict(X_valid) cb_r2_score = r2_score(Y_valid, preds) cb_r2_score |
0.893643437976127
House Price Prediction using Machine Learning in Python
We all have experienced a time when we have to look up for a new house to buy. But then the journey begins with a lot of frauds, negotiating deals, researching the local areas and so on.