Runs a training algorithm on the entire DDF dataset. @param trainMethodName @param args @return @throws DDFException
(String trainMethodName, Object... paramArgs)
| 72 | * @throws DDFException |
| 73 | */ |
| 74 | @Override |
| 75 | public IModel train(String trainMethodName, Object... paramArgs) throws DDFException { |
| 76 | /** |
| 77 | * Example signatures we must support: |
| 78 | * <p/> |
| 79 | * Unsupervised Training |
| 80 | * <p/> |
| 81 | * <code> |
| 82 | * Kmeans.train(data: RDD[Array[Double]], k: Int, maxIterations: Int, runs: Int, initializationMode: String) |
| 83 | * </code> |
| 84 | * <p/> |
| 85 | * Supervised Training |
| 86 | * <p/> |
| 87 | * <code> |
| 88 | * LogisticRegressionWithSGD.train(input: RDD[LabeledPoint], numIterations: Int, stepSize: Double, miniBatchFraction: |
| 89 | * Double, initialWeights: Array[Double]) |
| 90 | * |
| 91 | * SVM.train(input: RDD[LabeledPoint], numIterations: Int, stepSize: Double, regParam: Double, miniBatchFraction: |
| 92 | * Double) |
| 93 | * </code> |
| 94 | */ |
| 95 | |
| 96 | // Build the argument type array |
| 97 | if (paramArgs == null) paramArgs = new Object[0]; |
| 98 | |
| 99 | // Locate the training method |
| 100 | String mappedName = Config.getValueWithGlobalDefault(this.getEngine(), trainMethodName); |
| 101 | if (!Strings.isNullOrEmpty(mappedName)) trainMethodName = mappedName; |
| 102 | |
| 103 | TrainMethod trainMethod = new TrainMethod(trainMethodName, MLClassMethods.DEFAULT_TRAIN_METHOD_NAME, paramArgs); |
| 104 | if (trainMethod.getMethod() == null) { |
| 105 | throw new DDFException(String.format("Cannot locate method specified by %s", trainMethodName)); |
| 106 | } |
| 107 | |
| 108 | // Now we need to map the DDF and its column specs to the input format expected by the method we're invoking |
| 109 | Object[] allArgs = this.buildArgsForMethod(trainMethod.getMethod(), paramArgs); |
| 110 | |
| 111 | // Invoke the training method |
| 112 | Object rawModel = trainMethod.classInvoke(allArgs); |
| 113 | |
| 114 | |
| 115 | List<Schema.Column> columns = this.getDDF().getSchemaHandler().getColumns(); |
| 116 | String[] trainedColumns = new String[columns.size()]; |
| 117 | |
| 118 | for (int i = 0; i < columns.size(); i++) { |
| 119 | trainedColumns[i] = columns.get(i).getName(); |
| 120 | } |
| 121 | |
| 122 | for (String col : trainedColumns) { |
| 123 | mLog.info(">>>>>> trainedCol = " + col); |
| 124 | } |
| 125 | |
| 126 | IModel model = this.newModel(rawModel); |
| 127 | model.setTrainedColumns(trainedColumns); |
| 128 | mLog.info(">>>> modelID = " + model.getName()); |
| 129 | this.getManager().addModel(model); |
| 130 | return model; |
| 131 | } |
nothing calls this directly
no test coverage detected