private void tsmnuGetGoodsData_Click(object sender, EventArgs e) { try { IEnumerable <Goods> goods = MultiDbApi.GetMultiData(); TextShow("获取数据成功!共" + goods.Count() + "条数据"); MLMultiApi mlMulti = new MLMultiApi(); TextShow("开始训练数据"); mlMulti.InitData(goods); TextShow("训练完成"); _mltype = (int)MLType.多类分类; } catch (Exception ex) { TextShow(ex.Message); } }
private void btnCs_Click(object sender, EventArgs e) { try { string text = textBox1.Text; switch (_mltype) { case (int)MLType.多类分类: MLMultiApi mlMulti = new MLMultiApi(); TextShow("加载模型"); mlMulti.InitFinalModel(); TextShow(text); Goods goods = new Goods(); goods.fname = text; ResGoods res = mlMulti.Predict(goods); string name = MultiDbApi.GetStypeName(res.stype); TextShow("预测结果:" + res.stype + " " + name); TextShow("概率:" + res.Percent + " 分数:" + res.Score[0] + " " + res.Score[1]); break; case (int)MLType.二元分类: MLbinaryApi mLbinary = new MLbinaryApi(); TextShow("加载二元分类模型"); mLbinary.InitFinalModel(); TextShow(text); BGoods binarygood = new BGoods(); binarygood.fname = text; ResBGoods resbinary = mLbinary.Predict(binarygood); TextShow($"预测: {(Convert.ToBoolean(resbinary.isyuce) ? "杂货类" : "非杂货类")}"); TextShow($"概率: {resbinary.Gailv}|分数:{resbinary.Score}"); break; } } catch (Exception ex) { TextShow(ex.Message); } }