python - 密度总和不等于 1
问题描述
我惊讶地发现概率密度之和不等于 1。是否有调整使其等于 1?
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import PercentFormatter
plt.style.use('seaborn-deep')
#input file is a flat file that contains portfolio holdings and characteristics
input_file = r'\\CP\file.xls'
df = pd.read_excel(input_file,header=6)
#number of lines in Fund is 123
df_Fund=df[(df['Port. Weight']>0)]
#number of lines in Bench is 214
df_Bench=df[(df['Bench. Weight']>0)]
#Delta distribution
x = df_Fund['Delta']
y = df_Bench['Delta']
plt.hist([x,y],bins=10, density=True, range=(0,100), label=['Fund','Bench'])
plt.legend(loc='upper right')
plt.gca().yaxis.set_major_formatter(PercentFormatter(1))
plt.title='Delta Breakdown'
plt.show()
图形:
解决方案
如果你想让它总和为一,那么你除以总和。
例如,如果您将一些组件和总和求和为一个数字X
x_0 + x_1 + x_2 + ... = X
所以如果你那么它,你将每个组件除以你得到的总数
(x_0/X) + (x_1/X) + (x_2/X) + ... = (x_0+x_1+x_2...)/X = X/X = 1
这就是您对任何分布进行归一化的方式(如果分布是连续的,则总和变为积分)
希望这会有所帮助
推荐阅读
- android - Android 编译错误 - 任务 ':app:kaptDebugKotlin' 执行失败
- ubuntu - Ubuntu 16 R 无法验证以下签名
- php - SOAP 数据从 Postman 返回,但不使用 Guzzle
- javascript - 如何在for循环中比较两个不同长度的对象?
- reactjs - 更新地理位置值时无法读取未定义的属性“setState”
- java - java中VS Code和包装命名的问题
- apache - AH01797:客户端被服务器配置拒绝(任何目的地)
- sql - SQL 匹配新列
- css - 砌体布局中项目的自动高度 - CSS Grid
- r - 有没有办法转置不同的列名