def test_multinomial_nb(self): model = hyperopt_estimator( classifier=components.multinomial_nb('classifier'), preprocessing=[], algo=rand.suggest, trial_timeout=5.0, max_evals=5, ) # Inputs for MultinomialNB must be non-negative model.fit(np.abs(self.X_train), self.Y_train) model.score(np.abs(self.X_test), self.Y_test)
def test_one_hot_encoder(self): # requires a classifier that can handle sparse data model = hyperopt_estimator( classifier=components.multinomial_nb('classifier'), preprocessing=[components.one_hot_encoder('preprocessing')], algo=rand.suggest, trial_timeout=5.0, max_evals=5, ) # Inputs for one_hot_encoder must be non-negative integers model.fit(np.abs(np.round(self.X_test).astype(np.int)), self.Y_test) model.score(np.abs(np.round(self.X_test).astype(np.int)), self.Y_test)
def test_tfidf(self): # requires a classifier that can handle sparse data model = hyperopt_estimator( classifier=components.multinomial_nb('classifier'), preprocessing=[components.tfidf('preprocessing')], algo=rand.suggest, trial_timeout=5.0, max_evals=5, ) X = np.array([ 'This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?', ]) Y = np.array([0, 1, 2, 0]) model.fit(X, Y) model.score(X, Y)