Created
January 7, 2018 13:10
-
-
Save fukatani/3f757850b6adfe2d925548552a9cb367 to your computer and use it in GitHub Desktop.
Performance comparision RGF VS FastRGF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import numpy | |
from sklearn.datasets import load_boston | |
from sklearn.utils.validation import check_random_state | |
from sklearn.ensemble import RandomForestRegressor | |
from rgf.sklearn import FastRGFRegressor, RGFRegressor | |
boston = load_boston() | |
rng = check_random_state(42) | |
perm = rng.permutation(boston.target.size) | |
boston.data = boston.data[perm] | |
# dataset large enough | |
boston.data = numpy.hstack((boston.data, boston.data, boston.data, boston.data, boston.data)) | |
boston.data = numpy.hstack((boston.data, boston.data, boston.data, boston.data, boston.data)) | |
boston.data = numpy.hstack((boston.data, boston.data, boston.data, boston.data, boston.data)) | |
boston.data = numpy.hstack((boston.data, boston.data, boston.data, boston.data, boston.data)) | |
boston.data = numpy.hstack((boston.data, boston.data, boston.data, boston.data, boston.data)) | |
print('data shape ' + str(boston.data.shape)) | |
boston.target = boston.target[perm] | |
train_x = boston.data[100:] | |
test_x = boston.data[:100] | |
train_y = boston.target[100:] | |
test_y = boston.target[:100] | |
start = time.time() | |
reg = RGFRegressor() | |
reg.fit(train_x, train_y) | |
score = reg.score(test_x, test_y) | |
end = time.time() | |
print("RGF: {} sec".format(end - start)) | |
print("score: {}".format(score)) | |
start = time.time() | |
reg = FastRGFRegressor(min_samples_leaf=10, l2=10.0) | |
reg.fit(train_x, train_y) | |
score = reg.score(test_x, test_y) | |
end = time.time() | |
print("FastRGF: {} sec".format(end - start)) | |
print("score: {}".format(score)) | |
start = time.time() | |
reg = RandomForestRegressor() | |
reg.fit(train_x, train_y) | |
score = reg.score(test_x, test_y) | |
end = time.time() | |
print("Random Forest: {} sec".format(end - start)) | |
print("score: {}".format(score)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment