机器学习java_Java机器学习,第2部分
生活随笔
收集整理的這篇文章主要介紹了
机器学习java_Java机器学习,第2部分
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
機器學習java
歡迎使用本教程的第二部分,該教程使用LightningScorer為PMML文件評分。
讓我們找出其他參數是如何工作的。
初始步驟與教程的第一部分相似。
首先獲取本地副本
git clone https://github.com/sezinkarli/lightningscorer.git并用Maven構建它
mvn clean install并通過轉到目標文件夾開始
java -jar lightningscorer-uberjar-1.0.jar現在,通過轉到以下步驟來確保我們的服務器已啟動并正在運行
http://localhost:8080/。
服務器退貨
{ "data": "I have come here to chew bubblegum and kick ass...", "success": true }好吧,現在我們可以再次踢屁股。
我將使用apache commons的http get / post方法。 首先,我們將使用其他參數來部署我們的機器學習模型。 然后,我們將檢查它是否正常工作,然后使用我們的輸入值進行評分。 計分之后,我們將使用其他參數。
final String url = "http://localhost:8080/model/";final String modelId = "test2";//http://dmg.org/pmml/pmml_examples/knime_pmml_examples/ElNinoPolReg.xmlFile pmmlFile = new File("/tmp/ElNinoPolReg.xml");CloseableHttpClient client = HttpClients.createDefault();// deployment// notice that I give a variance value as an additional parameter that I will use laterHttpPost deployPost = new HttpPost(url + modelId + "?variance=3.25");MultipartEntityBuilder builder = MultipartEntityBuilder.create();builder.addBinaryBody("model", new File(pmmlFile.getAbsolutePath()), ContentType.APPLICATION_OCTET_STREAM, "model");HttpEntity multipart = builder.build();deployPost.setEntity(multipart);CloseableHttpResponse response = client.execute(deployPost);String deployResponse = IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8"));System.out.println(deployResponse);// {"data":true,"success":true}deployPost.releaseConnection();// check deployed modelHttpGet httpGet = new HttpGet(url + "ids");response = client.execute(httpGet);String getAllModelsResponse = IOUtils.toString(response.getEntity().getContent(), Charset.forName("UTF-8"));System.out.println(getAllModelsResponse);// {"data":["test1"],"success":true}httpGet.releaseConnection();//score deployed modelHttpPost scorePost = new HttpPost(url + modelId + "/score");StringEntity params = new StringEntity("{" +"\"fields\":" +"{\"latitude\":2.5," +"\"longitude\":11.4," +"\"zon_winds\":3.5," +"\"mer_winds\":3," +"\"humidity\":31.2," +"\"s_s_temp\":25.21" +"}" +"} ");scorePost.addHeader("content-type", "application/json");scorePost.setEntity(params);CloseableHttpResponse response2 = client.execute(scorePost);String scoreResponse = IOUtils.toString(response2.getEntity().getContent(), Charset.forName("UTF-8"));System.out.println(scoreResponse);// {"data":{"result":{"airtemp":29.788226026392735}},"success":true}scorePost.releaseConnection();HttpGet additionalParamGet = new HttpGet(url + modelId + "/additional");CloseableHttpResponse response3 = client.execute(additionalParamGet);String additionalParamResponse = IOUtils.toString(response3.getEntity().getContent(), Charset.forName("UTF-8"));System.out.println(additionalParamResponse);// {"data":{"variance":"3.25"},"success":true}additionalParamGet.releaseConnection();// Then you can use the variance value with your result in airtemp to calculate an interval for your scoreclient.close();翻譯自: https://www.javacodegeeks.com/2018/06/machine-learning-java-part-2.html
機器學習java
總結
以上是生活随笔為你收集整理的机器学习java_Java机器学习,第2部分的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cad返回快捷键是哪个键(cad返回键怎
- 下一篇: java 迁移数据_Java 10迁移建