def train_session(root, train, test, sideinfo=None): import shutil shutil.rmtree(root, ignore_errors=True) os.makedirs(root) print("save prefix = ", root) trainSession = smurff.TrainSession( num_latent=4, burnin=800, nsamples=100, verbose=global_verbose, save_freq=1, save_prefix=root, ) trainSession.addTrainAndTest(train, test, smurff.FixedNoise(1.0)) if sideinfo is not None: trainSession.addSideInfo(0, sideinfo, smurff.FixedNoise(10.), direct=True) predictions = trainSession.run() rmse = smurff.calc_rmse(predictions) #print("RMSE = %.2f%s" % (rmse, "" if sideinfo is None else " (with sideinfo)" )) return rmse
def noise_fixed10(): return smurff.FixedNoise(10.0)
def noise_fixed5(): return smurff.FixedNoise(5.0)
def test_fixed10(self): self.run_session(smurff.FixedNoise(10.0))
def test_fixed5(self): self.run_session(smurff.FixedNoise(5.0))
def get_side_noise(self): return smurff.FixedNoise(10.)
def get_train_noise(self): return smurff.FixedNoise(1.0)
#!/usr/bin/env python import smurff import pickle Y = smurff.matrix_io.read_matrix("ratings_1k_random.sdm") Ytrain, Ytest = smurff.prepare.make_train_test(Y, 0.2) sideinfo = smurff.matrix_io.read_matrix("features_1k_random.sdm") trainSession = smurff.TrainSession(num_latent=8, burnin=200, nsamples=200, verbose=1, save_name="movielens.hdf5", save_freq=1) trainSession.addTrainAndTest(Ytrain, Ytest) trainSession.addSideInfo(0, sideinfo, smurff.FixedNoise(10.)) trainSession.run()