RuntimeWarning: invalid value とエラーが出ました。
from matplotlib import pyplot as plt from sklearn.datasets import load_iris import numpy as np import warnings data = load_iris() features = data['data'] feature_names = data['feature_names'] target = data['target'] target_names = data['target_names'] labels = target_names[target] plength =features[:,2] is_setosa = (labels=='setosa') features = features[~is_setosa] labels = labels[~is_setosa] virginica =(labels=='virginica') max_setosa =plength[is_setosa].max() min_non_setosa = plength[~is_setosa].min() print('Maximum of setosa: {0}.'.format(max_setosa)) print('Minimum of others:{0}.'.format(min_non_setosa)) best_acc = -1.0 best_fi =-1.0 best_t = -1.0 for fi in range(features.shape[1]): thresh = features[:,fi].copy() thresh.sort() for t in thresh: pred =(features[:,fi]>t) acc = (labels[pred]=='virginica').mean() if acc>best_acc: best_acc = acc best_fi = fi best_t = t #with warnings.catch_warnings(): #warnings.simplefilter("ignore", category=RuntimeWarning) #foo = np.nanmean(features, axis=1) def appy_model(example): if example[best_fi] > best_t:print('verginica') else: print('versicolor')
と書いたコードを実行すると
iris1.py:36: RuntimeWarning: Mean of empty slice. acc = (labels[pred]=='virginica').mean() /Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/numpy/core/_methods.py:80: RuntimeWarning: invalid value
とエラーが出ました。
#with warnings.catch_warnings(): #warnings.simplefilter("ignore", category=RuntimeWarning) #foo = np.nanmean(features, axis=1)
とコメントをつけてあるところをはずしても
同様のエラーが出ました。
RuntimeWarning が出ることが問題かと思って、
それを除去するwith文を書いてもエラーが出たままで
どのように直せばよいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。