()
| 148 | |
| 149 | |
| 150 | @Test |
| 151 | public void testTrainScore() throws Exception { |
| 152 | final File tmpDir = File.createTempFile("FJunit_",".dir"); |
| 153 | tmpDir.delete(); |
| 154 | tmpDir.mkdirs(); |
| 155 | final File trainFile = new File(tmpDir,"uciCarTrain.tsv"); |
| 156 | final File modelFile = new File(tmpDir,"model.ser"); |
| 157 | final File resultFile = new File(tmpDir,"scored.tsv"); |
| 158 | TestLRPath.copyResourceToFile("com/winvector/logistic/uciCarTrain.tsv",trainFile); |
| 159 | final TrivialReader trainSource = new TrivialReader(trainFile.toURI(),'\t',null,false,null, false); |
| 160 | (new LogisticTrain()).run(trainSource,new Formula("rating ~ buying + maintenance + doors + persons + lug_boot + safety"),null, |
| 161 | modelFile,null); |
| 162 | final ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modelFile)); |
| 163 | final Model model = (Model)ois.readObject(); |
| 164 | ois.close(); |
| 165 | final double accuracy = LogisticScore.score(model,trainSource,resultFile); |
| 166 | // clean up |
| 167 | modelFile.delete(); |
| 168 | trainFile.delete(); |
| 169 | resultFile.delete(); |
| 170 | tmpDir.delete(); |
| 171 | // test |
| 172 | assertTrue(Math.abs(accuracy-0.9693)<1.0e-2); |
| 173 | } |
| 174 | |
| 175 | |
| 176 | /** |
nothing calls this directly
no test coverage detected