Model and application of machine learning for price prediction

When it comes to price prediction, the first thing we can think of is a competition on kaggle, about the prediction of housing prices, but in such a hot era of the real estate industry, it is also very interesting to make a Chinese version of housing price prediction, but what bloggers want to do is a pair of second-hand The prediction of equipment price is to predict the selling price by modeling various characteristics such as the type, age, used time, and geographical location of the second-hand equipment, but this is an easier application. Predicting the price of second-hand equipment with just a few pictures or a few pictures, I think this is more challenging.

The following price predictions are mainly constructed using the sk-learn package through linear regression models, decision tree (regression tree) models, xgboost, neural networks, support vector regression and other algorithm models.

1. Linear regression

from sklearn.linear_model import LinearRegression

2. Decision tree regression

from sklearn.tree import DecisionTreeRegressor

3. Support Vector Regression

from sklearn.svm import SVR  
linear_svr = SVR(kernel='linear')  
linear_svr.fit(x_train, y_train.ravel())  
linear_svr_predict = linear_svr.predict(x_test)  

4. Gradient Boosting Regression Algorithm

    import numpy as np  
    from sklearn.ensemble import GradientBoostingRegressor  
    gbdt=GradientBoostingRegressor(  
      loss='ls'  
    , learning_rate=0.1  
    , n_estimators = 100  
    , subsample=1  
    , min_samples_split=2  
    , min_samples_leaf=1  
    , max_depth=3  
    , init=None  
    , random_state=None  
    , max_features=None  
    , alpha=0.9  
    , verbose=0  
    , max_leaf_nodes=None  
    , warm_start=False  
    )  
    train_feat=np.genfromtxt("train_feat.txt",dtype=np.float32)  
    train_id=np.genfromtxt("train_id.txt",dtype=np.float32)  
    test_feat=np.genfromtxt("test_feat.txt",dtype=np.float32)  
    test_id=np.genfromtxt("test_id.txt",dtype=np.float32)  
    print train_feat.shape,rain_id.shape,est_feat.shape,est_id.shape  
    gbdt.fit(train_feat,train_id)  
    pred=gbdt.predict(test_feat)  
    total_err=0  
    for i in range(pred.shape[0]):  
        print pred[i],test_id[i]  
        err=(pred[i]-test_id[i])/test_id[i]  
        total_err+=err*err  
    print total_err/pred.shape[0]  

5. Random Forest Regression

from sklearn.ensemble import RandomForestRegressor

data=[[0,0,0],[1,1,1],[2,2,2],[1,1,1],[2,2,2],[0,0,0]]
target=[0,1,2,1,2,0]
rf = RandomForestRegressor()
rf.fit(data, target)

print rf.predict([[1,1,1]])
print rf.predict([[1,1,1],[2,2,2]])
#[ 1.]
#[ 1.  1.9]

data2=[[0,0,0],[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5]]
target2=[0,1,2,3,4,5]
rf2 = RandomForestRegressor()
rf2.fit(data2, target2)
print rf2.predict([[1,1,1]])
print rf2.predict([[1,1,1],[2,2,2],[4,4,4]])
#[ 0.7]
#[ 0.7  1.8  4. ]

6. Linear regression of xgboost

import xgboost as xgb
regr = xgb.XGBRegressor()

7. Neural Networks

You can use the neural network model to make predictions. This example is not available yet, and I will add it later.

Summary: This article mainly provides several options for rapid construction of price prediction models. Based on the above models, operations such as model fusion can also be done. For more in-depth understanding of some related content, refer to this article: Research on sales forecasting based on machine learning methods

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325697281&siteId=291194637