MCPcopy Create free account
hub / github.com/WinVector/Logistic / main

Method main

src/com/winvector/logistic/LogisticTrain.java:232–302  ·  view source on GitHub ↗

> logisticModel <- glm(rating!='unacc' ~ buying + maintinance + doors + persons + lug_boot +safety,family=binomial(link = "logit"),data=CarData) > table <- table(CarData$rating!='unacc',predict(logisticModel,type='response')>=0.5) > (table[1,1]+table[2,2])/(table[1,1]+table[1,2] + table[2,1] +table[

(final String[] args)

Source from the content-addressed store, hash-verified

230 * @throws InstantiationException
231 */
232 public static void main(final String[] args) throws IOException, ParseException, URISyntaxException, org.apache.commons.cli.ParseException, SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
233 final Log log = LogFactory.getLog(LogisticTrain.class);
234 log.info("start LogisticTrain\t" + new Date());
235 final CommandLine cl = parseCommandLine(args);
236 final String formulaStr = cl.getOptionValue(FORMULAKEY); // example: rating ~ buying + maintinance + doors + persons + lug_boot + safety
237 final String weightKey = cl.getOptionValue(WEIGHTKEY);
238 final Formula f = new Formula(formulaStr);
239 final boolean memorize = cl.hasOption(MEMKEY);
240 DBHandle handle = null;
241 Statement stmt = null;
242 final Iterable<BurstMap> trainSource;
243 final File resultFileSer = valueAsFile(cl,RESULTSERKEY);
244 final File resultFileTSV = valueAsFile(cl,RESULTTSVKEY);
245 {
246 final Iterable<BurstMap> origSource;
247 if(cl.getOptionValue(TRAINURIKEY)!=null) {
248 char sep = '\t';
249 if(cl.getOptionValue(TRAINSEP)!=null) {
250 sep = cl.getOptionValue(TRAINSEP).charAt(0);
251 }
252 final URI trainURI = new URI(cl.getOptionValue(TRAINURIKEY));
253 log.info(" source URI: " + trainURI.toString());
254 origSource = new TrivialReader(trainURI,sep,null,false,null,memorize);
255 } else {
256 final URI dbProps = new URI(cl.getOptionValue(TRAINHDLKEY));
257 final String dbTable = cl.getOptionValue(TRAINTBLKEY);
258 handle = DBUtil.buildConnection(dbProps, true);
259 stmt = handle.conn.createStatement();
260 log.info(" source db: " + handle);
261 origSource = DBIterable.buildSource(handle, stmt, dbTable, f.allTerms()); // TODO: deep intern db sources also
262 log.info(" query: " + origSource);
263 }
264 if(memorize) {
265 final Ticker ticker = new Ticker("LogisticTrain-memorize data");
266 final ArrayList<BurstMap> list = new ArrayList<BurstMap>();
267 for(final BurstMap row: origSource) {
268 ticker.tick();
269 list.add(row);
270 }
271 trainSource = list;
272 if(null!=stmt) {
273 stmt.close();
274 stmt = null;
275 }
276 if(null!=handle) {
277 handle.conn.close();
278 handle = null;
279 }
280 } else {
281 trainSource = origSource;
282 }
283 }
284 log.info("formula: " + f);
285 final LogisticTrain trainer;
286 if(cl.getOptionValue(TRAINCLASSKEY)!=null) {
287 trainer = (LogisticTrain)Class.forName(cl.getOptionValue(TRAINCLASSKEY)).newInstance();
288 } else {
289 trainer = new LogisticTrain();

Callers

nothing calls this directly

Calls 7

parseCommandLineMethod · 0.95
valueAsFileMethod · 0.95
allTermsMethod · 0.95
tickMethod · 0.95
runMethod · 0.95
toStringMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected