Skip to content

Instantly share code, notes, and snippets.

Avatar

Amy Ma yujingma45

View GitHub Profile
View BestModel.r
import time
start_time = time.time()
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
#from sklearn import pipeline, model_selection
from sklearn import pipeline, grid_search
#from sklearn.feature_extraction import DictVectorizer
from sklearn.base import BaseEstimator, TransformerMixin
View rg.r
> tuning.rg(ntrn,lambda,10,0.7)
[1] "=== cross validation error estimation ==="
[1] "lambda= 0.0001 : error= 11.0574771599181 +- 1.5911393576281"
[1] "lambda= 0.001 : error= 11.0554573634712 +- 1.59159985887222"
[1] "lambda= 0.01 : error= 11.0377334394576 +- 1.59698319488323"
[1] "lambda= 0.1 : error= 11.0537037442444 +- 1.70124419652984"
[1] "lambda= 1 : error= 14.7438810915394 +- 2.85190527401637"
[1] "lambda= 10 : error= 24.6020816723033 +- 5.47557805542126"
[1] "lambda= 100 : error= 40.0103673810083 +- 9.25347219989225"
[1] "lambda= 1000 : error= 56.4994813733851 +- 9.68175560688852"
View svm.r
> tuning.svm("normalized data",ntrn,cvec,10,0.7)
[1] "normalized data"
[1] "#########linear SVM#################"
[1] "parameter= 1 the best cost= 3.2 the error = 13.0911820319358"
[1] "########polynomial kernel SVM##########"
[1] "parameter= 2 the best cost= 1 the error = 36.0239737549915"
[1] "parameter= 3 the best cost= 1 the error = 15.5345486240454"
[1] "parameter= 4 the best cost= 0.32 the error = 33.5509708662857"
[1] "parameter= 5 the best cost= 0.32 the error = 41.9638713171909"
[1] "parameter= 6 the best cost= 0.032 the error = 45.8911349089365"
View nn.r
> tuning.nn(trn,neuron,10,0.7)
[1] "=== cross validation error estimation ==="
[1] "depth= 1 : error= 70.9794189514517 +- 15.904800477383"
[1] "depth= 2 : error= 70.9722170232778 +- 15.8954005190479"
[1] "depth= 3 : error= 71.0124803004767 +- 15.8597654828364"
[1] "depth= 4 : error= 70.5867870706421 +- 15.818947243105"
[1] "depth= 5 : error= 70.7432130613939 +- 15.6752259506747"
[1] "depth= 6 : error= 71.2585730501765 +- 16.1677503694949"
[1] "depth= 7 : error= 71.0870255049561 +- 16.0324643862916"
[1] "depth= 8 : error= 71.0129340109873 +- 15.9439431180934"
View rf.r
> tuning.rf(trn,mtry,20,0.7)
[1] "=== cross validation error estimation ==="
[1] "mtry= 2 : error= 9.89178214242082 +- 4.06175518360904"
[1] "mtry= 4 : error= 7.7269900435814 +- 2.53016370451501"
[1] "mtry= 6 : error= 7.48214012711454 +- 1.98854233231896"
[1] "mtry= 8 : error= 7.53741415199526 +- 1.78742904316897"
[1] "mtry= 10 : error= 7.92473002002763 +- 1.88953063618415"
[1] "mtry= 12 : error= 8.37506100241071 +- 1.9922333938174"
[1] "mtry= 14 : error= 8.61657448209067 +- 2.04644195003867"
[1] "mtry= 16 : error= 8.59454798339517 +- 2.05803385159497"
View gbm.r
> depth=c(1,2,3,4,5)
> tuning.gbm(trn,depth,20,0.7)
[1] "=== cross validation error estimation ==="
[1] "depth= 1 : error= 12.2088907005888 +- 2.63624188615258"
[1] "depth= 2 : error= 9.99951434560433 +- 2.30181005481302"
[1] "depth= 3 : error= 9.39671136126591 +- 2.19944247921552"
[1] "depth= 4 : error= 9.14194019449996 +- 2.16337261929302"
[1] "depth= 5 : error= 8.97911772123462 +- 2.18464631653844"
[1] 5
> #normalized data