python报错ValueError: supplied range of [-inf, 5.572154032177765] is not finite

数据分布不均匀时,采用log变换处理数据,

plt.hist(np.log(df_train['cycle'].values), orientation = 'vertical',histtype = 'bar', color ='skyblue') 
plt.show()
"""
ValueError: supplied range of [-inf, 5.572154032177765] is not finite
"""

这是因为你的数据中有0,经过log变化就是-inf(负无穷)

data=np.log(df_train['cycle'])
data

python报错ValueError: supplied range of [-inf, 5.572154032177765] is not finite_第1张图片画图的时候就会报错,你可以让values+1

plt.hist(np.log(df_train['cycle'].values+1), orientation = 'vertical',histtype = 'bar', color ='skyblue') 
plt.show()

python报错ValueError: supplied range of [-inf, 5.572154032177765] is not finite_第2张图片

你可能感兴趣的:(笔记,python,开发语言)