#!/usr/bin/env python# -*- coding:utf-8 -*- import numpy as npimport matplotlib.pyplot as pltimport jsonfrom decimal import Decimal # 保留浮点类型jstring=‘{"name":"pro","price":12.05}‘str=json.loads(jstring,parse_float=Decimal)print(str) # 柱状图def is_outlier(points,threshold=3.5): if len(points.shape)==1: points=points[:,None] median=np.median(points,axis=0) diff=np.sum((points-median)**2,axis=-1) diff=np.sqrt(diff) med_abs_deviation=np.median(diff) modified_z_score=0.6745*diff/med_abs_deviation return modified_z_score > threshold x=np.random.random(10)buckets=50np.r_[x,-49,95,100,-100]fitered=x[~is_outlier(x)] plt.figure() plt.subplot(211)plt.hist(x,buckets)plt.xlabel(‘Raw‘) plt.subplot(212)plt.hist(fitered,buckets)plt.xlabel(‘Cleaned‘) plt.show()
原文地址:https://www.cnblogs.com/NiceTime/p/10125207.html
时间: 2024-10-02 20:19:27