1. 数据集
2. 数据集分析
2.1. 使用方式
- 可用该数据集的分类研究
(1)刀具磨损检测
采用有监督的二分类方法对磨损刀具和未磨损刀具进行识别。
使用未磨损的工具进行了8次实验
而使用磨损的工具进行了10次实验
(2)检测夹紧不到位
该数据可用于检测工件何时没有以足够的压力被夹在虎钳中以通过视觉检查
这里我们研究第一种——刀具磨损检测。
- experiment.csv中的 CNC 测量可以通过两种方式使用:
(1) 将每个 CNC 测量作为独立观察,其中正在执行的操作在Machining_Process列中给出。活动加工操作标记为“第 1 层向上”、“第 1 层向下”、“第 2 层向上”、“第 2 层向下”、“第 3 层向上”和“第 3 层向下”。
(2)将18个实验(整个时间序列)中的每一个作为时间序列分类(time series classification)的观察值。
这里我们使用第二种方式。
2.2. 数据集组成
for dirname, _, filenames in os.walk('D:\\toolwear\\Tool_Wear_Detection1\\archive'):
for filename in filenames:
print(os.path.join(dirname, filename))
D:\toolwear\Tool_Wear_Detection1\archive\experiment_01.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_02.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_03.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_04.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_05.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_06.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_07.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_08.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_09.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_10.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_11.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_12.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_13.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_14.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_15.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_16.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_17.csv
D:\toolwear\Tool_Wear_Detection1\archive\experiment_18.csv
D:\toolwear\Tool_Wear_Detection1\archive\README.txt
D:\toolwear\Tool_Wear_Detection1\archive\README_CH.txt
D:\toolwear\Tool_Wear_Detection1\archive\test_artifact.jpg
D:\toolwear\Tool_Wear_Detection1\archive\train.csv
2.2.1. train.csv
train.csv是一个18行7列的表格。
experiment_result = pd.read_csv('D:\\toolwear\\Tool_Wear_Detection1\\archive\\train.csv')
print(f'train.csv : {experiment_result.shape}')
experiment_result
train.csv : (18, 7)
2.2.2. experiment_i.csv
experiment_x.csv有18个,分别代表了这18个实验中,每隔100ms各指标的情况。
显示experiment_x.csv的形状、指标集合、以及数据
experiment_tmp = pd.read_csv('D:\\toolwear\\Tool_Wear_Detection1\\archive\\experiment_01.csv')
print(f'experiment_XX.csv : {experiment_tmp.shape}')
print(experiment_tmp.columns)
experiment_tmp
experiment_XX.csv : (1055, 48)
Index(['X1_ActualPosition', 'X1_ActualVelocity', 'X1_ActualAcceleration',
'X1_CommandPosition', 'X1_CommandVelocity', 'X1_CommandAcceleration',
'X1_CurrentFeedback', 'X1_DCBusVoltage', 'X1_OutputCurrent',
'X1_OutputVoltage', 'X1_OutputPower', 'Y1_ActualPosition',
'Y1_ActualVelocity', 'Y1_ActualAcceleration', 'Y1_CommandPosition',
'Y1_CommandVelocity', 'Y1_CommandAcceleration', 'Y1_CurrentFeedback',
'Y1_DCBusVoltage', 'Y1_OutputCurrent', 'Y1_OutputVoltage',
'Y1_OutputPower', 'Z1_ActualPosition', 'Z1_ActualVelocity',
'Z1_ActualAcceleration', 'Z1_CommandPosition', 'Z1_CommandVelocity',
'Z1_CommandAcceleration', 'Z1_CurrentFeedback', 'Z1_DCBusVoltage',
'Z1_OutputCurrent', 'Z1_OutputVoltage', 'S1_ActualPosition',
'S1_ActualVelocity', 'S1_ActualAcceleration', 'S1_CommandPosition',
'S1_CommandVelocity', 'S1_CommandAcceleration', 'S1_CurrentFeedback',
'S1_DCBusVoltage', 'S1_OutputCurrent', 'S1_OutputVoltage',
'S1_OutputPower', 'S1_SystemInertia', 'M1_CURRENT_PROGRAM_NUMBER',
'M1_sequence_number', 'M1_CURRENT_FEEDRATE', 'Machining_Process'],
dtype='object')
每个文件都有来自CNC中的4个电机(X、Y、Z轴和主轴)的测量值。
2.2.3. 数据集分类
从算法的角度来说,数据可分为输入数据和输出数据
输入数据
- No:实验编号(No作为一个总数据,一个编号对应了许多experiment.csv里的分数据)
- 材质:蜡
- 进给速度:刀具沿工件的相对速度(mm/s)。
- 夹紧压力:用虎钳(棒子)夹住工件的压力
输出(预测)
- 工具情况:工具是否磨损
- 机加工完成:工件没有从气动虎钳中移动,机加工是否完成的指示
- 目视检查:工件是否通过目视检查的指示,仅用于加工完成的实验
2.3. 输入数据分析
2.3.1. No:实验编号
2.3.1.1. 加工过程
hv.Bars(df['Machining_Process'].value_counts()).opts(title="Machining Process Count", color="red", xlabel="Machining Processes", ylabel="Count")\
.opts(opts.Bars(width=500, height=300,tools=['hover'],xrotation=45,show_grid=True))
2.3.1.2. 速度
2.3.1.3. 电流
2.3.1.4. 电压
2.3.2. 材质、进给速度、夹紧压力
feedrate = hv.Distribution(df['feedrate']).opts(title="Distribution of feedrate", color="green", xlabel="Feedrate", ylabel="Density")
clamp = hv.Distribution(df['clamp_pressure']).opts(title="Distribution of clamp pressure", color="green", xlabel="Pressure", ylabel="Density")
material = hv.Bars(df['material'].value_counts()).opts(title="Material Count", color="green", xlabel="Material", ylabel="Count")
(feedrate + clamp + material).opts(opts.Bars(width=300, height=300,tools=['hover'],show_grid=True)).cols(2)
2.4. 输出数据分析
- 工具条件:未磨损工具的标签
- 机加工完成:工件没有从气动虎钳中移动,机加工是否完成的指示
- Passed_visual_inspection:工件是否通过目视检查的指示,仅用于加工完成的实验
tool_df = np.round(df['tool_condition'].value_counts(normalize=True) * 100)
finalized_df = np.round(df['machining_finalized'].value_counts(normalize=True) * 100)
vis_passed_df = np.round(df['passed_visual_inspection'].value_counts(normalize=True) * 100)
tool_wear = hv.Bars(tool_df).opts(title="Tool Wear Count", color="green", xlabel="Worn/Unworn", ylabel="Percentage", yformatter='%d%%')
finalized = hv.Bars(finalized_df).opts(title="Finalized Count", color="green", xlabel="Yes/No", ylabel="Percentage", yformatter='%d%%')
vis_inspection = hv.Bars(vis_passed_df).opts(title="Visual Inspection Passed Count", color="green", xlabel="Yes/No", ylabel="Percentage", yformatter='%d%%')
(tool_wear + finalized + vis_inspection).opts(opts.Bars(width=300, height=300,tools=['hover'],show_grid=True)).cols(2)
finalized_df_worn = np.round(df[df['tool_condition']=='worn']['machining_finalized'].value_counts(normalize=True) * 100)
finalized_df_unworn = np.round(df[df['tool_condition']=='unworn']['machining_finalized'].value_counts(normalize=True) * 100)
vis_passed_df_worn = np.round(df[df['tool_condition']=='worn']['passed_visual_inspection'].value_counts(normalize=True) * 100)
vis_passed_df_unworn = np.round(df[df['tool_condition']=='unworn']['passed_visual_inspection'].value_counts(normalize=True) * 100)
finalized_worn = hv.Bars(finalized_df_worn).opts(title="[WORN] Finalized Count", color="orange", xlabel="Yes/No", ylabel="Percentage", yformatter='%d%%')\
* hv.Text('yes', 15, f"{np.round(finalized_df_worn['yes']/sum(finalized_df_worn)*100)}%")\
* hv.Text('no', 15, f"{np.round(finalized_df_worn['no']/sum(finalized_df_worn)*100)}%")
finalized_unworn = hv.Bars(finalized_df_unworn).opts(title="[UNWORN] Finalized Count", color="orange", xlabel="Yes/No", ylabel="Percentage", yformatter='%d%%')\
* hv.Text('yes', 15, f"{np.round(finalized_df_unworn['yes']/sum(finalized_df_unworn)*100)}%")\
* hv.Text('no', 15, f"{np.round(finalized_df_unworn['no']/sum(finalized_df_unworn)*100)}%")
vis_inspection_worn = hv.Bars(vis_passed_df_worn).opts(title="[WORN] Visual Inspection Passed Count", color="green", xlabel="Yes/No", ylabel="Percentage", yformatter='%d%%')\
* hv.Text('yes', 45, f"{np.round(vis_passed_df_worn['yes']/sum(vis_passed_df_worn)*100)}%")\
* hv.Text('no', 45, f"{np.round(vis_passed_df_worn['no']/sum(vis_passed_df_worn)*100)}%")
vis_inspection_unworn = hv.Bars(vis_passed_df_unworn).opts(title="[UNWORN] Visual Inspection Passed Count", color="green", xlabel="Yes/No", ylabel="Percentage", yformatter='%d%%')\
* hv.Text('yes', 15, f"{np.round(vis_passed_df_unworn['yes']/sum(vis_passed_df_unworn)*100)}%")\
* hv.Text('no', 15, f"{np.round(vis_passed_df_unworn['no']/sum(vis_passed_df_unworn)*100)}%")
((finalized_worn + finalized_unworn) + (vis_inspection_worn + vis_inspection_unworn)).opts(opts.Bars(width=400, height=300,tools=['hover'],show_grid=True)).cols(2)
worn_fin_vis = pd.concat([finalized_df_worn, vis_passed_df_worn], axis=1,sort=True).rename(columns={'machining_finalized':'[WORN] Finalized', 'passed_visual_inspection':'[WORN] Visual Inspection Passed'})
worn_fin_vis = pd.melt(worn_fin_vis.reset_index(), ['index']).rename(columns={'index':'Yes/No', 'variable':'Outputs'})
hv.Bars(worn_fin_vis, ['Outputs','Yes/No'], 'value').opts(opts.Bars(title="Machining Finalized and Passed Visual Inspection by Worn Tool Count", width=700, height=400,tools=['hover'],\
show_grid=True, ylabel="Percentage", yformatter='%d%%'))
3. 未使用时间序列模型的CNC铣刀磨损预测
3.1. 基于XGBoost的CNC铣刀磨损预测
3.1.1. 数据预处理
将目标变量(工具磨损状态)添加到每个实验数据中。0:unworn,1:worn
frames = list()
results = pd.read_csv("archive\\train.csv")
for i in range(1,19):
exp = '0' + str(i) if i < 10 else str(i)
frame = pd.read_csv("archive\\experiment_{}.csv".format(exp))
# 从train.csv读取相对应的结果
row = results[results['No'] == i]
# 将experiment_i.csv加上名为'target'的列,表示