Skip to content

Instantly share code, notes, and snippets.

@gabraganca
Created April 5, 2019 12:13
Show Gist options
  • Save gabraganca/23411f0fb5a21147764eb2326ad97671 to your computer and use it in GitHub Desktop.
Save gabraganca/23411f0fb5a21147764eb2326ad97671 to your computer and use it in GitHub Desktop.
# Implementação baseada em
# https://github.com/NicolasHug/Surprise/blob/master/examples/benchmark.py
set_cell_seed(MY_SEED)
# Os algortimos para verificar
classes = (SVD, BaselineOnly)
kf = KFold(random_state=MY_SEED) # certifica que as dobras serão as mesmas
table = []
for klass in classes:
start = time.time()
out = cross_validate(klass(), data, ['rmse', 'mae'], kf, n_jobs=-1)
cv_time = str(datetime.timedelta(seconds=int(time.time() - start)))
mean_rmse = '{:.3f}'.format(np.mean(out['test_rmse']))
mean_mae = '{:.3f}'.format(np.mean(out['test_mae']))
new_line = [klass.__name__, mean_rmse, mean_mae, cv_time]
table.append(new_line)
header = ['Algoritmo',
'RMSE',
'MAE',
'Tempo'
]
pd.DataFrame(table, columns=header)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment