使用ML.NET建立PCB加投率模型对单一蚀刻工序进行加投率预测, 此实例为最简单预测,要想实现全流程加投率预测挑战难度还是挺大的,可以查看另一种关于大数据在PCB行业应用---加投率计算基本原理:PCB 加投率计算实现基本原理--K最近邻算法(KNN)
建立数据结构,蚀刻工序影响报废的的关键参数,铜厚、线宽公差、最小线宽、最小线距(实际影响参数会更多)
/// <summary> /// PCB加投模型样本数据结构(此为演示结构并非真实加投模型结构)--蚀刻工序
/// 大数据量样本数越多预测结果数据越准确(选用的大数据数据分类算法) /// </summary> public class PCB_Scrap_Data { /// <summary> /// PCB铜厚 /// </summary> [Column("0")] public float CuThickness; /// <summary> /// 蚀刻线宽公差 /// </summary> [Column("1")] public float Tolerance; /// <summary> /// 最小线宽 /// </summary> [Column("2")] public float Width; /// <summary> /// 最小线距 /// </summary> [Column("3")] public float Space; /// <summary> /// 加投率数值 /// </summary> [Column("4")] [ColumnName("Label")] public float Label; } /// <summary> /// 此为预测PCB加投率结果类 /// </summary> public class ScrapPrediction { /// <summary> /// 预测加投率值 /// </summary> [ColumnName("PredictedLabel")] public float PredictedLabels; }
准备PCB蚀刻工序历史实际报废率数据与对应的影响蚀刻报废的参数因子(测试数据只用了12条,数据量是远远不够的,仅仅用于测试用,要实际要预测的话于少准备1年以前的生产数据,数据量的多少决定预测的准确率高低),此数据是参数对此蚀刻工序的影响报废权重值,并非真实的值, 为了简化:报废多少量就是因该要加投多少量。
如下数据:每行数据带表信息: 【表面铜厚】,【铜厚】,【最小线宽】,【最小线距】,【报废率】
69,3,14,14,0.03 44,35,10,10,0.03 64,11,13,13,0.03 39,0,31,31,0.03 4,2,47,47,0.02 2,1,48,48,0.02 2,3,48,48,0.02 12,8,40,40,0.02 11,75,7,7,0.01 14,61,13,13,0.01 18,75,4,4,0.01 11,45,22,22,0.01
//创建管道并加载数据 var pipeline = new LearningPipeline(); string dataPath = ".\\Data\\pcb.data"; pipeline.Add(new TextLoader<PCB_Scrap_Data>(dataPath, separator: ",")); //转换数据 pipeline.Add(new Dictionarizer("Label")); //将所有功能放入矢量 pipeline.Add(new ColumnConcatenator("Features", "CuThickness", "Tolerance", "Width", "Space")); //添加学习算法(SDCA算法--即:随机双坐标上升) pipeline.Add(new StochasticDualCoordinateAscentClassifier()); //将标签转Label换回原始文本 pipeline.Add(new PredictedLabelColumnOriginalValueConverter() { PredictedLabelColumn = "PredictedLabel" }); //根据数据集--训练模型 var model = pipeline.Train<PCB_Scrap_Data, ScrapPrediction>(); //训练模型好的PCB加投率模型保存起来 model.WriteAsync("PCB_Scrap_Model.zip");
// 用PCB加投率(参数因子)套入训练好模型来预测PCB加投率-----测试调用 var prediction = model.Predict(new PCB_Scrap_Data() { CuThickness = 18, Tolerance = 75, Width = 4, Space = 4, }); Console.WriteLine($"PCB加投率预测值为: {prediction.PredictedLabels}");
将PCB加投率模型封装WebAPI接口,供外部调用
// POST api/ScrapPrediction /// <summary> /// PCB加投率预测---通过训练好模型来预测PCB加投率 /// </summary> /// <param name="value"></param> /// <returns></returns> [HttpPost] public async Task<double> Post([FromBody] PCB_Scrap_Data value) { var model = await PredictionModel.ReadAsync<PCB_Scrap_Data, ScrapPrediction>("PCB_Scrap_Model.zip"); var prediction = model.Predict(value); return prediction.PredictedLabels; }
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:PCB 机器学习(ML.NET)初体验实现PCB加投率预测 - Python技术站