/** * Close connection */ @Override public void close() throws IOException { client.close(); }
/** * Permanently delete a model instance. * * @param algorithm the algorithm * @param modelID the model id * @throws LensException the lens exception */ @Override public void deleteModel(String algorithm, String modelID) throws LensException { client.deleteModel(algorithm, modelID); }
/** * Permanently delete a test report instance. * * @param algorithm the algorithm * @param reportID the report id * @throws LensException the lens exception */ @Override public void deleteTestReport(String algorithm, String reportID) throws LensException { client.deleteTestReport(algorithm, reportID); }
/** * Train model. * * @param algorithm the algorithm * @param params the params * @return the string */ public String trainModel(String algorithm, Form params) { return getMLWebTarget().path(algorithm).path("train").request(MediaType.APPLICATION_JSON_TYPE) .post(Entity.entity(params, MediaType.APPLICATION_FORM_URLENCODED_TYPE), String.class); }
ModelMetadata metadata = client.getModelMetadata(algorithm, modelId); String modelPathURI = metadata.getModelPath(); URI modelURI = new URI(modelPathURI); Path modelPath = new Path(modelURI); FileSystem fs = FileSystem.get(modelURI, client.getConf()); in = new ObjectInputStream(fs.open(modelPath)); MLModel<?> model = (MLModel) in.readObject();
/** * Get list of available machine learning algorithms * * @return */ @Override public List<String> getAlgorithms() { return client.getAlgoNames(); }
/** * Get model IDs for the given algorithm. * * @param algorithm the algorithm * @return the models * @throws LensException the lens exception */ @Override public List<String> getModels(String algorithm) throws LensException { return client.getModelsForAlgorithm(algorithm); }
/** * Get user friendly information about parameters accepted by the algorithm. * * @param algorithm the algorithm * @return map of param key to its help message */ @Override public Map<String, String> getAlgoParamDescription(String algorithm) { List<String> paramDesc = client.getParamDescriptionOfAlgo(algorithm); // convert paramDesc to map Map<String, String> paramDescMap = new LinkedHashMap<String, String>(); for (String str : paramDesc) { String[] keyHelp = StringUtils.split(str, ":"); paramDescMap.put(keyHelp[0].trim(), keyHelp[1].trim()); } return paramDescMap; }
/** * Get the FS location where model instance is saved. * * @param algorithm the algorithm * @param modelID the model id * @return the model path */ @Override public String getModelPath(String algorithm, String modelID) { ModelMetadata metadata = client.getModelMetadata(algorithm, modelID); return metadata.getModelPath(); }
public LensMLClient(LensClient lensClient) { client = new LensMLJerseyClient(lensClient.getConnection(), lensClient .getConnection().getSessionHandle()); }
/** * Gets the model metadata. * * @param algorithm the algorithm * @param modelID the model id * @return the model metadata */ public ModelMetadata getModelMetadata(String algorithm, String modelID) { try { return getMLWebTarget().path("models").path(algorithm).path(modelID).request().get(ModelMetadata.class); } catch (NotFoundException exc) { return null; } }
/** * Gets the test report. * * @param algorithm the algorithm * @param reportID the report id * @return the test report */ public TestReport getTestReport(String algorithm, String reportID) { try { return getMLWebTarget().path("reports").path(algorithm).path(reportID).request().get(TestReport.class); } catch (NotFoundException exc) { return null; } }
/** * Delete test report. * * @param algorithm the algorithm * @param reportID the report id * @return the string */ public String deleteTestReport(String algorithm, String reportID) { return getMLWebTarget().path("reports").path(algorithm).path(reportID).request().delete(String.class); }
/** * Delete model. * * @param algorithm the algorithm * @param modelID the model id */ public void deleteModel(String algorithm, String modelID) { getMLWebTarget().path("models").path(algorithm).path(modelID).request().delete(); }
/** * Predict single. * * @param algorithm the algorithm * @param modelID the model id * @param features the features * @return the string */ public String predictSingle(String algorithm, String modelID, Map<String, String> features) { WebTarget target = getMLWebTarget().path("predict").path(algorithm).path(modelID); for (Map.Entry<String, String> entry : features.entrySet()) { target.queryParam(entry.getKey(), entry.getValue()); } return target.request().get(String.class); }
public List<String> getAlgoNames() { StringList algoNames = getMLWebTarget().path("algos").request().get(StringList.class); return algoNames == null ? null : algoNames.getElements(); }
/** * Gets the test reports of algorithm. * * @param algorithm the algorithm * @return the test reports of algorithm */ public List<String> getTestReportsOfAlgorithm(String algorithm) { try { StringList list = getMLWebTarget().path("reports").path(algorithm).request().get(StringList.class); return list == null ? null : list.getElements(); } catch (NotFoundException exc) { return null; } }
/** * Gets the models for algorithm. * * @param algorithm the algorithm * @return the models for algorithm */ public List<String> getModelsForAlgorithm(String algorithm) { try { StringList models = getMLWebTarget().path("models").path(algorithm).request().get(StringList.class); return models == null ? null : models.getElements(); } catch (NotFoundException exc) { return null; } }
/** * Gets the param description of algo. * * @param algorithm the algorithm * @return the param description of algo */ public List<String> getParamDescriptionOfAlgo(String algorithm) { try { StringList paramHelp = getMLWebTarget().path("algos").path(algorithm).request(MediaType.APPLICATION_XML) .get(StringList.class); return paramHelp.getElements(); } catch (NotFoundException exc) { return null; } }
/** * Test model. * * @param table the table * @param algorithm the algorithm * @param modelID the model id * @param outputTable the output table name * @return the string */ public String testModel(String table, String algorithm, String modelID, String outputTable) { WebTarget modelTestTarget = getMLWebTarget().path("test").path(table).path(algorithm).path(modelID); FormDataMultiPart mp = new FormDataMultiPart(); LensSessionHandle sessionHandle = this.sessionHandle == null ? connection.getSessionHandle() : this.sessionHandle; mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), sessionHandle, MediaType.APPLICATION_XML_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("outputTable").build(), outputTable)); return modelTestTarget.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class); }