在回归模型上使用预测

时间:2018-08-03 06:18:12

标签: r regression logistic-regression predict confusion-matrix

我试图弄清楚如何通过回归模型对数据集的另一部分进行测试,以使我开始感到困惑exportAsDoc() { const preHtml = '<html xmlns:o=\'urn:schemas-microsoft-com:office:office\' ' + '' + ' xmlns:w=\'urn:schemas-microsoft-com:office:word\' xmlns=\'http://www.w3.org/TR/REC-html40\'><head><meta charset=\'utf-8\'>' + '<title>Export HTML To Doc</title></head><body>'; const postHtml = '</body></html>'; let innerHtml = ''; // Specify file name const filename = this.respSheet.title + '.doc'; const respSheetKpis = this.respSheet.sheet_kpis; respSheetKpis.forEach(x => { const footer = '<p style="text-align: center">' + x.kpi.name + ' - ' + x.kpiValue + '</p>'; innerHtml += footer; x.sheet_kpi_dimensions.forEach(dimension => { if (dimension.dimension !== undefined) innerHtml += dimension.dimension.name; let table = '<table>\n' + ' <tr>\n' + ' <th>Istatistik adi</th>\n' + ' <th>Degeri</th> \n' + ' </tr>\n'; const data = dimension.data; if (data !== undefined) { for ( let i = 0 ; i < data.length ; i ++ ) { table += ' <tr>\n' + ' <th>' + data[ i ].title + '</th>\n' + ' <th>' + data[ i ].value + '</th> \n' + ' </tr>\n'; } table += '</table>'; innerHtml += table; } }) }); const html = preHtml + innerHtml + postHtml; const blob = new Blob(['\ufeff', html], { type: 'application/msword' }); // Specify link url const url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html); // Create download link element const downloadLink = document.createElement('a'); document.body.appendChild(downloadLink); if (navigator.msSaveOrOpenBlob ) { navigator.msSaveOrOpenBlob(blob, filename); } else { // Create a link to the file downloadLink.href = url; // Setting the file name downloadLink.download = filename; // triggering the function downloadLink.click(); } document.body.removeChild(downloadLink); ,但我却错失了自己的错。

matrix

当我这样预测时,我会收到此错误:

  

“ model.frame.default(条款,newdata,na.action = na.action,   xlev = object $ xlevels):因子状态具有新级别AP“

dupt:Report       studentreport

1 个答案:

答案 0 :(得分:0)

我重新输入了您发布的代码。由于在您的数据中找不到Enrolling列,因此在glm列中使用了GPATypeWeighted以便进行模型检查。未检测到预测错误。

library(leaps)
library(caret)
studentreport <- dget("https://drive.google.com/uc?authuser=0&id=1PHpkhPpEjIt-apCJpzvAKAlWZTPX7Evv&export=download")
studentreport <- data.frame(studentreport)
smp_size <- floor(0.75 * nrow(studentreport))

set.seed(123)
train_ind <- sample(seq_len(nrow(studentreport)), size = smp_size)

train <- studentreport[train_ind, ]
test <- studentreport[-train_ind, ]

fitreport <- glm(train)
Fitstart = glm(GPATypeWeighted ~ 1, data = train)

Report <- step(Fitstart, direction="forward", scope = formula(fitreport))

predict(Report, newdata = test, type ="response")

输出:

           3            4            5            7           13           14           16           23           27           36 
1.000000e+00 1.000000e+00 1.000000e+00 1.804986e-15 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 
          37           43           44           56           57           60           62           64           66           69 
1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 2.097525e-15 
          70           79           82           86           91           92           93           96           97          100 
1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 
         101          108          112          114          115          116          117          120          123          138 
1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 2.199615e-15 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 
         140          148          155          157          158          161          164          165          174          177 
1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 
         180          185          187          200          203          204          207          214          215          216 
1.000000e+00 1.000000e+00 1.000000e+00 1.756027e-15 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.686952e-15 1.000000e+00 
         222          239          248 
1.000000e+00 1.000000e+00 1.000000e+00