运行这两行后如何获得Matthews相关系数?

时间:2015-06-23 08:41:22

标签: r machine-learning

我正在尝试以下示例:

target_cm_table_pred <- prediction(data_item_col, T_or_F_col)
target_cm_table_perf <- performance(target_cm_table_pred,"mat")

我不明白为什么我不能从输出中获得系数作为单个数字,就像“auc”一样,对于如何做出任何想法?我的意思是,为了获得系数的值,我必须写什么?

1 个答案:

答案 0 :(得分:1)

这是我写的一个小函数,用于获取Matthews相关性的值。这将混淆矩阵作为输入值。根据您的问题,您只需要根据类别的预测值创建一个混淆矩阵即可。您可以使用 插入符 包中的confusionMatrix函数创建此文件。

 //controller:
    public function uploadFile()
    {
        if (isset($_FILES['file']) && count($_FILES['file']['name']) > 0) {
            $acceptFormat = array(
                'jpeg' => 'image/jpeg',
                'jpg' => 'image/jpg',
                'png' => 'image/png'
            );

            $folder = "system";
            $destinationFilePath = "../" . $this->_config->upload_catalog_name . "" . $folder;
            $resultArray = uploadFiles($_FILES,$acceptFormat,$destinationFilePath);    
        }
    }

    //function :
     function uploadFiles($filesArray,$acceptFormat,$destinationFilePath){
      $result = array();
      foreach ($filesArray as $key => $file)
      {
        for($i=0; $i<count($file['name']); $i++){
          $temp = array();
          $ext = strtolower(pathinfo($file['name'][$i], PATHINFO_EXTENSION));
          if (!in_array($ext, array_keys($acceptFormat))) {
              $temp['newFileName'] = $file['name'][$i];
              $temp['error'] = 'Invalid file format.';
              // return error if invalid format with original file name and continue upload next file 
          }else if ($file['size'][$i] > 1000000000) 
          {
              $temp['newFileName'] = $file['name'][$i];
              $temp['error'] = 'Exceeded filesize limit.';
              // return error if Exceeded filesize limit with original file name and continue upload next file 
          }else {

              $tempData=date('Y-m-d H:i:s');
              $tempData=str_replace("-", "", $tempData);
              $tempData=str_replace(":", "", $tempData);
              $tempData=str_replace(" ", "", $tempData);
              $newFileName = $destinationFilePath.$tempData.$file['name'][$i]."." . $ext;
              $sourcePath = $file['tmp_name'][$i];
              if(move_uploaded_file($sourcePath,$newFileName))
              {
                $temp['newFileName']=$newFileName;
                $temp['error'] = '';
                //upload file successfully and return new file name; 
              }else{
                $temp['newFileName'] = $file['name'][$i];
                $temp['error'] = 'Failed to move uploaded file.';

              }
          }

          $result[] = $temp;
        }
      }
      return $result;
   }

logit1_trc:预测值 ,train $ y:响应变量

您可以在创建的函数中直接传递此混淆矩阵并获取系数。

conf_matrix <- confusionMatrix(data=logit1_trc, train$y))

我希望这对您有帮助