java isfile exists_Java File.exists() versus File.isFile()

博客探讨了在Java中,使用File.exists()方法检查文件或目录存在性的实际用途。作者指出,虽然File.isFile()和File.isDirectory()可能更直接,但存在某些场景下,仅知道对象是否存在而不需要区分其类型是有帮助的。讨论涉及到Java文档中关于File类的描述,以及可能存在的“特殊文件”类型,这些特殊文件可能不明确属于文件或目录。博客中寻求一个具体例子来说明File.exists()的实用性。

I'm unable to think of a realistic use case for the method java.io.File.exists() or its equivalent in Java 7 java.nio.file.Files.exists(Path). It seems that isFile() or isDirectory() would be preferable in all cases (or canRead(), canWrite(), etc.).

For example, in How do I check if a file exists in Java?, the accepted answer seems silly, as the second answer points out.

Can anyone give an example where it's useful to know that a thing exists, without knowing whether the thing is a file or directory?

EDIT: I understand what File.exists() does. My question is, when would that functionality ever help someone? I'm searching for an example like, "Use File.exists() when _ _ _ _ _ _, because neither File.isFile() nor File.isDirectory() add any value in that case."

In retrospect, I think my confusion here was regarding two seemingly contradictory statements in the JavaDoc of the File class. The first sentence defines the class as,

An abstract representation of file and directory pathnames.

That sounds like a clear dichotomy; but further in, the doc counters it with,

Instances of this class may or may not denote an actual file-system object such as a file or a directory.

I think an example of a third file-system object would have helped immensely in the documentation; but that category seems to lack even a name, resulting in the awkward phrasing of the JavaDoc for the Files class: a collection of static methods,

that operate on files, directories, or other types of files.

In the accepted answer, @koral refers to these other types as "special files". That seems apt to me. They are so special, I didn't know they existed.

