{"id":4685,"date":"2018-02-27T08:17:59","date_gmt":"2018-02-27T16:17:59","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=4685"},"modified":"2025-06-13T23:16:58","modified_gmt":"2025-06-14T06:16:58","slug":"machine-learning-couchbase-nexosis","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/","title":{"rendered":"Machine Learning with Couchbase and Nexosis"},"content":{"rendered":"<div class=\"paragraph\">\n<p>Machine Learning is a tool that is helping developers and data scientists to accomplish all sorts of tasks:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>Classification &#8211; organize and tag data<\/p>\n<\/li>\n<li>\n<p>Regression &#8211; find relationships between data points<\/p>\n<\/li>\n<li>\n<p>Forecasting &#8211; use current data to predict the future<\/p>\n<\/li>\n<li>\n<p>Anomaly detection &#8211; find unusual data points<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>In this post, I&#8217;m going to show you how you can combine the web-based REST API that Nexosis provides for machine learning with Couchbase Server.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>The first place to go when trying out machine learning is often Kaggle. Kaggle provides a wide variety of data sets perfect for machine learning applications. I&#8217;ve decided to use the <a href=\"https:\/\/www.kaggle.com\/bittlingmayer\/amazonreviews\">Amazon Reviews for Sentiment Analysis data set<\/a> (I have <a href=\"https:\/\/raw.githubusercontent.com\/couchbaselabs\/blog-source-code\/master\/Groves\/101MachineLearningNexosis\/src\/modified5000.csv\">truncated it and slightly modified it for this post<\/a>).<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>The data in this set contains the text of a review left on Amazon and a label of either &#8220;__label__1&#8221; or &#8220;__label__2&#8221;. The former means it was a negative review (1 or 2 stars) and the latter means it was a positive review (4 or 5 stars). Score 3 is consider neutral and is not included in this training set, but I&#8217;m going to explore that a little later.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>My goal is to give Nexosis an Amazon review that is <strong>not<\/strong> in the training set, and have Nexosis classify it as &#8220;__label__1&#8221; or &#8220;__label__2&#8221; for me. This type of classification is also known as <strong>sentiment analysis<\/strong>. This can be useful for early warning of negative customer experience, for instance.<\/p>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_create_your_nexosis_machine_learning_account\">Create your Nexosis machine learning account<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>I found it very easy to get started with <a href=\"https:\/\/nexosis.com\">Nexosis<\/a>. The community edition of <a href=\"https:\/\/nexosis.com\/pricing\">Nexosis is free<\/a>. Once you log in, visit your profile page and make note of your API key (you&#8217;ll need it for every API request you make).<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/02\/10101-nexosis-machine-learning-api-key.png\" alt=\"Nexosis machine learning API key\"><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>From this point on, when making an HTTP request to Nexosis, you will need to include that key in your header as <code>api-key<\/code>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_setting_up_machine_learning\">Setting up machine learning<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The first step to setup Nexosis is to give it a data set. I&#8217;m using the data set I got from Kaggle. The data is a two column CSV file. To get this data to Nexosis, you can make a request like so (using a tool like Postman, for instance):<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>POST https:\/\/ml.nexosis.com\/v1\/imports\/url\r\n\r\n{\r\n\t\"dataSetName\" : \"AmazonReviews\",\r\n\t\"url\" : \"https:\/\/raw.githubusercontent.com\/couchbaselabs\/blog-source-code\/master\/Groves\/101MachineLearningNexosis\/src\/modified5000.csv\"\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Don&#8217;t forget the api-key in the header!<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>The response from this request, if successful, should look similar to this:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>{\r\n  \"importId\": \"&lt; guid &gt;\",\r\n  \"type\": \"url\",\r\n  \"status\": \"requested\",\r\n  \"dataSetName\": \"AmazonReviews\",\r\n  \"parameters\": {\r\n    \"url\": \"https:\/\/raw.githubusercontent.com\/\"\r\n  },\r\n  \"requestedDate\": \"2018-02-19T19:04:13.012859+00:00\",\r\n  \"statusHistory\": [\r\n    {\r\n      \"date\": \"2018-02-19T19:04:13.012859+00:00\",\r\n      \"status\": \"requested\"\r\n    }\r\n  ],\r\n  \"messages\": [],\r\n  \"columns\": {},\r\n  \"links\": [\r\n    {\r\n      \"rel\": \"self\",\r\n      \"href\": \"https:\/\/ml.nexosis.com\/v1\/imports\/url\"\r\n    },\r\n    {\r\n      \"rel\": \"data\",\r\n      \"href\": \"https:\/\/ml.nexosis.com\/v1\/data\/AmazonReviews\"\r\n    }\r\n  ]\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>This import may take a little time. You can make a GET request to  https:\/\/ml.nexosis.com\/v1\/imports to check to see that your request went through. You&#8217;ll see this data set as one of the &#8220;items&#8221;.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_creating_a_nexosis_session\">Creating a Nexosis session<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The next step is to create a Nexosis session. This will start Nexosis training on the data that you already imported. Here&#8217;s a sample POST to start a session:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>POST https:\/\/ml.nexosis.com\/v1\/sessions\/model\r\n{\r\n\t\"predictionDomain\":\"classification\",\r\n\t\"dataSourceName\" : \"AmazonReviews\",\r\n\t\"targetColumn\": \"review_sentiment\",\r\n\t\"extraParameters\" : { \"balance\": true }\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Some notes on what this all means:<\/p>\n<\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><code>\"predictionDomain\":\"classification\"<\/code> &#8211; Remember when I said I was going to use &#8220;classification&#8221; for sentiment analysis?<\/p>\n<\/li>\n<li>\n<p><code>\"dataSourceName\" : \"AmazonReviews\"<\/code> &#8211; I gave the data source this name, so I&#8217;m telling it to use this data source for training.<\/p>\n<\/li>\n<li>\n<p><code>\"targetColumn\": \"review_sentiment\"<\/code> &#8211; The &#8216;review_sentiment&#8217; column contains the &#8220;__label__1&#8221; or &#8220;__label__2&#8221; values. This is the value that I want Nexosis to learn how to generate.<\/p>\n<\/li>\n<li>\n<p><code>\"extraParameters\" : { \"balance\": true }<\/code> &#8211; If your data set is unbalanced (meaning, for instance, it contains a lot more negative reviews than positive ones), that could disproportionally influence the machine learning. Set balance to &#8220;true&#8221; to adjust for this.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<div class=\"paragraph\">\n<p>The response from that request will look something like this:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>{\r\n  \"columns\": {\r\n    \"text\": {\r\n      \"dataType\": \"text\",\r\n      \"role\": \"feature\"\r\n    },\r\n    \"review_sentiment\": {\r\n      \"dataType\": \"string\",\r\n      \"role\": \"target\",\r\n      \"imputation\": \"mode\",\r\n      \"aggregation\": \"mode\"\r\n    }\r\n  },\r\n  \"sessionId\": \"&lt; guid &gt;\",\r\n  \"type\": \"model\",\r\n  \"status\": \"requested\",\r\n  \"predictionDomain\": \"classification\",\r\n  \"availablePredictionIntervals\": [],\r\n  \"requestedDate\": \"2018-02-19T19:28:41.812052+00:00\",\r\n  \"statusHistory\": [\r\n    {\r\n      \"date\": \"2018-02-19T19:28:41.812052+00:00\",\r\n      \"status\": \"requested\"\r\n    }\r\n  ],\r\n  \"extraParameters\": {\r\n    \"balance\": true\r\n  },\r\n  \"messages\": [],\r\n  \"name\": \"Classification on AmazonReviews\",\r\n  \"dataSourceName\": \"AmazonReviews\",\r\n  \"dataSetName\": \"AmazonReviews\",\r\n  \"targetColumn\": \"review_sentiment\",\r\n  \"isEstimate\": false,\r\n  \"links\": [\r\n    {\r\n      \"rel\": \"results\",\r\n      \"href\": \"https:\/\/ml.nexosis.com\/v1\/sessions\/&lt; guid &gt;\/results\"\r\n    },\r\n    {\r\n      \"rel\": \"data\",\r\n      \"href\": \"https:\/\/ml.nexosis.com\/v1\/data\/AmazonReviews\"\r\n    },\r\n    {\r\n      \"rel\": \"vocabularies\",\r\n      \"href\": \"https:\/\/ml.nexosis.com\/v1\/vocabulary?createdFromSessionid=&lt; guid &gt;\"\r\n    }\r\n  ]\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Note that this type of session will take some time to produce. You will get an email notification from Nexosis when the session is ready. You can also check the &#8220;results&#8221; (see the above URL) from time to time.<\/p>\n<\/div>\n<div class=\"sect2\">\n<h3 id=\"_completed_model\">Completed model<\/h3>\n<div class=\"paragraph\">\n<p>Once the session is completed, you will get a <code>modelId<\/code> in the results, that will be another GUID. You will need this to proceed.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Once you receive the modelId, you can check to see how accurate the model is. Make a GET to https:\/\/ml.nexosis.com\/v1\/sessions\/&lt; guid &gt;\/results and look at the <code>metrics<\/code> field. The results for mine looks like:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>\"metrics\": {\r\n  \"macroAverageF1Score\": 0.81341486902927584,\r\n  \"rocAreaUnderCurve\": 0.88777613666838784,\r\n  \"accuracy\": 0.814,\r\n  \"macroAveragePrecision\": 0.81521331769769212,\r\n  \"macroAverageRecall\": 0.81309365130828448,\r\n  \"matthewsCorrelationCoefficient\": 0.62830339352567144\r\n},<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>This will let you know how reliable the model is. If it&#8217;s not high enough for whatever threshold you decide you need, you may want to try adjusting your model<br \/>\nfor better accuracy. You can consider adding\/removing fields from the training set until you meet the necessary threshold.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>It&#8217;s still not going to be perfect, so if this analysis is going to be used for something high-impact and crucial, you may want to involve a human in some part of the process.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>81% accuracy is enough for me to proceed.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_test_out_the_machine_learning_model\">Test out the machine learning model<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Let&#8217;s test the model out with REST. I&#8217;ll be making a POST request to the <strong>\/predict<\/strong> url using the modelId like:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><code>POST https:\/\/ml.nexosis.com\/v1\/models\/&lt;model ID guid&gt;\/predict<\/code><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>The body of this request will contain the Amazon review that I want to get Nexosis&#8217;s opinion on. I&#8217;ll give it the text of a 1-star review.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>{\r\n\t\"data\":[{\r\n\t\t\"text\" : \"Junk! Don't waste your money! ... It worked great for about two weeks then progressively got worse for the next four until it now barely works\"\r\n\t}],\r\n\t\t\"extraParameters\" :{\r\n\t\t\t\"includeClassScores\" : false\r\n\t\t}\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>When submitting that, Nexosis will think about it and return a result like this:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>{\r\n  \"data\": [\r\n    {\r\n      \"text\": \"Junk! Don't waste your money! ... It worked great for about two weeks then progressively got worse for the next four until it now barely works\",\r\n      \"review_sentiment\": \"__label__1\"\r\n    }\r\n  ],\r\n\r\n  \/\/ ... etc ...\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>This means two things:<\/p>\n<\/div>\n<div class=\"olist arabic\">\n<ol class=\"arabic\">\n<li>\n<p>The model is working okay!<\/p>\n<\/li>\n<li>\n<p>The review I just sent is likely a negative review. Reading it myself, I would have to agree.<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_using_nexosis_in_couchbase\">Using Nexosis in Couchbase<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Instead of creating these POST requests by hand, we can use Nexosis directly in Couchbase.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><em>Note: Nexosis doesn&#8217;t require Couchbase and vice versa. Nexosis simply exposes a JSON REST API and Couchbase is able to use it. They work well together because they both follow common web standards.<\/em><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>To use Nexosis in Couchbase, simply make CURL requests to the Nexosis API from a Couchbase N1QL query.<\/p>\n<\/div>\n<div class=\"sect2\">\n<h3 id=\"_allowing_curl_in_couchbase\">Allowing CURL in Couchbase<\/h3>\n<div class=\"paragraph\">\n<p>First, you need to setup couchbase to allow it to make <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/5.0\/n1ql\/n1ql-language-reference\/curl.html\">CURL<\/a> requests. Allowing any arbitrary CURL request would be a security risk, so you&#8217;ll need to opt-in to allowing certain requests. You do this by creating (or updating) a curl_whitelist.json file. Check out <a href=\"https:\/\/www.couchbase.com\/blog\/curl-comes-n1ql-querying-external-json-data\/\">CURL Comes to N1QL<\/a> for more details.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Here is the curl_whitelist.json I&#8217;m using. On Windows, this file goes in the <code>C:\\Program Files\\Couchbase\\Server\\var\\lib\\couchbase\\n1qlcerts<\/code> folder.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code>{\r\n  \"all_access\":false,\r\n  \"allowed_urls\":[\"https:\/\/ml.nexosis.com\/v1\/models\/&lt; modelId guid &gt;\/predict \"],\r\n  \"disallowed_urls\":[]\r\n}<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect2\">\n<h3 id=\"_creating_a_n1ql_query\">Creating a N1QL query<\/h3>\n<div class=\"paragraph\">\n<p>N1QL is Couchbase&#8217;s SQL implementation used to query JSON. Ultimately, you may want Nexosis to feed into UPDATE or INSERT commands. But for this post, I&#8217;m just going to use a SELECT.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>In Couchbase, I&#8217;ve created a bucket with some reviews I pulled manually from Amazon. (I also executed <code>CREATE PRIMARY INDEX on reviews<\/code>).<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/02\/10102-reviews-in-bucket.png\" alt=\"Reviews in Couchbase bucket\"><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>These were not part of the training data, so Nexosis will be giving a positive or negative sentiment score on its own.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Let&#8217;s start with a simple <code>SELECT<\/code> and build from there.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/02\/10103-query-1.png\" alt=\"First simple query\"><\/span><\/p>\n<\/div>\n<\/div>\n<div class=\"sect2\">\n<h3 id=\"_using_curl_to_bring_in_machine_learning\">Using CURL to bring in Machine Learning<\/h3>\n<div class=\"paragraph\">\n<p>Next, I&#8217;ll bring in CURL. I&#8217;m using <a href=\"https:\/\/developer.couchbase.com\/documentation\/server\/current\/n1ql\/n1ql-language-reference\/let.html\">LET<\/a> to make the query more readable.<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-SQL\">SELECT CURL(url, { \"header\": headers, \"data\": body, \"request\":requestType}) AS nexosis\r\nFROM reviews r\r\n\r\nLET\r\nurl = 'https:\/\/ml.nexosis.com\/v1\/models\/&lt; modelId guid &gt;\/predict',\r\nheaders = [\"Content-Type: application\/json\", \"api-key: &lt; my API key &gt;\"],\r\nbody = '{ \"data\": [{ \"text\": \"' || r.text || '\" }], \"extraParameters\": { \"includeClassScores\": false }}',\r\nrequestType = \"POST\";<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>Notice that the <code>body<\/code> is pulling the text directly from the review document in Couchbase. The only thing I&#8217;ve selected (so far) is the entire response from Nexosis, which looks similar to this:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p><span class=\"image\"><img decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2018\/02\/10104-query-2.png\" alt=\"Query 2\"><\/span><\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>I could further drill into the results from Nexosis, and put it side by side with the actual score from Amazon to see how Nexosis did. Here&#8217;s the query:<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-SQL\">SELECT r.actual, r.text, CURL(url, { \"header\": headers, \"data\": body, \"request\":requestType}).data[0].review_sentiment AS nexosis\r\nFROM reviews r\r\n\r\nLET\r\nurl = 'https:\/\/ml.nexosis.com\/v1\/models\/&lt; modelId GUID &gt;\/predict',\r\nheaders = [\"Content-Type: application\/json\", \"api-key: &lt; my api key &gt;\"],\r\nbody = '{ \"data\": [{ \"text\": \"' || r.text || '\" }], \"extraParameters\": { \"includeClassScores\": false }}',\r\nrequestType = \"POST\";<\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"paragraph\">\n<p>And here&#8217;s the results (I truncated the full text):<\/p>\n<\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight decode:true\"><code class=\"language-JavaScript\">[\r\n  {\r\n    \"actual\": 1,\r\n    \"nexosis\": \"__label__1\",\r\n    \"text\": \"Junk! Don't waste your money...\"\r\n  },\r\n  {\r\n    \"actual\": 5,\r\n    \"nexosis\": \"__label__2\",\r\n    \"text\": \"This is the greatest thing since sliced bread...\"\r\n  },\r\n  {\r\n    \"actual\": 3,\r\n    \"nexosis\": \"__label__1\",\r\n    \"text\": \"The most confusing RC I've ever seen...\"\r\n  }\r\n]<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect2\">\n<h3 id=\"_results\">Results<\/h3>\n<div class=\"paragraph\">\n<p>As you might expect, Nexosis took the 1-star review from Amazon and rightly discerned that it was a negative review (classified it as &#8220;__label__1&#8221;).<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>It also took the 5-star review and rightly discerned that it was a positive review (classified it as &#8220;__label__2&#8221;).<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>I also decided to give it a 3-star &#8220;neutral&#8221; review. Note that the training set had none of these, so this may not be valid, but I was curious. It classified it as a negative review. Just based on the language alone this is probably accurate. This might actually be a helpful tool to look at ostensibly &#8220;neutral&#8221; reviews and discern if they are leaning one way or the other.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<h2 id=\"_summary\">Summary<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Anytime you use CURL in N1QL, be careful. When you use CURL, you are putting your query at the mercy of an HTTP request to a 3rd party. You may want to run these in the background as a batch process to <code>UPDATE<\/code> and <code>INSERT<\/code> instead of a live <code>SELECT<\/code> like I&#8217;m doing.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>But if you CURL wisely, you can use a 3rd party tool like Nexosis to peform machine learning, categorization, sentiment analysis, and more. Nexosis happened to make it very easy for me to get started and very easy to use with a standard CURL command.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>If you are interested in Nexosis, check out the <a href=\"https:\/\/nexosis.com\/use-case\">Nexosis Use Cases<\/a> page to see how Nexosis can help you or your business. If you have questions about using Nexosis, check out the <a href=\"https:\/\/community.nexosis.com\/\">Nexosis Forums<\/a>.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Have a question about Couchbase? Check out the <a href=\"https:\/\/www.couchbase.com\/forums\/\">Couchbase forums<\/a>, and check out the <a href=\"https:\/\/www.couchbase.com\/forums\/c\/sql\/16\">N1QL Forum<\/a> if you have a question about the queries you see in this post.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Have a question for me? I&#8217;m on <a href=\"https:\/\/twitter.com\/mgroves\">Twitter @mgroves<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Machine Learning is a tool that is helping developers and data scientists to accomplish all sorts of tasks: Classification &#8211; organize and tag data Regression &#8211; find relationships between data points Forecasting &#8211; use current data to predict the future [&hellip;]<\/p>\n","protected":false},"author":71,"featured_media":4686,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1816,1812],"tags":[1245,1771,2140,1950],"ppma_author":[8937],"class_list":["post-4685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-couchbase-server","category-n1ql-query","tag-cloud","tag-curl","tag-machine-learning","tag-rest-api"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Machine Learning with Couchbase and Nexosis - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Machine Learning APIs from Nexosis can be used from Couchbase using the CURL function in N1QL. In this post, machine learning classifies Amazon reviews.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Machine Learning with Couchbase and Nexosis\" \/>\n<meta property=\"og:description\" content=\"Machine Learning APIs from Nexosis can be used from Couchbase using the CURL function in N1QL. In this post, machine learning classifies Amazon reviews.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-27T16:17:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T06:16:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1039\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Matthew Groves\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mgroves\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matthew Groves\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\"},\"author\":{\"name\":\"Matthew Groves\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\"},\"headline\":\"Machine Learning with Couchbase and Nexosis\",\"datePublished\":\"2018-02-27T16:17:59+00:00\",\"dateModified\":\"2025-06-14T06:16:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\"},\"wordCount\":1489,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg\",\"keywords\":[\"cloud\",\"curl\",\"Machine Learning (ML)\",\"REST API\"],\"articleSection\":[\"Couchbase Server\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\",\"name\":\"Machine Learning with Couchbase and Nexosis - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg\",\"datePublished\":\"2018-02-27T16:17:59+00:00\",\"dateModified\":\"2025-06-14T06:16:58+00:00\",\"description\":\"Machine Learning APIs from Nexosis can be used from Couchbase using the CURL function in N1QL. In this post, machine learning classifies Amazon reviews.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg\",\"width\":1920,\"height\":1039},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Machine Learning with Couchbase and Nexosis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58\",\"name\":\"Matthew Groves\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g\",\"caption\":\"Matthew Groves\"},\"description\":\"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.\",\"sameAs\":[\"https:\/\/crosscuttingconcerns.com\",\"https:\/\/x.com\/mgroves\"],\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Machine Learning with Couchbase and Nexosis - The Couchbase Blog","description":"Machine Learning APIs from Nexosis can be used from Couchbase using the CURL function in N1QL. In this post, machine learning classifies Amazon reviews.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/","og_locale":"en_US","og_type":"article","og_title":"Machine Learning with Couchbase and Nexosis","og_description":"Machine Learning APIs from Nexosis can be used from Couchbase using the CURL function in N1QL. In this post, machine learning classifies Amazon reviews.","og_url":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/","og_site_name":"The Couchbase Blog","article_published_time":"2018-02-27T16:17:59+00:00","article_modified_time":"2025-06-14T06:16:58+00:00","og_image":[{"width":1920,"height":1039,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg","type":"image\/jpeg"}],"author":"Matthew Groves","twitter_card":"summary_large_image","twitter_creator":"@mgroves","twitter_misc":{"Written by":"Matthew Groves","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/"},"author":{"name":"Matthew Groves","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58"},"headline":"Machine Learning with Couchbase and Nexosis","datePublished":"2018-02-27T16:17:59+00:00","dateModified":"2025-06-14T06:16:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/"},"wordCount":1489,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg","keywords":["cloud","curl","Machine Learning (ML)","REST API"],"articleSection":["Couchbase Server","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/","url":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/","name":"Machine Learning with Couchbase and Nexosis - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg","datePublished":"2018-02-27T16:17:59+00:00","dateModified":"2025-06-14T06:16:58+00:00","description":"Machine Learning APIs from Nexosis can be used from Couchbase using the CURL function in N1QL. In this post, machine learning classifies Amazon reviews.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2018\/02\/101-hero-review-star.jpg","width":1920,"height":1039},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/machine-learning-couchbase-nexosis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Machine Learning with Couchbase and Nexosis"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/3929663e372020321b0152dc4fa65a58","name":"Matthew Groves","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ba51e6aacc53995c323a634e4502ef54","url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","caption":"Matthew Groves"},"description":"Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.","sameAs":["https:\/\/crosscuttingconcerns.com","https:\/\/x.com\/mgroves"],"url":"https:\/\/www.couchbase.com\/blog\/author\/matthew-groves\/"}]}},"authors":[{"term_id":8937,"user_id":71,"is_guest":0,"slug":"matthew-groves","display_name":"Matthew Groves","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/70feb1b28a099ad0112b8d21fe1e81e1a4524beed3e20b7f107d5370e85a07ab?s=96&d=mm&r=g","author_category":"","last_name":"Groves","first_name":"Matthew","job_title":"","user_url":"https:\/\/crosscuttingconcerns.com","description":"Matthew D. Groves is a guy who loves to code.  It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything.  He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s.  He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community.  He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/71"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=4685"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/4685\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/4686"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=4685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=4685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=4685"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}