def test_learner_api_load_into_existing_instance(): """ Check that `Learner.load()` works as expected """ # create a LinearSVC instance and train it on some data learner1 = Learner('LinearSVC') (train_fs, test_fs) = make_classification_data(num_examples=200, num_features=5, use_feature_hashing=False, non_negative=True) learner1.train(train_fs, grid_search=False) # now use `load()` to replace the existing instance with a # different saved learner other_model_file = join( _my_dir, 'other', 'test_load_saved_model.{}.model'.format(sys.version_info[0])) learner1.load(other_model_file) # now load the saved model into another instance using the class method # `from_file()` learner2 = Learner.from_file(other_model_file) # check that the two instances are now basically the same eq_(learner1.model_type, learner2.model_type) eq_(learner1.model_params, learner2.model_params) eq_(learner1.model_kwargs, learner2.model_kwargs)
def test_learner_api_load_into_existing_instance(): """ Check that `Learner.load()` works as expected """ # create a LinearSVC instance and train it on some data learner1 = Learner('LinearSVC') (train_fs, test_fs) = make_classification_data(num_examples=200, num_features=5, use_feature_hashing=False, non_negative=True) learner1.train(train_fs, grid_search=False) # now use `load()` to replace the existing instance with a # different saved learner other_model_file = join(_my_dir, 'other', 'test_load_saved_model.{}.model'.format(sys.version_info[0])) learner1.load(other_model_file) # now load the saved model into another instance using the class method # `from_file()` learner2 = Learner.from_file(other_model_file) # check that the two instances are now basically the same eq_(learner1.model_type, learner2.model_type) eq_(learner1.model_params, learner2.model_params) eq_(learner1.model_kwargs, learner2.model_kwargs)