import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import os import matplotlib.font_manager as fm # 设置中文字体(使用字体文件路径方式) font_path = "C:/Windows/Fonts/simhei.ttf" # 根据你系统实际情况修改路径 font = fm.FontProperties(fname=font_path, size=12) # 设置全局字体和中文显示 plt.rcParams['font.sans-serif'] = [font.get_name()] plt.rcParams['axes.unicode_minus'] = False # 正常显示负号 sns.set(font_scale=1.2) sns.set_style("whitegrid") class FireEventFeatureExtractor: def __init__(self, excel_path, output_dir): """初始化特征提取器,指定输出目录""" self.excel_path = excel_path self.output_dir = output_dir self.raw_data = None self.candidate_events = None self.features = None if not os.path.exists(self.output_dir): os.makedirs(self.output_dir) print(f"已创建输出目录: {self.output_dir}") else: print(f"输出目录已存在: {self.output_dir}") def load_data(self, sheet_name="原始数据"): print(f"正在加载{sheet_name}数据...") self.raw_data = pd.read_excel(self.excel_path, sheet_name=sheet_name) print("正在进行数据清洗...") valid_mask = ( (self.raw_data['机号 (Machinery number)'] != -1) & (self.raw_data['地址 (Address)'].notna()) & (self.raw_data['火警次数 (Number of fire alarms)'] > 0) ) self.raw_data = self.raw_data[valid_mask].copy() print(f"清洗后数据量: {len(self.raw_data)} 条记录") return self def identify_faulty_devices(self): print("正在标记故障设备...") device_stats = self.raw_data.groupby('用户编码 (User coded)').agg({ '是否属于误报 (Whether a misstatement)': lambda x: (x == '是 (True)').all(), '火警次数 (Number of fire alarms)': 'sum' }).reset_index() device_stats['is_faulty'] = ( (device_stats['是否属于误报 (Whether a misstatement)'] == True) & (device_stats['火警次数 (Number of fire alarms)'] >= 5) ) self.raw_data = self.raw_data.merge( device_stats[['用户编码 (User coded)', 'is_faulty']], on='用户编码 (User coded)', how='left' ) self.raw_data['is_faulty'] = self.raw_data['is_faulty'].fillna(False) return self def build_candidate_events(self, min_devices=2): print(f"正在构建候选事件(至少{min_devices}个设备)...") group_keys = [ '项目名称 (Object name)', '回路 (Loop)', '机号 (Machinery number)' ] self.candidate_events = self.raw_data.groupby(group_keys).agg({ '用户编码 (User coded)': 'nunique', '火警次数 (Number of fire alarms)': 'sum', 'is_faulty': lambda x: (self.raw_data.loc[x.index, 'is_faulty'] * self.raw_data.loc[x.index, '火警次数 (Number of fire alarms)']).sum() }).reset_index() self.candidate_events.columns = group_keys + ['参与设备数(ndev)', '总报警次数(total)', '故障报警次数'] self.candidate_events = self.candidate_events[ self.candidate_events['参与设备数(ndev)'] >= min_devices ].reset_index(drop=True) self.candidate_events['故障占比(faulty_ratio)'] = ( self.candidate_events['故障报警次数'] / self.candidate_events['总报警次数(total)'] ).clip(0, 1) self.candidate_events.insert(0, '候选事件ID', range(1, len(self.candidate_events) + 1)) print(f"成功构建{len(self.candidate_events)}个候选事件") self.features = self.candidate_events.copy() return self def save_features(self): output_path = os.path.join(self.output_dir, "候选事件特征向量.xlsx") self.features.to_excel(output_path, index=False) print(f"特征向量已保存至: {output_path}") return self def visualize(self): print("正在生成可视化图表...") # 1. 参与设备数分布 plt.figure(figsize=(12, 5)) plt.subplot(1, 2, 1) sns.histplot(data=self.features, x='参与设备数(ndev)', bins=10, kde=True) plt.title('参与设备数分布') plt.xlabel('参与设备数') plt.ylabel('事件数量') plt.subplot(1, 2, 2) sns.boxplot(data=self.features, y='参与设备数(ndev)') plt.title('参与设备数箱线图') plt.ylabel('参与设备数') plt.tight_layout() plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) plt.close() # 2. 总报警次数分布 plt.figure(figsize=(10, 6)) log_total = np.log1p(self.features['总报警次数(total)']) sns.histplot(log_total, bins=15, kde=True) plt.title('总报警次数分布(对数变换)') plt.xlabel('log(总报警次数 + 1)') plt.ylabel('事件数量') plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) plt.close() # 3. 故障占比分布 plt.figure(figsize=(10, 6)) sns.histplot(data=self.features, x='故障占比(faulty_ratio)', bins=10, kde=True) plt.title('故障占比分布') plt.xlabel('故障占比') plt.ylabel('事件数量') plt.xticks(np.arange(0, 1.1, 0.1)) plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) plt.close() # 4. 特征相关性分析 plt.figure(figsize=(12, 10)) features_for_corr = self.features[['参与设备数(ndev)', '总报警次数(total)', '故障占比(faulty_ratio)']] features_for_corr.loc[:, '总报警次数(log)'] = np.log1p(features_for_corr['总报警次数(total)']) g = sns.pairplot(features_for_corr[['参与设备数(ndev)', '总报警次数(log)', '故障占比(faulty_ratio)']]) g.fig.suptitle('特征相关性散点图矩阵', y=1.02) plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) plt.close() print("可视化图表已保存至结果目录") return self def run_pipeline(self): print("====== 开始火灾事件特征提取流程 ======") self.load_data() \ .identify_faulty_devices() \ .build_candidate_events() \ .save_features() \ .visualize() print("====== 特征提取流程完成 ======") return self if __name__ == "__main__": excel_file_path = "预处理结果/火灾报警数据预处理结果_20250821_005317.xlsx" output_directory = r"C:\Users\cheny\Desktop\PythonProject2" extractor = FireEventFeatureExtractor(excel_file_path, output_directory) extractor.run_pipeline() print("\n前5条候选事件特征向量:") print(extractor.features[['候选事件ID', '项目名称 (Object name)', '参与设备数(ndev)', '总报警次数(total)', '故障占比(faulty_ratio)']].head()) 原代码如上 报错内容如下 E:\Anaconda\python.exe C:\Users\cheny\Desktop\PythonProject2\步骤二.py 输出目录已存在: C:\Users\cheny\Desktop\PythonProject2 ====== 开始火灾事件特征提取流程 ====== 正在加载原始数据数据... 正在进行数据清洗... 清洗后数据量: 27713 条记录 正在标记故障设备... 正在构建候选事件(至少2个设备)... 成功构建3840个候选事件 特征向量已保存至: C:\Users\cheny\Desktop\PythonProject2\候选事件特征向量.xlsx 正在生成可视化图表... C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 31665 (\N{CJK UNIFIED IDEOGRAPH-7BB1}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:123: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 31665 (\N{CJK UNIFIED IDEOGRAPH-7BB1}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:124: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 25253 (\N{CJK UNIFIED IDEOGRAPH-62A5}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 35686 (\N{CJK UNIFIED IDEOGRAPH-8B66}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 65288 (\N{FULLWIDTH LEFT PARENTHESIS}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 23545 (\N{CJK UNIFIED IDEOGRAPH-5BF9}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 21464 (\N{CJK UNIFIED IDEOGRAPH-53D8}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 25442 (\N{CJK UNIFIED IDEOGRAPH-6362}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:134: UserWarning: Glyph 65289 (\N{FULLWIDTH RIGHT PARENTHESIS}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 25925 (\N{CJK UNIFIED IDEOGRAPH-6545}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 38556 (\N{CJK UNIFIED IDEOGRAPH-969C}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 21344 (\N{CJK UNIFIED IDEOGRAPH-5360}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 27604 (\N{CJK UNIFIED IDEOGRAPH-6BD4}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:144: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:150: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy features_for_corr.loc[:, '总报警次数(log)'] = np.log1p(features_for_corr['总报警次数(total)']) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 25253 (\N{CJK UNIFIED IDEOGRAPH-62A5}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 35686 (\N{CJK UNIFIED IDEOGRAPH-8B66}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 25925 (\N{CJK UNIFIED IDEOGRAPH-6545}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 38556 (\N{CJK UNIFIED IDEOGRAPH-969C}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 21344 (\N{CJK UNIFIED IDEOGRAPH-5360}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 27604 (\N{CJK UNIFIED IDEOGRAPH-6BD4}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 25253 (\N{CJK UNIFIED IDEOGRAPH-62A5}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 35686 (\N{CJK UNIFIED IDEOGRAPH-8B66}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 25925 (\N{CJK UNIFIED IDEOGRAPH-6545}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 38556 (\N{CJK UNIFIED IDEOGRAPH-969C}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 21344 (\N{CJK UNIFIED IDEOGRAPH-5360}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 27604 (\N{CJK UNIFIED IDEOGRAPH-6BD4}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 29305 (\N{CJK UNIFIED IDEOGRAPH-7279}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 24449 (\N{CJK UNIFIED IDEOGRAPH-5F81}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 30456 (\N{CJK UNIFIED IDEOGRAPH-76F8}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 20851 (\N{CJK UNIFIED IDEOGRAPH-5173}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 25955 (\N{CJK UNIFIED IDEOGRAPH-6563}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 28857 (\N{CJK UNIFIED IDEOGRAPH-70B9}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 30697 (\N{CJK UNIFIED IDEOGRAPH-77E9}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:154: UserWarning: Glyph 38453 (\N{CJK UNIFIED IDEOGRAPH-9635}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) 可视化图表已保存至结果目录 ====== 特征提取流程完成 ====== 前5条候选事件特征向量: 候选事件ID 项目名称 (Object name) 参与设备数(ndev) 总报警次数(total) 故障占比(faulty_ratio) 0 1 AQSJAHYXQGC 3 15 0.666667 1 2 AQSJAHYXQGC 4 4 1.000000 2 3 AQSJAHYXQGC 3 3 0.666667 3 4 AQSJAHYXQGC 2 2 0.500000 4 5 HXYXQ1-10HLJDXCK 2 177 1.000000 进程已结束,退出代码为 0
08-22
import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns import os # 设置中文字体,确保图表中文正常显示 plt.rcParams["font.family"] = ["SimHei", "WenQuanYi Micro Hei", "Heiti TC"] sns.set(font_scale=1.2) sns.set_style("whitegrid") class FireEventFeatureExtractor: def __init__(self, excel_path, output_dir): """初始化特征提取器,指定输出目录""" self.excel_path = excel_path # 设置用户指定的输出目录 self.output_dir = output_dir self.raw_data = None self.candidate_events = None self.features = None # 创建输出目录(如果不存在) if not os.path.exists(self.output_dir): os.makedirs(self.output_dir) print(f"已创建输出目录: {self.output_dir}") else: print(f"输出目录已存在: {self.output_dir}") def load_data(self, sheet_name="原始数据"): """加载原始数据并进行预处理""" print(f"正在加载{sheet_name}数据...") self.raw_data = pd.read_excel(self.excel_path, sheet_name=sheet_name) # 数据清洗:移除无效记录 print("正在进行数据清洗...") valid_mask = ( (self.raw_data['机号 (Machinery number)'] != -1) & (self.raw_data['地址 (Address)'].notna()) & (self.raw_data['火警次数 (Number of fire alarms)'] > 0) ) self.raw_data = self.raw_data[valid_mask].copy() print(f"清洗后数据量: {len(self.raw_data)} 条记录") return self def identify_faulty_devices(self): """标记故障设备:误报且火警次数≥5的设备判定为故障设备""" print("正在标记故障设备...") # 按用户编码(设备唯一标识)分组,判断是否为故障设备 device_stats = self.raw_data.groupby('用户编码 (User coded)').agg({ '是否属于误报 (Whether a misstatement)': lambda x: (x == '是 (True)').all(), '火警次数 (Number of fire alarms)': 'sum' }).reset_index() # 故障设备判定条件 device_stats['is_faulty'] = ( (device_stats['是否属于误报 (Whether a misstatement)'] == True) & (device_stats['火警次数 (Number of fire alarms)'] >= 5) ) # 将故障设备信息合并回原始数据 self.raw_data = self.raw_data.merge( device_stats[['用户编码 (User coded)', 'is_faulty']], on='用户编码 (User coded)', how='left' ) # 填充缺失值(默认为非故障设备) self.raw_data['is_faulty'] = self.raw_data['is_faulty'].fillna(False) return self def build_candidate_events(self, min_devices=2): """构建候选事件:按建筑+回路+机号分组,筛选设备数≥min_devices的组""" print(f"正在构建候选事件(至少{min_devices}个设备)...") group_keys = [ '项目名称 (Object name)', '回路 (Loop)', '机号 (Machinery number)' ] # 分组计算关键指标 self.candidate_events = self.raw_data.groupby(group_keys).agg({ '用户编码 (User coded)': 'nunique', # 参与设备数 '火警次数 (Number of fire alarms)': 'sum', # 总报警次数 # 故障报警次数:故障设备的火警次数之和 'is_faulty': lambda x: (self.raw_data.loc[x.index, 'is_faulty'] * self.raw_data.loc[x.index, '火警次数 (Number of fire alarms)']).sum() }).reset_index() # 重命名列 self.candidate_events.columns = group_keys + [ '参与设备数(ndev)', '总报警次数(total)', '故障报警次数' ] # 筛选符合条件的候选事件 self.candidate_events = self.candidate_events[ self.candidate_events['参与设备数(ndev)'] >= min_devices ].reset_index(drop=True) # 计算故障占比 self.candidate_events['故障占比(faulty_ratio)'] = ( self.candidate_events['故障报警次数'] / self.candidate_events['总报警次数(total)'] ).clip(0, 1) # 确保比例在0-1之间 # 添加事件ID self.candidate_events.insert(0, '候选事件ID', range(1, len(self.candidate_events) + 1)) print(f"成功构建{len(self.candidate_events)}个候选事件") self.features = self.candidate_events.copy() return self def save_features(self): """保存特征向量结果到Excel文件""" output_path = os.path.join(self.output_dir, "候选事件特征向量.xlsx") self.features.to_excel(output_path, index=False) print(f"特征向量已保存至: {output_path}") return self def visualize(self): """可视化特征分布和相关性""" print("正在生成可视化图表...") # 1. 参与设备数分布 plt.figure(figsize=(12, 5)) plt.subplot(1, 2, 1) sns.histplot(data=self.features, x='参与设备数(ndev)', bins=10, kde=True) plt.title('参与设备数分布') plt.xlabel('参与设备数') plt.ylabel('事件数量') plt.subplot(1, 2, 2) sns.boxplot(data=self.features, y='参与设备数(ndev)') plt.title('参与设备数箱线图') plt.ylabel('参与设备数') plt.tight_layout() plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) plt.close() # 2. 总报警次数分布(对数变换) plt.figure(figsize=(10, 6)) # 对总报警次数进行对数变换,处理数据范围过大的问题 log_total = np.log1p(self.features['总报警次数(total)']) sns.histplot(log_total, bins=15, kde=True) plt.title('总报警次数分布(对数变换)') plt.xlabel('log(总报警次数 + 1)') plt.ylabel('事件数量') plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) plt.close() # 3. 故障占比分布 plt.figure(figsize=(10, 6)) sns.histplot(data=self.features, x='故障占比(faulty_ratio)', bins=10, kde=True) plt.title('故障占比分布') plt.xlabel('故障占比') plt.ylabel('事件数量') plt.xticks(np.arange(0, 1.1, 0.1)) plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) plt.close() # 4. 特征相关性分析 plt.figure(figsize=(12, 10)) features_for_corr = self.features[['参与设备数(ndev)', '总报警次数(total)', '故障占比(faulty_ratio)']] # 对总报警次数进行对数变换以改善可视化效果 features_for_corr['总报警次数(log)'] = np.log1p(features_for_corr['总报警次数(total)']) g = sns.pairplot(features_for_corr[['参与设备数(ndev)', '总报警次数(log)', '故障占比(faulty_ratio)']]) g.fig.suptitle('特征相关性散点图矩阵', y=1.02) plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) plt.close() print("可视化图表已保存至结果目录") return self def run_pipeline(self): """运行完整的特征提取流程""" print("====== 开始火灾事件特征提取流程 ======") self.load_data() \ .identify_faulty_devices() \ .build_candidate_events() \ .save_features() \ .visualize() print("====== 特征提取流程完成 ======") return self if __name__ == "__main__": # 替换为你的Excel文件实际路径 excel_file_path = "预处理结果/火灾报警数据预处理结果_20250821_005317.xlsx" # 设置保存路径为C:\Users\cheny\Desktop\PythonProject2 output_directory = r"C:\Users\cheny\Desktop\PythonProject2" # 运行特征提取流程 extractor = FireEventFeatureExtractor(excel_file_path, output_directory) extractor.run_pipeline() # 打印前5条特征结果 print("\n前5条候选事件特征向量:") print(extractor.features[['候选事件ID', '项目名称 (Object name)', '参与设备数(ndev)', '总报警次数(total)', '故障占比(faulty_ratio)']].head()) 代码如上 报错内容如下 C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 31665 (\N{CJK UNIFIED IDEOGRAPH-7BB1}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:139: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) Arial. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 31665 (\N{CJK UNIFIED IDEOGRAPH-7BB1}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:140: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "参与设备数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 25253 (\N{CJK UNIFIED IDEOGRAPH-62A5}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 35686 (\N{CJK UNIFIED IDEOGRAPH-8B66}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 65288 (\N{FULLWIDTH LEFT PARENTHESIS}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 23545 (\N{CJK UNIFIED IDEOGRAPH-5BF9}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 21464 (\N{CJK UNIFIED IDEOGRAPH-53D8}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 25442 (\N{CJK UNIFIED IDEOGRAPH-6362}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:151: UserWarning: Glyph 65289 (\N{FULLWIDTH RIGHT PARENTHESIS}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "总报警次数分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 25925 (\N{CJK UNIFIED IDEOGRAPH-6545}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 38556 (\N{CJK UNIFIED IDEOGRAPH-969C}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 21344 (\N{CJK UNIFIED IDEOGRAPH-5360}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 27604 (\N{CJK UNIFIED IDEOGRAPH-6BD4}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 20107 (\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 20214 (\N{CJK UNIFIED IDEOGRAPH-4EF6}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:161: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "故障占比分布.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:168: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy features_for_corr['总报警次数(log)'] = np.log1p(features_for_corr['总报警次数(total)']) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 25253 (\N{CJK UNIFIED IDEOGRAPH-62A5}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 35686 (\N{CJK UNIFIED IDEOGRAPH-8B66}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 25925 (\N{CJK UNIFIED IDEOGRAPH-6545}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 38556 (\N{CJK UNIFIED IDEOGRAPH-969C}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 21344 (\N{CJK UNIFIED IDEOGRAPH-5360}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) E:\Anaconda\Lib\site-packages\seaborn\axisgrid.py:123: UserWarning: Glyph 27604 (\N{CJK UNIFIED IDEOGRAPH-6BD4}) missing from font(s) Arial. self._figure.tight_layout(*args, **kwargs) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 21442 (\N{CJK UNIFIED IDEOGRAPH-53C2}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 19982 (\N{CJK UNIFIED IDEOGRAPH-4E0E}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 35774 (\N{CJK UNIFIED IDEOGRAPH-8BBE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 22791 (\N{CJK UNIFIED IDEOGRAPH-5907}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 24635 (\N{CJK UNIFIED IDEOGRAPH-603B}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 25253 (\N{CJK UNIFIED IDEOGRAPH-62A5}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 35686 (\N{CJK UNIFIED IDEOGRAPH-8B66}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 25925 (\N{CJK UNIFIED IDEOGRAPH-6545}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 38556 (\N{CJK UNIFIED IDEOGRAPH-969C}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 21344 (\N{CJK UNIFIED IDEOGRAPH-5360}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 27604 (\N{CJK UNIFIED IDEOGRAPH-6BD4}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 29305 (\N{CJK UNIFIED IDEOGRAPH-7279}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 24449 (\N{CJK UNIFIED IDEOGRAPH-5F81}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 30456 (\N{CJK UNIFIED IDEOGRAPH-76F8}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 20851 (\N{CJK UNIFIED IDEOGRAPH-5173}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 25955 (\N{CJK UNIFIED IDEOGRAPH-6563}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 28857 (\N{CJK UNIFIED IDEOGRAPH-70B9}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 30697 (\N{CJK UNIFIED IDEOGRAPH-77E9}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300) C:\Users\cheny\Desktop\PythonProject2\步骤二.py:172: UserWarning: Glyph 38453 (\N{CJK UNIFIED IDEOGRAPH-9635}) missing from font(s) Arial. plt.savefig(os.path.join(self.output_dir, "特征相关性分析.png"), dpi=300)
08-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值