Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Performance comparision RGF VS FastRGF
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