Просмотр исходного кода

feat: 创建,训练,查看模型

icenaked 3 лет назад
Родитель
Сommit
5cce2f2790
4 измененных файлов с 103 добавлено и 114 удалено
  1. 8 7
      src/api/model.js
  2. 10 15
      src/views/file/FileDetail.vue
  3. 72 74
      src/views/ml/ConfigDetail.vue
  4. 13 18
      src/views/ml/ModelList.vue

+ 8 - 7
src/api/model.js

@@ -8,15 +8,15 @@ import {MOCK} from "./_prefix";
  * @returns
  */
 export const addModel = async payload => {
-    const {fileInfoId, configId, modelName, modelTypeId, argument} = payload;
-    const res = await axios.post(`${MODEL_MODULE}/add`, {
-        fileInfoId,
+    const {configId, userId, modelName, machineLearningAlgorithm, trainParams} = payload;
+    const res = await axios.post(`${MOCK}/ml/models`, {
         configId,
+        userId,
         modelName,
-        modelTypeId,
-        arguments:argument
+        machineLearningAlgorithm,
+        trainParams
     })
-    return res//response
+    return res
 }
 /**
  * 新建DL模型 POST /model/add/dl
@@ -111,7 +111,8 @@ export const getModelByConfigId = async payload => {
      */
     export const train = async payload=>{
         const { modelId } = payload;
-        const res=await axios.get(`${MODEL_MODULE}/train`,{params:{modelId:modelId}});
+        // const res=await axios.get(`${MODEL_MODULE}/train`,{params:{modelId:modelId}});
+        const res=await axios.get(`${MOCK}/ml/models/:modelId/train`);
         return res;
     }
     /**

+ 10 - 15
src/views/file/FileDetail.vue

@@ -126,21 +126,16 @@
 <!--          </el-select>-->
 <!--        </el-form-item>-->
         <el-form-item label="模型类别" required>
-          <el-select v-model="form.type" placeholder="学习类型" class="handle-select mr10" >
+          <el-select v-model="form.type" placeholder="学习类型" class="handle-select mr10">
             <el-option key="1" label="监督学习" value="SUPERVISED_LEARNING"></el-option>
             <el-option key="2" label="非监督学习" value="UNSUPERVISED_LEARNING"></el-option>
           </el-select>
-        </el-form-item>
-        <el-form-item label="标签字段" required>
-          <el-select v-model="form.needLabel" placeholder="是否需要" class="handle-select mr10" @change="selectLabelChange">
-            <el-option key="1" label="是" value='1'></el-option>
-            <el-option key="2" label="否" value='2'></el-option>
-          </el-select>
-          <el-alert type="info" description="您选择的最后一个字段为标签字段" v-if="labelTip===1"
+          <el-alert type="info" description="您选择的最后一个字段为标签字段" v-if="form.type === 'SUPERVISED_LEARNING'"
                     show-icon style="height: 40px; margin-top: 10px"></el-alert>
-          <el-alert type="info" description="没有目标字段,适用于k-means模型" v-if="labelTip===2"
+          <el-alert type="info" description="没有目标字段,适用于k-means模型" v-if="form.type === 'UNSUPERVISED_LEARNING'"
                     show-icon style="height: 40px; margin-top: 10px"></el-alert>
         </el-form-item>
+
         <el-form-item label="选中字段" >
           <el-table :data="selectData" border class="table" header-cell-class-name="table-header" >
             <el-table-column label="字段名">
@@ -372,10 +367,10 @@ export default {
       if(selectValue==="8")featureTip.value=2;
       else featureTip.value=1;
     }
-    const selectLabelChange=(selectValue)=>{
-      if(selectValue==="1") labelTip.value=1;
-      else labelTip.value=2;
-    }
+    // const selectLabelChange=(selectValue)=>{
+    //   if(selectValue === "SUPERVISED_LEARNING") labelTip.value=1;
+    //   else labelTip.value=2;
+    // }
     const configCreate = ref(false);
     const createConfig =() => {
       if (selectData.value.length<=1){
@@ -395,7 +390,7 @@ export default {
         features:[],
         label: ''
       }
-      if (form.needLabel === '2'){
+      if (form.type === 'UNSUPERVISED_LEARNING'){
         for(let i=0;i<selectData.value.length;i++){
           payload.features.push(selectData.value[i].fieldName);
         }
@@ -436,7 +431,7 @@ export default {
       labelTip,
       methodMsg,
       selectModelTypeChange,
-      selectLabelChange,
+      //selectLabelChange,
       handleSelectChange,
       handleSearch,
       handlePageChange,

+ 72 - 74
src/views/ml/ConfigDetail.vue

@@ -65,32 +65,41 @@
 
           <el-dialog title="新建模型" v-model="modelVisiable" width="30%">
             <el-form label-width="120px">
-              <el-form-item label="文件Id" required>
-                <el-input v-model="form.fileInfoId" ></el-input>
-              </el-form-item>
               <el-form-item label="模型名称" required>
                 <el-input v-model="form.modelName"></el-input>
               </el-form-item>
-              <el-form-item label="MaxIter" v-model="showMaxIter" v-if="showMaxIter===true">
-                <el-input v-model="form.MaxIter"></el-input>
+              <el-form-item label="算法名称" required>
+                <el-select v-model="form.machineLearningAlgorithm" placeholder="请选择一个算法" class="handle-select mr10">
+                  <el-option key="1" label="逻辑回归" value="LOGISTIC_REGRESSION_CLASSIFICATION"></el-option>
+                  <el-option key="2" label="决策树" value="DECISION_TREE_CLASSIFICATION"></el-option>
+                  <el-option key="3" label="梯度提升树分类" value="GRADIENT_BOOSTED_TREE_CLASSIFICATION"></el-option>
+                  <el-option key="4" label="多层感知器分类" value="MULTI_LAYER_PERCEPTRON_CLASSIFICATION"></el-option>
+                  <el-option key="5" label="朴素贝叶斯分类" value="NAIVE_BAYES_CLASSIFICATION"></el-option>
+                  <el-option key="6" label="随机森林分类" value="RANDOM_FOREST_CLASSIFICATION"></el-option>
+                  <el-option key="7" label="随机森林回归" value="RANDOM_FOREST_REGRESSION"></el-option>
+                  <el-option key="8" label="K均值聚类" value="K_MEANS_CLUSTERING"></el-option>
+                </el-select>
+              </el-form-item>
+              <el-form-item label="MaxIter" v-model="showMaxIter" v-if="judgeAlgorithmType() === 1">
+                <el-input v-model="form.trainParams.MaxIter"></el-input>
               </el-form-item>
-              <el-form-item label="RegParam" v-model="showRegParam" v-if="showRegParam===true">
-                <el-input v-model="form.RegParam"></el-input>
+              <el-form-item label="RegParam" v-model="showRegParam" v-if="judgeAlgorithmType() === 1">
+                <el-input v-model="form.trainParams.RegParam"></el-input>
               </el-form-item>
-              <el-form-item label="ElasticNetParam" v-model="showElasticNetParam" v-if="showElasticNetParam===true">
-                <el-input v-model="form.ElasticNetParam"></el-input>
+              <el-form-item label="ElasticNetParam" v-model="showElasticNetParam" v-if="judgeAlgorithmType() === 1">
+                <el-input v-model="form.trainParams.ElasticNetParam"></el-input>
               </el-form-item>
-              <el-form-item label="Category" v-model="showCategory" v-if="showCategory===true">
-                <el-input v-model="form.Category"></el-input>
+              <el-form-item label="Category" v-model="showCategory" v-if="judgeAlgorithmType() === 3">
+                <el-input v-model="form.trainParams.Category"></el-input>
               </el-form-item>
-              <el-form-item label="DataSetOccupy" v-model="showTrainingDataSetOccupy" v-if="showTrainingDataSetOccupy===true">
-                <el-input v-model="form.TrainingDataSetOccupy"></el-input>
+              <el-form-item label="DataSetOccupy" v-model="showTrainingDataSetOccupy" v-if="judgeAlgorithmType() === 3">
+                <el-input v-model="form.trainParams.TrainingDataSetOccupy"></el-input>
               </el-form-item>
-              <el-form-item label="NumOfCluster" v-model="showNumOfCluster" v-if="showNumOfCluster===true">
-                <el-input v-model="form.NumOfCluster"></el-input>
+              <el-form-item label="NumOfCluster" v-model="showNumOfCluster" v-if="judgeAlgorithmType() === 2">
+                <el-input v-model="form.trainParams.NumOfCluster"></el-input>
               </el-form-item>
-              <el-form-item label="Seed" v-model="showSeed" v-if="showSeed===true">
-                <el-input v-model="form.Seed"></el-input>
+              <el-form-item label="Seed" v-model="showSeed" v-if="judgeAlgorithmType() === 2">
+                <el-input v-model="form.trainParams.Seed"></el-input>
               </el-form-item>
 
             </el-form>
@@ -165,18 +174,24 @@ export default {
     const showNumOfCluster=ref(false);
     const showSeed=ref(false);
 
+    // let form = reactive({
+    //   modelTypeId:"",
+    //   configId:route.query.configId,
+    //   fileInfoId:"",
+    //   modelName:"",
+    //   MaxIter:"",
+    //   RegParam:"",
+    //   ElasticNetParam:"",
+    //   Category:"",
+    //   TrainingDataSetOccupy:"",
+    //   NumOfCluster:"",
+    //   Seed:"",
+    // });
     let form = reactive({
-      modelTypeId:"",
-      configId:route.query.configId,
-      fileInfoId:"",
-      modelName:"",
-      MaxIter:"",
-      RegParam:"",
-      ElasticNetParam:"",
-      Category:"",
-      TrainingDataSetOccupy:"",
-      NumOfCluster:"",
-      Seed:"",
+      configId: route.query.configId,
+      modelName: "",
+      machineLearningAlgorithm: "",
+      trainParams: {},
     });
     // 获取表格数据
 
@@ -200,15 +215,6 @@ export default {
           // }
           // console.log("form",form);
           tableData.value = res.result.features;
-          // for (var i = 0; i < tableData.value.length; i++) {
-          //   if (tableData.value[i].conOrDis === 1) {
-          //     tableData.value[i].conOrDis = "连续值"
-          //   } else {
-          //     tableData.value[i].conOrDis = "离散值"
-          //   }
-          // }
-          fileId.value=tableData.value[0].fileInfoId;
-          form.fileInfoId=(String)(fileId.value)
         });
         getModelByConfigId({configId:route.query.configId}).then(res =>{
           modelData.value=res.result.modelVOList;
@@ -218,9 +224,11 @@ export default {
     };
     getData();
 
-
-
-
+    const judgeAlgorithmType =()=>{
+      if (form.machineLearningAlgorithm === 'LOGISTIC_REGRESSION_CLASSIFICATION') return 1;
+      else if (form.machineLearningAlgorithm === 'K_MEANS_CLUSTERING') return 2;
+      else return 3;
+    }
 
     // 查询操作
     const handleSearch = () => {
@@ -235,58 +243,47 @@ export default {
 
     // 删除操作
 
-
     // 表格编辑时弹窗和保存
     const editVisible = ref(true);
 
-
-
     const saveModel = () => {
       modelVisiable.value = false
-      form.fileInfoId=tableData.value[0].fileInfoId
-      console.log(form.fileInfoId)
-      //todo:   调用Model相关接口
-      console.log("savemodel",form);
-      const payload={modelTypeId:form.modelTypeId,
-                     configId:form.configId,
-                      fileInfoId:form.fileInfoId,
-                      modelName:form.modelName,
-                      argument:[]
+      const payload={
+        configId:form.configId,
+        userId: 1,
+        modelName:form.modelName,
+        machineLearningAlgorithm: form.machineLearningAlgorithm,
+        trainParams:{}
       }
       const arg1={
-        MaxIter:form.MaxIter,
-        RegParam:form.RegParam,
-        ElasticNetParam:form.ElasticNetParam
+        MaxIter:form.trainParams.MaxIter,
+        RegParam:form.trainParams.RegParam,
+        ElasticNetParam:form.trainParams.ElasticNetParam
       }
       const arg3={
-        Category:form.Category,
-        TrainingDataSetOccupy:form.TrainingDataSetOccupy
+        Category:form.trainParams.Category,
+        TrainingDataSetOccupy:form.trainParams.TrainingDataSetOccupy
       }
       const arg4={
-        NumOfCluster:form.NumOfCluster,
-        Seed:form.Seed
+        NumOfCluster:form.trainParams.NumOfCluster,
+        Seed:form.trainParams.Seed
       }
-      if (config.value.modelTypeId==='1'){
-        payload.argument=arg1;
-      }else if (config.value.modelTypeId==='5'){
-        payload.argument=arg4;
+      if (judgeAlgorithmType() === 1){
+        payload.trainParams=arg1;
+      }else if (judgeAlgorithmType() === 5){
+        payload.trainParams=arg4;
       }else{
-        payload.argument=arg3;
+        payload.trainParams=arg3;
       }
-      console.log("here",payload);
       addModel(payload).then(res=>{
-
-        if(res.status===200) {
+        console.log(res)
+        if(res.msg === '成功') {
           ElMessage.success(`已成功生成模型`);
-
         }
         else ElMessage.error(`生成模型失败`);
       })
 
 
-
-
-
     };
     let idx = -1;
     const handleEdit = () => {
@@ -297,10 +294,9 @@ export default {
 
     //生成模型弹窗
     const modelVisiable=ref(false);
-    const createModel=()=>{
 
+    const createModel=()=>{
         modelVisiable.value=true;
-      console.log("here",modelVisiable);
     }
     const handleSelectChange=val=>{
       selectData.value=val;
@@ -325,6 +321,8 @@ export default {
       showNumOfCluster,
       showSeed,
       showTrainingDataSetOccupy,
+
+      judgeAlgorithmType,
       selectData,
       handleSelectChange,
       handleSearch,
@@ -349,7 +347,7 @@ export default {
 }
 
 .handle-select {
-  width: 120px;
+  width: 150px;
 }
 
 .handle-input {

+ 13 - 18
src/views/ml/ModelList.vue

@@ -96,10 +96,7 @@
           <span class="dialog-footer">
             <el-button @click="useModelVisible = false">取消</el-button>
             <router-link :to="{path:'/charts',query:{fileId:useform.file,modelId:usemodelId}}">
-            <el-button type="primary" 
-            @click="useModel()"
-              >使用模型</el-button
-            >
+            <el-button type="primary" @click="useModel()" style="margin-left: 10px"> 使用模型 </el-button>
             </router-link>
           </span>
         </template>
@@ -152,10 +149,9 @@ export default {
     // 获取表格数据
 
     const getpage=()=> {
-      // console.log("getpage");
       const uid=1;
       GetAllFile(uid).then(res=>{
-        fileList.value=res.data;
+        fileList.value=res.result.fileInfoVOList;
       })
       getAllModel({
          userId: uid
@@ -203,14 +199,15 @@ export default {
             }).then(res=>{
               instance.confirmButtonLoading = false
               console.log("train_res: ",res);
-              if (res.status === 200 & res.data === true)
+              if (res.msg === '成功')
               {
-                // ElMessageBox({
-                //   title: '模型训练',
-                //   message: `模型训练成功`,
-                //   confirmButtonText: '确定',
-                // })
-                location.reload();
+                ElMessageBox({
+                  title: '模型训练',
+                  message: `模型训练成功`,
+                  confirmButtonText: '确定',
+                })
+                //location.reload();
+                getpage();
                 done()
               }
               else
@@ -232,7 +229,7 @@ export default {
     const resVisible = ref(false);
     const handleTrainRes = (index) => {
       const reg=new RegExp("\"","g");
-     modelRes.value= ((JSON.stringify(tableData.value[index].resOfModel)+"")
+     modelRes.value= ((JSON.stringify(tableData.value[index].trainResultMap)+"")
             .replace(reg,"")
             .replace("{","")
             .replace("}","")
@@ -243,16 +240,14 @@ export default {
         str=str+modelRes.value[i]
         str=str+"\n"
       }
-       ElMessageBox.confirm(tableData.value[index].resOfModel)
-
+       ElMessageBox.confirm(str)
       }
 
 
 
-const usemodelId=ref();
+    const usemodelId=ref();
     //todo模型使用
      const editUseModel = (index) => {
-      console.log(useModelVisible)
       useModelVisible.value=true;
       usemodelId.value=tableData.value[index].modelId
     };