def test_train_save_load_predict(self): print "test train, save, load and predict..." xs = SklearnRandomForestTrainTestModel.get_xs_from_results( self.features) ys = SklearnRandomForestTrainTestModel.get_ys_from_results( self.features) xys = SklearnRandomForestTrainTestModel.get_xys_from_results( self.features) self.model = SklearnRandomForestTrainTestModel( { 'norm_type': 'normalize', 'random_state': 0 }, None) self.model.train(xys) self.model.to_file(self.model_filename) self.assertTrue(os.path.exists(self.model_filename)) loaded_model = SklearnRandomForestTrainTestModel.from_file( self.model_filename, None) result = loaded_model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.17634739353518517, places=4)
def test_train_save_load_predict(self): print "test train, save, load and predict..." xs = SklearnRandomForestTrainTestModel.get_xs_from_results(self.features) ys = SklearnRandomForestTrainTestModel.get_ys_from_results(self.features) xys = SklearnRandomForestTrainTestModel.get_xys_from_results(self.features) self.model = SklearnRandomForestTrainTestModel({'norm_type':'normalize', 'random_state':0}, None) self.model.train(xys) self.model.to_file(self.model_filename) self.assertTrue(os.path.exists(self.model_filename)) loaded_model = SklearnRandomForestTrainTestModel.from_file(self.model_filename, None) result = loaded_model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.17634739353518517, places=4)
def test_train_predict_randomforest(self): print "test random forest train and predict..." # random forest don't need proper data normalization xs = SklearnRandomForestTrainTestModel.get_xs_from_results( self.features, [0, 1, 2]) ys = SklearnRandomForestTrainTestModel.get_ys_from_results( self.features, [0, 1, 2]) xys = SklearnRandomForestTrainTestModel.get_xys_from_results( self.features, [0, 1, 2]) model = SklearnRandomForestTrainTestModel( { 'norm_type': 'normalize', 'random_state': 0 }, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643766, places=4) model = SklearnRandomForestTrainTestModel( { 'norm_type': 'clip_0to1', 'random_state': 0 }, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4) model = SklearnRandomForestTrainTestModel( { 'norm_type': 'custom_clip_0to1', 'custom_clip_0to1_map': { 'Moment_noref_feature_1st_score': [0.0, 100.0], }, 'random_state': 0 }, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4) model = SklearnRandomForestTrainTestModel( { 'norm_type': 'clip_minus1to1', 'random_state': 0 }, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4) model = SklearnRandomForestTrainTestModel( { 'norm_type': 'none', 'random_state': 0 }, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4)
def test_train_predict_randomforest(self): print "test random forest train and predict..." # random forest don't need proper data normalization xs = SklearnRandomForestTrainTestModel.get_xs_from_results(self.features, [0, 1, 2]) ys = SklearnRandomForestTrainTestModel.get_ys_from_results(self.features, [0, 1, 2]) xys = SklearnRandomForestTrainTestModel.get_xys_from_results(self.features, [0, 1, 2]) model = SklearnRandomForestTrainTestModel({'norm_type':'normalize', 'random_state': 0}, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643766, places=4) model = SklearnRandomForestTrainTestModel({'norm_type':'clip_0to1', 'random_state': 0}, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4) model = SklearnRandomForestTrainTestModel( {'norm_type': 'custom_clip_0to1', 'custom_clip_0to1_map': { 'Moment_noref_feature_1st_score': [0.0, 100.0], }, 'random_state': 0 }, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4) model = SklearnRandomForestTrainTestModel({'norm_type':'clip_minus1to1', 'random_state': 0}, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4) model = SklearnRandomForestTrainTestModel({'norm_type':'none', 'random_state': 0}, None) model.train(xys) result = model.evaluate(xs, ys) self.assertAlmostEquals(result['RMSE'], 0.051804171170643752, places=4)