### Question:
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);  }### Answer:
@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(); }
@Test public final void testLoadModelWithNoSchema() { final ExampleModelLoader loader = new ExampleModelLoader(0); final Path modelPath = get("dummy"); final DatasetSchema testSchema = new DatasetSchema(ImmutableList.of()); assertThatThrownBy(() -> loader.loadModel(modelPath, testSchema)) .as("The of loading a model with a dataset which has no target variable.") .isInstanceOf(IllegalArgumentException.class); }