@Test public void loadModel() { final ExampleModelLoader loader = new ExampleModelLoader(0); final Path modelPath = get("dummy"); final DatasetSchema testSchema = TestDatasetSchemaBuilder.builder().withCategoricalFields(1).build(); assertThat(loader.loadModel(modelPath, testSchema)) .as("The result loading a model with the Example Loader") .isNotNull(); }
@Override public ExampleModel loadModel(final Path modelPath, final DatasetSchema schema) { if (!schema.getTargetIndex().isPresent()) { throw new IllegalArgumentException("This model requires a schema with a predefined target variable."); } final int numberClasses = ((CategoricalValueSchema) schema .getFieldSchemas() .get(schema.getTargetIndex().get()) .getValueSchema()) .getNominalValues() .size(); final double[] fixedPrediction = new double[numberClasses]; fixedPrediction[this.indexToPredict] = 1.0; return new ExampleModel(schema, this.indexToPredict, fixedPrediction); }
ExampleModelLoader implements MachineLearningModelLoader<ExampleModel> { @Override public ExampleModel loadModel(final Path modelPath, final DatasetSchema schema) { if (!schema.getTargetIndex().isPresent()) { throw new IllegalArgumentException("This model requires a schema with a predefined target variable."); } final int numberClasses = ((CategoricalValueSchema) schema .getFieldSchemas() .get(schema.getTargetIndex().get()) .getValueSchema()) .getNominalValues() .size(); final double[] fixedPrediction = new double[numberClasses]; fixedPrediction[this.indexToPredict] = 1.0; return new ExampleModel(schema, this.indexToPredict, fixedPrediction); } }
ExampleModelLoader implements MachineLearningModelLoader<ExampleModel> { @Override public ExampleModel loadModel(final Path modelPath, final DatasetSchema schema) { if (!schema.getTargetIndex().isPresent()) { throw new IllegalArgumentException("This model requires a schema with a predefined target variable."); } final int numberClasses = ((CategoricalValueSchema) schema .getFieldSchemas() .get(schema.getTargetIndex().get()) .getValueSchema()) .getNominalValues() .size(); final double[] fixedPrediction = new double[numberClasses]; fixedPrediction[this.indexToPredict] = 1.0; return new ExampleModel(schema, this.indexToPredict, fixedPrediction); } ExampleModelLoader(final int indexToPredict); }
ExampleModelLoader implements MachineLearningModelLoader<ExampleModel> { @Override public ExampleModel loadModel(final Path modelPath, final DatasetSchema schema) { if (!schema.getTargetIndex().isPresent()) { throw new IllegalArgumentException("This model requires a schema with a predefined target variable."); } final int numberClasses = ((CategoricalValueSchema) schema .getFieldSchemas() .get(schema.getTargetIndex().get()) .getValueSchema()) .getNominalValues() .size(); final double[] fixedPrediction = new double[numberClasses]; fixedPrediction[this.indexToPredict] = 1.0; return new ExampleModel(schema, this.indexToPredict, fixedPrediction); } ExampleModelLoader(final int indexToPredict); @Override ExampleModel loadModel(final Path modelPath, final DatasetSchema schema); @Override List<ParamValidationError> validateForLoad(final Path modelPath,
                                                      final DatasetSchema schema,
                                                      final Map<String, String> params); @Override DatasetSchema loadSchema(final Path modelPath); }
ExampleModelLoader implements MachineLearningModelLoader<ExampleModel> { @Override public ExampleModel loadModel(final Path modelPath, final DatasetSchema schema) { if (!schema.getTargetIndex().isPresent()) { throw new IllegalArgumentException("This model requires a schema with a predefined target variable."); } final int numberClasses = ((CategoricalValueSchema) schema .getFieldSchemas() .get(schema.getTargetIndex().get()) .getValueSchema()) .getNominalValues() .size(); final double[] fixedPrediction = new double[numberClasses]; fixedPrediction[this.indexToPredict] = 1.0; return new ExampleModel(schema, this.indexToPredict, fixedPrediction); } ExampleModelLoader(final int indexToPredict); @Override ExampleModel loadModel(final Path modelPath, final DatasetSchema schema); @Override List<ParamValidationError> validateForLoad(final Path modelPath,
                                                      final DatasetSchema schema,
                                                      final Map<String, String> params); @Override DatasetSchema loadSchema(final Path modelPath);  }