| 41 | import com.winvector.variables.VariableEncodings; |
| 42 | |
| 43 | public class LogisticTrain { |
| 44 | |
| 45 | public static PrimaVariableInfo buildVariableDefs(final Formula f, final Iterable<BurstMap> source) { |
| 46 | // pass to get numeric columns and categorical columns |
| 47 | final Log log = LogFactory.getLog(LogisticTrain.class); |
| 48 | final PrimaVariableInfo def = new PrimaVariableInfo(); |
| 49 | def.readyForDefTracking(f); |
| 50 | // not going to parallelize this as it it is cheaper than scans that evaluate model probabilities. |
| 51 | log.info("start variable def scan 1/2"); |
| 52 | final Ticker ticker = new Ticker("build variable defs"); |
| 53 | for (BurstMap row : source) { |
| 54 | ticker.tick(); |
| 55 | def.trackVariableDefsFromRow(row); |
| 56 | } |
| 57 | log.info("start variable def scan 2/2"); |
| 58 | ticker.start(); |
| 59 | // pass to get levels of categorical variables |
| 60 | for(BurstMap row: source) { |
| 61 | ticker.tick(); |
| 62 | def.trackVariableLevelsFromRow(row); |
| 63 | } |
| 64 | log.info("done variable def scans"); |
| 65 | def.trimStuckLevels(); |
| 66 | return def; |
| 67 | } |
| 68 | |
| 69 | public static VariableEncodings buildAdpater(final Formula f, final String weightKey, |
| 70 | final Iterable<BurstMap> source) { |
| 71 | final PrimaVariableInfo def = buildVariableDefs(f,source); |
| 72 | return new VariableEncodings(def,f.useIntercept,weightKey); |
| 73 | } |
| 74 | |
| 75 | private static final String TRAINURIKEY = "trainURI"; |
| 76 | private static final String TRAINSEP = "sep"; |
| 77 | private static final String TRAINHDLKEY = "trainHDL"; |
| 78 | private static final String TRAINTBLKEY = "trainTBL"; |
| 79 | private static final String MEMKEY = "inmemory"; |
| 80 | private static final String FORMULAKEY = "formula"; |
| 81 | private static final String WEIGHTKEY = "weights"; |
| 82 | private static final String RESULTSERKEY = "resultSer"; |
| 83 | private static final String RESULTTSVKEY = "resultTSV"; |
| 84 | private static final String TRAINCLASSKEY = "trainClass"; |
| 85 | |
| 86 | private static CommandLine parseCommandLine(final String[] args) throws org.apache.commons.cli.ParseException { |
| 87 | final CommandLineParser clparser = new GnuParser(); |
| 88 | final Options cloptions = new Options(); |
| 89 | cloptions.addOption(TRAINURIKEY,true,"URI to get training TSV data from"); |
| 90 | cloptions.addOption(TRAINSEP,true,"(optional) training data input separator"); |
| 91 | cloptions.addOption(TRAINHDLKEY,true,"XML file to get JDBC connection to training data table"); |
| 92 | cloptions.addOption(TRAINTBLKEY,true,"table to use from database for training data"); |
| 93 | cloptions.addOption(MEMKEY, false, "(optional) if set data is held in memory during training"); |
| 94 | cloptions.addOption(FORMULAKEY,true,"formula to fit"); |
| 95 | cloptions.addOption(WEIGHTKEY,true,"(optional) symbol to user for weights"); |
| 96 | cloptions.addOption(RESULTSERKEY,true,"(optional) file to write seriazlized results to"); |
| 97 | cloptions.addOption(RESULTTSVKEY,true,"(optional) file to write TSV results to"); |
| 98 | cloptions.addOption(TRAINCLASSKEY,true,"(optional) alternate class to use for training"); |
| 99 | cloptions.getOption(FORMULAKEY).setRequired(true); |
| 100 | final CommandLine cl = clparser.parse(cloptions, args); |
nothing calls this directly
no outgoing calls
no test coverage detected