Reputation: 11
I'm getting the warning below, upon running the code. However, the result will print the accuracy1, precision1, and recall1. How to avoid the warning?
warning:
UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no
predicted samples. 'precision', 'predicted', average, warn_for)
acc = []
pre = []
recall = []
for i in range(iters):
features_train, features_test, labels_train, labels_test = \
train_test_split(features, labels, test_size = 0.3, random_state = i)
grid_search.fit(features_train, labels_train)
predicts = grid_search.predict(features_test)
acc = acc + [accuracy_score(labels_test, predicts)]
pre = pre + [precision_score(labels_test, predicts)]
recall = recall + [recall_score(labels_test, predicts)]
print "accuracy1: {}".format(np.mean(acc))
print "precision1: {}".format(np.mean(pre))
print "recall1: {}".format(np.mean(recall))
best_params = grid_search.best_estimator_.get_params()
for param_name in params.keys():
print("%s = %r, " % (param_name, best_params[param_name]))
Upvotes: 0
Views: 556
Reputation: 11
import warnings
warnings.simplefilter('ignore')
The above module import fixed my issue.
Upvotes: 1
Reputation: 451
You can do it as:
import warnings
warnings.filterwarnings("ignore")
Upvotes: 0