产品缺陷频数监控:加权卡方与休哈特控制图实战应用
(num_samples), chi_square_values, marker='o', label="加权卡方统计量") plt.axhline(y=ucl, color='r', linestyle='--', label=f"UCL ({ucl:.2f})") plt.axhline(y=lcl, color='g', linestyle='--', label=f"LCL ({lcl:.2f})") plt.fill_between(range(num_samples), lcl, ucl, color='gray', alpha=0.2) plt.title(title) plt.xlabel("样本编号") plt.ylabel("加权卡方统计量") plt.legend() plt.show() # 休哈特控制图计算 def shewhart_control_chart(data, alpha=0.05): """ 计算并绘制休哈特控制图 :param data: 观测数据 :param alpha: 显著性水平 :return: 控制限和均值 """ num_samples, num_categories = data.shape means = np.mean(data, axis=0) stds = np.std(data, axis=0, ddof=1) overall_mean = np.mean(means) overall_std = np.sqrt(np.sum(stds 2) / num_categories) lcl = overall_mean - chi2.ppf(1 - alpha / 2, num_categories - 1) * overall_std ucl = overall_mean + chi2.ppf(1 - alpha / 2, num_categories - 1) * overall_std return lcl, ucl, overall_mean # 绘制休哈特控制图 def plot_shewhart_control_chart(data, lcl, ucl, overall_mean, title="休哈特控制图"): """ 绘制休哈特控制图 :param data: 观测数据 :param lcl: 下控制限 :param ucl: 上控制限 :param overall_mean: 总体均值 :param title: 图表 """ sample_means = np.mean(data, axis=1) num_samples = len(sample_means) plt.figure(figsize=(12, 6)) plt.plot(range(num_samples), sample_means, marker='o', label="样本均值") plt.axhline(y=ucl, color='r', linestyle='--', label=f"UCL ({ucl:.2f})") plt.axhline(y=lcl, color='g', linestyle='--', label=f"LCL ({lcl:.2f})") plt.axhline(y=overall_mean, color='b', linestyle='-', label=f"总体均值 ({overall_mean:.2f})") plt.fill_between(range(num_samples), lcl, ucl, color='gray', alpha=0.2) plt.title(title) plt.xlabel("样本编号") plt.ylabel("样本均值") plt.legend() plt.show() # 示例运行 if __name__ == "__main__": # 参数设置 num_samples = 50 num_categories = 4 sample_size = 100 true_probs = [0.2, 0.3, 0.3, 0.2] weights = [1, 2, 3, 4] # 数据生成 simulated_data = generate_data(num_samples, num_categories, sample_size, true_probs) # 数据预处理 detected_data = detect_and_remove_outliers(simulated_data) imputed_data = impute_missing_values(detected_data) # 探索性数据分析 exploratory_data_analysis(imputed_data) # 加权卡方统计量计算 chi_square_values = weighted_chi_square(imputed_data, true_probs, weights) # 确定控制限 lcl, ucl = determine_control_limits(num_categories) # 绘制加权卡方控制图 plot_control_chart(chi_square_values, lcl, ucl) # 休哈特控制图计算与绘制 lcl_shewhart, ucl_shewhart, overall_mean = shewhart_control_chart(imputed_data) plot_shewhart_control_chart(imputed_data, lcl_shewhart, ucl_shewhart, overall_mean) ######[AI问答 | 925点数解答 | 2025-04-05 17:47:55]
- Express 应用创建与数据查询 API 实现:附代码示例与注意要点(字节豆包 | 387点数解答 | 2024-12-05 09:09:59)226
- 用 Python 中 pandas 库搞定产品月度数据表格:代码示例全解析( | 322点数解答 | 2024-01-12 17:18:58)338
- Python嵌套字典揭秘:某产品10 - 12月数据全解析(阿里通义 | 330点数解答 | 2024-01-12 17:20:10)337
- 用Python和Pandas将特定字典数据写入Excel并自定义表头( | 451点数解答 | 2024-01-12 17:22:58)334
- Python写入Excel报错:表头与数据长度不匹配及解决办法( | 401点数解答 | 2024-01-12 17:24:16)373
- 解决Python写入Excel时表头与数据列数不匹配的ValueError错误(阿里通义 | 288点数解答 | 2024-01-12 17:24:54)345
- Python写入Excel报错解决:确保表头与数据长度匹配 (讯飞星火 | 286点数解答 | 2024-01-12 17:26:30)328
- Python:解决字典数据写入 Excel 自定义表头 ValueError 问题(讯飞星火 | 252点数解答 | 2024-01-12 17:28:47)315
- 解决Python将字典数据写入Excel自定义表头时的ValueError问题 (讯飞星火 | 272点数解答 | 2024-01-12 17:29:05)337
- DESKTOP-IG9NT74 设备详细配置大揭秘! (字节豆包 | 38点数解答 | 2026-02-07 18:22:48)42