02-ECDF and Histogram

本文解释了经验累积分布函数(ECDF)与累积分布函数(CDF)之间的区别。ECDF是从实际数据集中构建的,而CDF是一种理论构造。通过硬币翻转的例子详细说明了两者的概率测度差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Difference between ECDF(Empirical Cumulative Distribution Function) and CDF:

The empirical CDF is built from an actual data set . The CDF is a theoretical construct.

Let X be a random variable.

  • The cumulative distribution function F(x)gives the P(Xx).
  • An empirical CDF function G(x)gives the P(Xx) in your actual sample.

The distinction is which probability measure is used. For the ECDF, you use the probability measure implicitly defined by the frequency counts in your sample.

Simple example (coin flip):

Let XX be a random variable denoting the result of a single coin flip where X=1denotes heads and X=0 denotes tails.

The CDF for a fair coin is given by:

F(x)=0121for x<0for 0x<1for 1x

If you flipped 2 heads and 1 tail, the empirical CDF would be:

G(x)=0231for x<0for 0x<1for 1x

The empirical CDF would reflect that 2/3 of your flips were heads.


Why ECDF is useful?

  • 1st step for data visualization. Usually along with Histogram; 

enter image description here

  • Help us to define the distribution of dataset;




%%% 步骤1:导入附件1的Excel数据(自适应读取) filePath = 'A.xlsx'; % 替换为实际文件路径 % 检查文件是否存在 if ~exist(filePath, 'file') error('文件不存在,请检查路径:%s', filePath); end % 尝试多种方式读取数据 try % 方法1:使用readtable读取表格数据(优先) T = readtable(filePath); % 假设第一列包含检测次数数据 inspection_counts = table2array(T(:, 1)); catch e % 方法2:使用xlsread读取原始数据 [~, ~, rawData] = xlsread(filePath); inspection_counts = str2double(rawData); end % 检查数据是否有效 if isempty(inspection_counts) || all(isnan(inspection_counts)) error('未读取到有效数据,请检查Excel文件格式和内容'); end %%% 步骤2:数据清洗与逻辑校验 % 子步骤2.1:剔除无效检测次数(检测次数<2或非数值) valid_mask = ~isnan(inspection_counts) & (inspection_counts >= 2); valid_inspections = inspection_counts(valid_mask); fprintf('原始数据量:%d条\n', length(inspection_counts)); fprintf('剔除无效数据:%d条(检测次数<2或非数值)\n', sum(~valid_mask)); % 子步骤2.2:处理统计异常值(可选,根据需要启用) % [valid_inspections, outliers] = remove_outliers(valid_inspections); % if ~isempty(outliers) % fprintf('处理统计异常值:%d条\n', length(outliers)); % end %%% 步骤3:转换为寿命天数(检测次数×15天) life_days = valid_inspections * 15; %%% 步骤4:输出预处理结果 fprintf('预处理后有效数据量:%d条\n', length(life_days)); disp('前5条寿命天数数据:'); disp(life_days(1:min(5, length(life_days)))); %%% 步骤5:可视化寿命分布 figure('Position', [100, 100, 800, 400]); % 直方图 subplot(1,2,1); histogram(life_days, 'Normalization', 'pdf', 'BinWidth', 15); title('寿命天数分布直方图'); xlabel('寿命天数'); ylabel('概率密度'); grid on; % 经验累积分布函数(ECDF) subplot(1,2,2); ecdf(life_days); title('寿命天数累积分布函数'); xlabel('寿命天数'); ylabel('累积概率'); grid on; %%% 辅助函数:检测并处理异常值(可选) function [clean_data, outliers] = remove_outliers(data) % 使用箱线图法检测异常值 q1 = prctile(data, 25); q3 = prctile(data, 75); iqr = q3 - q1; lower_fence = q1 - 1.5 * iqr; upper_fence = q3 + 1.5 * iqr; % 标记异常值 is_outlier = (data < lower_fence) | (data > upper_fence); outliers = data(is_outlier); % 处理异常值(用中位数替换) clean_data = data; clean_data(is_outlier) = median(data); end
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值