| 20 | |
| 21 | |
| 22 | public class TestRoundTrip { |
| 23 | |
| 24 | |
| 25 | @Test |
| 26 | public void testMRScore() throws Exception { |
| 27 | final File tmpDir = File.createTempFile("MRJunit_",".dir"); |
| 28 | tmpDir.delete(); |
| 29 | tmpDir.mkdirs(); |
| 30 | final File trainFile = new File(tmpDir,"uciCarTrain.tsv"); |
| 31 | final File modelFile = new File(tmpDir,"model.ser"); |
| 32 | final File resDir = new File(tmpDir,"mrRes"); |
| 33 | TestLRPath.copyResourceToFile("com/winvector/logistic/uciCarTrain.tsv",trainFile); |
| 34 | (new LogisticTrain()).run(new TrivialReader(trainFile.toURI(),'\t',null,false,null, false),new Formula("rating ~ buying + maintenance + doors + persons + lug_boot + safety"),null, |
| 35 | modelFile,null); |
| 36 | final MapReduceScore mrs = new MapReduceScore(); |
| 37 | mrs.setConf(new Configuration()); |
| 38 | final double accuracy = mrs.run(modelFile.getAbsolutePath(),trainFile.getAbsolutePath(),resDir.getAbsolutePath()); |
| 39 | // clean up |
| 40 | modelFile.delete(); |
| 41 | trainFile.delete(); |
| 42 | for(final File f: resDir.listFiles()) { |
| 43 | f.delete(); |
| 44 | } |
| 45 | resDir.delete(); |
| 46 | tmpDir.delete(); |
| 47 | // test |
| 48 | assertTrue(Math.abs(accuracy-0.9693)<1.0e-2); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void testMRTrain() throws Exception { |
| 53 | final File tmpDir = File.createTempFile("MRJunit_",".dir"); |
| 54 | tmpDir.delete(); |
| 55 | tmpDir.mkdirs(); |
| 56 | final File trainFile = new File(tmpDir,"exB.txt"); |
| 57 | final File modelFile = new File(tmpDir,"model.ser"); |
| 58 | final File resultFile = new File(tmpDir,"scored.tsv"); |
| 59 | TestLRPath.copyResourceToFile("com/winvector/logistic/exB.txt",trainFile); |
| 60 | final MapReduceLogisticTrain mrt = new MapReduceLogisticTrain(); |
| 61 | mrt.setConf(new Configuration()); |
| 62 | final double accuracy1 = mrt.run(trainFile.getAbsolutePath(),"y ~ x1 + x2", null, |
| 63 | modelFile.getAbsolutePath(), 5); |
| 64 | final ObjectInputStream ois = new ObjectInputStream(new FileInputStream(modelFile)); |
| 65 | final Model model = (Model)ois.readObject(); |
| 66 | ois.close(); |
| 67 | final double accuracy2 = LogisticScore.score(model,new TrivialReader(trainFile.toURI(),'\t',null,false,null, false),resultFile); |
| 68 | // clean up |
| 69 | modelFile.delete(); |
| 70 | trainFile.delete(); |
| 71 | resultFile.delete(); |
| 72 | tmpDir.delete(); |
| 73 | // test |
| 74 | assertTrue(Math.abs(accuracy1-1.0)<1.0e-3); |
| 75 | assertTrue(Math.abs(accuracy2-1.0)<1.0e-3); |
| 76 | } |
| 77 | } |
nothing calls this directly
no outgoing calls
no test coverage detected