{"id":12190,"date":"2021-10-06T00:00:39","date_gmt":"2021-10-06T07:00:39","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=12190"},"modified":"2025-06-13T21:25:12","modified_gmt":"2025-06-14T04:25:12","slug":"linear-regression-model-couchbase-jupyter-notebook-tutorial","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/","title":{"rendered":"Training a Linear Regression Model with Couchbase &#038; a Jupyter Notebook: Step-by-Step Tutorial"},"content":{"rendered":"<p><strong>Data scientists love Jupyter Notebooks<\/strong> \u2013 and it makes a natural pairing with the Couchbase document database. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook.jpg\" alt=\"Jupyter Notebook logo\" width=\"86\" height=\"100\" class=\"alignright size-full wp-image-12215\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook.jpg 86w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-17x20.jpg 17w\" sizes=\"auto, (max-width: 86px) 100vw, 86px\" \/><\/p>\n<p>Why? The <a href=\"https:\/\/jupyter-notebook-beginner-guide.readthedocs.io\/en\/latest\/what_is_jupyter.html?ref=hello-from-couchbase\" rel=\"noopener\" target=\"_blank\">Jupyter Notebook<\/a> web application lets you create and share documents that contain narrative text, equations and the like for use cases such as data visualization and machine learning. <a href=\"https:\/\/developer.couchbase.com\/new-to-couchbase\/?ref=blog\" rel=\"noopener\" target=\"_blank\">Couchbase<\/a> lets you store and process vast amounts of data (semi-structured and unstructured) at scale and support the kinds of data the world is full of: narrative text (social media posts, etc.), equations and more. <\/p>\n<p>In this post, you\u2019ll learn how to establish connectivity between a Couchbase cluster and a Jupyter Notebook, then pull data from Couchbase and use it to train a linear regression model for machine learning. We\u2019ll walk through an example to predict a target variable\u2019s value using categorical variables via a linear regression equation. <\/p>\n<h2>Loading Your Data<\/h2>\n<p>To kick things off, proceed through these steps to load the sample dataset: <\/p>\n<ol>\n<li>In the Couchbase cluster\u2019s Admin Console, go to Buckets > Add Bucket to create a new bucket, as shown here:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/couchbase-cluster-admin-console-add-bucket.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/couchbase-cluster-admin-console-add-bucket.png\" alt=\"Add a bucket in the Couchbase cluster admin console\" width=\"1000\" height=\"428\" class=\"aligncenter size-full wp-image-12196\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-cluster-admin-console-add-bucket.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-cluster-admin-console-add-bucket-300x128.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-cluster-admin-console-add-bucket-768x329.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-cluster-admin-console-add-bucket-20x9.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a>\n<\/li>\n<li>\n<p>Add documents to your bucket by either navigating to Documents > Add Document, like this:<\/p>\n<p>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/add-documents-to-Couchbase-bucket.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/add-documents-to-Couchbase-bucket.png\" alt=\"Add documents to a Couchbase bucket\" width=\"1000\" height=\"494\" class=\"aligncenter size-full wp-image-12193\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/add-documents-to-Couchbase-bucket.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/add-documents-to-Couchbase-bucket-300x148.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/add-documents-to-Couchbase-bucket-768x379.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/add-documents-to-Couchbase-bucket-20x10.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>or uploading a list of JSON documents or a CSV file. For this example we\u2019ll upload a CSV file using <a href=\"https:\/\/docs.couchbase.com\/server\/current\/tools\/cbimport.html?ref=blog\" rel=\"noopener\" target=\"_blank\">`cbimport`<\/a>. Here\u2019s what my document looks like:<\/p>\n<p>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/csv-file-upload-cbimport-tool.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/csv-file-upload-cbimport-tool.png\" alt=\"CSV file upload using the cbimport tool\" width=\"1000\" height=\"494\" class=\"aligncenter size-full wp-image-12197\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/csv-file-upload-cbimport-tool.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/csv-file-upload-cbimport-tool-300x148.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/csv-file-upload-cbimport-tool-768x379.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/csv-file-upload-cbimport-tool-20x10.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<\/li>\n<li>The file can be any data you want to work on. This example uses the <a href=\"https:\/\/www.kaggle.com\/ashydv\/advertising-dataset\/version\/1\" rel=\"noopener\" target=\"_blank\">Advertising Dataset from Kaggle.<\/a><\/li>\n<li>Go to Documents > Import, as shown here:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/import-documents-kaggle-advertising-dataset-couchbase.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/import-documents-kaggle-advertising-dataset-couchbase.png\" alt=\"Import the Kaggle advertising dataset documents into Couchbase\" width=\"1000\" height=\"486\" class=\"aligncenter size-full wp-image-12199\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/import-documents-kaggle-advertising-dataset-couchbase.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/import-documents-kaggle-advertising-dataset-couchbase-300x146.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/import-documents-kaggle-advertising-dataset-couchbase-768x373.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/import-documents-kaggle-advertising-dataset-couchbase-20x10.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<\/li>\n<li>\n<p>Select the file you wish to import and the data bucket where the documents reside:<\/p>\n<p>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/select-file-data-bucket-couchbase.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/select-file-data-bucket-couchbase.png\" alt=\"Select the file in the Couchbase data bucket\" width=\"1000\" height=\"625\" class=\"aligncenter size-full wp-image-12210\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/select-file-data-bucket-couchbase.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/select-file-data-bucket-couchbase-300x188.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/select-file-data-bucket-couchbase-768x480.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/select-file-data-bucket-couchbase-20x13.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<p>Your Documents menu should now look something like this:<\/p>\n<p>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/couchbase-admin-console-documents-menu.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/couchbase-admin-console-documents-menu.png\" alt=\"The documents menu in the Couchbase admin console\" width=\"1000\" height=\"625\" class=\"aligncenter size-full wp-image-12195\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-admin-console-documents-menu.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-admin-console-documents-menu-300x188.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-admin-console-documents-menu-768x480.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/couchbase-admin-console-documents-menu-20x13.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/p>\n<\/li>\n<li>In the Admin Console, create a primary index for the data bucket to make the data queryable, as you see here:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/primary-index-data-bucket-couchbase-web-console.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/primary-index-data-bucket-couchbase-web-console.png\" alt=\"Add a primary index to a data bucket in the Couchbase Web Console\" width=\"1000\" height=\"491\" class=\"aligncenter size-full wp-image-12207\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/primary-index-data-bucket-couchbase-web-console.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/primary-index-data-bucket-couchbase-web-console-300x147.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/primary-index-data-bucket-couchbase-web-console-768x377.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/primary-index-data-bucket-couchbase-web-console-20x10.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a>\n<\/li>\n<\/ol>\n<div class=\"wp-block-spacer\" style=\"height: 15px;\" aria-hidden=\"true\"> <\/div>\n<h2>Installing the Jupyter Notebook<\/h2>\n<p>First off, <a href=\"https:\/\/github.com\/couchbaselabs\/couchbase-jupyter-example#readme\" rel=\"noopener\" target=\"_blank\">download the couchbase-jupyter-example<\/a> from the Couchbase Labs GitHub repo. Then follow these steps:<\/p>\n<ol>\n<li><a href=\"https:\/\/jupyter.org\/install\" rel=\"noopener\" target=\"_blank\">Install Jupyter Notebook<\/a> via either the Python package management system (`pip`) or <a href=\"https:\/\/www.anaconda.com\/\" rel=\"noopener\" target=\"_blank\">Anaconda.<\/a><\/li>\n<li>Install the dependencies for this project by using `pip` from the `requirements` file in your shell:\n<pre>\r\n$ pip install -r requirements.txt\r\n<\/pre>\n<\/li>\n<li>Open Jupyter Notebook from the shell.<\/li>\n<li>Create a new notebook with Python 3, as shown here:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/new-jupyter-notebook-python-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/new-jupyter-notebook-python-3.png\" alt=\"Making a new Jupyter Notebook using Python 3\" width=\"1000\" height=\"362\" class=\"aligncenter size-full wp-image-12204\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/new-jupyter-notebook-python-3.png 1000w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/new-jupyter-notebook-python-3-300x109.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/new-jupyter-notebook-python-3-768x278.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/new-jupyter-notebook-python-3-20x7.png 20w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a>\n<\/li>\n<\/ol>\n<div class=\"wp-block-spacer\" style=\"height: 15px;\" aria-hidden=\"true\"> <\/div>\n<h2>What Is a Linear Regression Model?<\/h2>\n<p>The linear regression model is powerful for predictive analysis, letting us determine the strength of categorical or independent variables and forecasting the effect of those variables and identifying trends in the data. <\/p>\n<p>As you might deduce from the name <em>linear regression<\/em>, the \u201ccurve\u201d we use to fit the data is a line. The simplest form of the regression equation is `y = mx + c`, where `y` represents the target variable, `x` represents a single categorical variable and `m` and `c` are constants. We will use a simple linear regression equation in our example.<\/p>\n<p>The categorical variables in our example are `TV`, `Radio` and `Newspaper`. The target variable is `Sales`.<\/p>\n<h2>Training Our Linear Regression Model<\/h2>\n<ol>\n<li>In the new Jupyter Notebook, use the code shown below to connect to the Couchbase server. Use your username and password, of course, instead of `Administrator` and `123456`.<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook-connect-couchbase-server.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook-connect-couchbase-server.png\" alt=\"Connecting a Jupyter Notebook to Couchbase Server\" width=\"789\" height=\"110\" class=\"aligncenter size-full wp-image-12200\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-connect-couchbase-server.png 789w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-connect-couchbase-server-300x42.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-connect-couchbase-server-768x107.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-connect-couchbase-server-20x3.png 20w\" sizes=\"auto, (max-width: 789px) 100vw, 789px\" \/><\/a><\/p>\n<\/li>\n<li>Import the required libraries, shown in the screenshot here. If these libraries aren\u2019t present in your environment, download the latest versions of these libraries to the right environment using the Python package manager, `pip`.<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/python-package-manager-import-required-libraries.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/python-package-manager-import-required-libraries.png\" alt=\"Import required libraries using Python package manager\" width=\"772\" height=\"120\" class=\"aligncenter size-full wp-image-12208\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/python-package-manager-import-required-libraries.png 772w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/python-package-manager-import-required-libraries-300x47.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/python-package-manager-import-required-libraries-768x119.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/python-package-manager-import-required-libraries-20x3.png 20w\" sizes=\"auto, (max-width: 772px) 100vw, 772px\" \/><\/a><\/p>\n<\/li>\n<li>Using the `SELECT` command, fetch the data from your data bucket into a pandas data  frame:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/pandas-data-frame-fetch-data.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/pandas-data-frame-fetch-data.png\" alt=\"Fetch data into a pandas data frame\" width=\"782\" height=\"79\" class=\"aligncenter size-full wp-image-12206\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/pandas-data-frame-fetch-data.png 782w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/pandas-data-frame-fetch-data-300x30.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/pandas-data-frame-fetch-data-768x78.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/pandas-data-frame-fetch-data-20x2.png 20w\" sizes=\"auto, (max-width: 782px) 100vw, 782px\" \/><\/a><\/p>\n<\/li>\n<li>You can view the contents of your pandas data frame using the `describe()` command, as shown here:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/data-frame-contents-describe-command.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/data-frame-contents-describe-command.png\" alt=\"Using the describe command to view data frame contents\" width=\"785\" height=\"218\" class=\"aligncenter size-full wp-image-12198\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/data-frame-contents-describe-command.png 785w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/data-frame-contents-describe-command-300x83.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/data-frame-contents-describe-command-768x213.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/data-frame-contents-describe-command-20x6.png 20w\" sizes=\"auto, (max-width: 785px) 100vw, 785px\" \/><\/a><\/p>\n<\/li>\n<li>Create boxplots corresponding to the values of each categorical variable to detect outliers:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/boxplot-data-visualization-detect-outliers.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/boxplot-data-visualization-detect-outliers.png\" alt=\"Detect outliers using boxplot data visualization\" width=\"784\" height=\"334\" class=\"aligncenter size-full wp-image-12194\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/boxplot-data-visualization-detect-outliers.png 784w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/boxplot-data-visualization-detect-outliers-300x128.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/boxplot-data-visualization-detect-outliers-768x327.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/boxplot-data-visualization-detect-outliers-20x9.png 20w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a><\/p>\n<\/li>\n<li>Create scatter plots for each categorical variable against the target variable to determine the degree of correlation.<br \/>\nNotice that `TV` appears to have the highest degree of correlation.<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/scatter-plots-data-visualization-categorical-variable-correlation.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/scatter-plots-data-visualization-categorical-variable-correlation.png\" alt=\"Categorical variable correlation using scatter plots for data visualization\" width=\"784\" height=\"253\" class=\"aligncenter size-full wp-image-12209\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/scatter-plots-data-visualization-categorical-variable-correlation.png 784w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/scatter-plots-data-visualization-categorical-variable-correlation-300x97.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/scatter-plots-data-visualization-categorical-variable-correlation-768x248.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/scatter-plots-data-visualization-categorical-variable-correlation-20x6.png 20w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a><\/p>\n<\/li>\n<li>Split the dataset, using 60% of it for training and the remaining 40% for testing. We can now determine the value of coefficients in the regression equation, when the categorical variable is `TV` and the target variable is `Sales`, using the <a href=\"https:\/\/towardsdatascience.com\/understanding-the-ols-method-for-simple-linear-regression-e0a4e8f692cc\" rel=\"noopener\" target=\"_blank\">Ordinary Least Squares method<\/a>.<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/ordinary-least-squares-method-regression-testing.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/ordinary-least-squares-method-regression-testing.png\" alt=\"Ordinary Least Squares method for regression testing\" width=\"784\" height=\"393\" class=\"aligncenter size-full wp-image-12205\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/ordinary-least-squares-method-regression-testing.png 784w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/ordinary-least-squares-method-regression-testing-300x150.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/ordinary-least-squares-method-regression-testing-768x385.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/ordinary-least-squares-method-regression-testing-20x10.png 20w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a><\/p>\n<\/li>\n<li>Now train the model using the code you see here:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/training-data-jupyter-notebook.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/training-data-jupyter-notebook.png\" alt=\"Training data in a Jupyter notebook\" width=\"784\" height=\"298\" class=\"aligncenter size-full wp-image-12213\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/training-data-jupyter-notebook.png 784w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/training-data-jupyter-notebook-300x114.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/training-data-jupyter-notebook-768x292.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/training-data-jupyter-notebook-20x8.png 20w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/a><\/p>\n<\/li>\n<li>Next, substitute `test` for `train` to use the model to predict the test set\u2019s values, like this:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/testing-data-tv-variable-advertising-dataset.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/testing-data-tv-variable-advertising-dataset.png\" alt=\"Testing data for a TV variable in an advertising dataset\" width=\"791\" height=\"294\" class=\"aligncenter size-full wp-image-12212\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/testing-data-tv-variable-advertising-dataset.png 791w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/testing-data-tv-variable-advertising-dataset-300x112.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/testing-data-tv-variable-advertising-dataset-768x285.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/testing-data-tv-variable-advertising-dataset-20x7.png 20w\" sizes=\"auto, (max-width: 791px) 100vw, 791px\" \/><\/a><\/p>\n<\/li>\n<\/ol>\n<div class=\"wp-block-spacer\" style=\"height: 15px;\" aria-hidden=\"true\"> <\/div>\n<p>Using the same approach, we can train and test a model with the categorical variables `Radio` and `Newspaper`, as well:<br \/>\n<br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/training-data-radio-variable-linear-regression.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/training-data-radio-variable-linear-regression.png\" alt=\"Linear regression training data using a radio variable\" width=\"290\" height=\"195\" class=\"alignleft size-full wp-image-12214\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/training-data-radio-variable-linear-regression.png 290w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/training-data-radio-variable-linear-regression-20x13.png 20w\" sizes=\"auto, (max-width: 290px) 100vw, 290px\" \/><\/a><br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/testing-data-radio-variable-linear-regression.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/testing-data-radio-variable-linear-regression.png\" alt=\"Linear regression testing data using the radio variable\" width=\"297\" height=\"195\" class=\"alignright size-full wp-image-12211\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/testing-data-radio-variable-linear-regression.png 297w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/testing-data-radio-variable-linear-regression-20x13.png 20w\" sizes=\"auto, (max-width: 297px) 100vw, 297px\" \/><\/a><br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook-training-data-newspaper-couchbase.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook-training-data-newspaper-couchbase.png\" alt=\"Training data in a Jupyter Notebook from Couchbase (newspaper variable) \" width=\"279\" height=\"201\" class=\"alignleft size-full wp-image-12202\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-training-data-newspaper-couchbase.png 279w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-training-data-newspaper-couchbase-20x14.png 20w\" sizes=\"auto, (max-width: 279px) 100vw, 279px\" \/><\/a><br \/>\n<a href=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook-testing-data-newspaper-couchbase.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/10\/jupyter-notebook-testing-data-newspaper-couchbase.png\" alt=\"Testing data in a Jupyter Notebook from Couchbase (newspaper variable) \" width=\"297\" height=\"196\" class=\"alignright size-full wp-image-12201\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-testing-data-newspaper-couchbase.png 297w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-testing-data-newspaper-couchbase-20x13.png 20w\" sizes=\"auto, (max-width: 297px) 100vw, 297px\" \/><\/a><\/p>\n<h2>Going Further with Machine Learning &#038; Couchbase<\/h2>\n<p>Now that you\u2019ve gotten your feet wet with connecting <a href=\"https:\/\/www.couchbase.com\/products\/server\/?ref=blog\" rel=\"noopener\" target=\"_blank\">Couchbase Server<\/a> to Jupyter Notebook and explored the machine learning concept of linear regression, build on that knowledge with these posts on <a href=\"https:\/\/www.couchbase.com\/blog\/couchbase-machine-learning-model-store\/?ref=blog\" rel=\"noopener\" target=\"_blank\">how to use Couchbase as a machine learning model store<\/a> and <a href=\"https:\/\/www.couchbase.com\/blog\/enable-ai-driven-insights-using-couchbase-a-practical-framework?ref=blog\" rel=\"noopener\" target=\"_blank\">enabling AI-driven insights using Couchbase<\/a>.<\/p>\n<div class=\"wp-block-spacer\" style=\"height: 30px;\" aria-hidden=\"true\"> <\/div>\n<div style=\"text-align:center;\"><strong>Try it out for yourself:<br\/ ><br \/>\n<a href=\"https:\/\/www.couchbase.com\/downloads\/?ref=blog\" rel=\"noopener\" target=\"_blank\">Get Couchbase 7 here<\/a><\/strong><\/div>\n<div class=\"wp-block-spacer\" style=\"height: 15px;\" aria-hidden=\"true\"> <\/div>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Data scientists love Jupyter Notebooks \u2013 and it makes a natural pairing with the Couchbase document database. Why? The Jupyter Notebook web application lets you create and share documents that contain narrative text, equations and the like for use cases [&hellip;]<\/p>\n","protected":false},"author":79062,"featured_media":12191,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[10122,1815,2381,1816,9139],"tags":[2250,2312,2140],"ppma_author":[9457],"class_list":["post-12190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence-ai","category-best-practices-and-tutorials","category-community","category-couchbase-server","category-python","tag-data-visualization","tag-document-database","tag-machine-learning"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Training a Linear Regression Model with Couchbase &amp; a Jupyter Notebook: Step-by-Step Tutorial<\/title>\n<meta name=\"description\" content=\"Follow this step-by-step tutorial on training and testing a machine learning model for deep data insights using Jupyter Notebook and Couchbase Server.\" \/>\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\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Training a Linear Regression Model with Couchbase &amp; a Jupyter Notebook: Step-by-Step Tutorial\" \/>\n<meta property=\"og:description\" content=\"Follow this step-by-step tutorial on training and testing a machine learning model for deep data insights using Jupyter Notebook and Couchbase Server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-06T07:00:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:25:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial-social.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"418\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Agrima Khanna\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial-social.png\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Agrima Khanna\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/\"},\"author\":{\"name\":\"Agrima Khanna\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#\\\/schema\\\/person\\\/70424341a4f4d4236f120d7ea0488f00\"},\"headline\":\"Training a Linear Regression Model with Couchbase &#038; a Jupyter Notebook: Step-by-Step Tutorial\",\"datePublished\":\"2021-10-06T07:00:39+00:00\",\"dateModified\":\"2025-06-14T04:25:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/\"},\"wordCount\":773,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png\",\"keywords\":[\"data visualization\",\"document database\",\"Machine Learning (ML)\"],\"articleSection\":[\"Artificial Intelligence (AI)\",\"Best Practices and Tutorials\",\"Community\",\"Couchbase Server\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/\",\"name\":\"Training a Linear Regression Model with Couchbase & a Jupyter Notebook: Step-by-Step Tutorial\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png\",\"datePublished\":\"2021-10-06T07:00:39+00:00\",\"dateModified\":\"2025-06-14T04:25:12+00:00\",\"description\":\"Follow this step-by-step tutorial on training and testing a machine learning model for deep data insights using Jupyter Notebook and Couchbase Server.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png\",\"width\":1200,\"height\":628,\"caption\":\"Learn how to build a linear regression model using a Jupyter Notebook and Couchbase in this tutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/linear-regression-model-couchbase-jupyter-notebook-tutorial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Training a Linear Regression Model with Couchbase &#038; a Jupyter Notebook: Step-by-Step Tutorial\"}]},{\"@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\\\/70424341a4f4d4236f120d7ea0488f00\",\"name\":\"Agrima Khanna\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/agrima-khanna-couchbase-intern.png920ff5d3b8a4939dcc5036c29574367a\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/agrima-khanna-couchbase-intern.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/wp-content\\\/uploads\\\/sites\\\/1\\\/2021\\\/10\\\/agrima-khanna-couchbase-intern.png\",\"caption\":\"Agrima Khanna\"},\"url\":\"https:\\\/\\\/www.couchbase.com\\\/blog\\\/author\\\/agrima-khanna\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Training a Linear Regression Model with Couchbase & a Jupyter Notebook: Step-by-Step Tutorial","description":"Follow this step-by-step tutorial on training and testing a machine learning model for deep data insights using Jupyter Notebook and Couchbase Server.","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\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Training a Linear Regression Model with Couchbase & a Jupyter Notebook: Step-by-Step Tutorial","og_description":"Follow this step-by-step tutorial on training and testing a machine learning model for deep data insights using Jupyter Notebook and Couchbase Server.","og_url":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-10-06T07:00:39+00:00","article_modified_time":"2025-06-14T04:25:12+00:00","og_image":[{"width":800,"height":418,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial-social.png","type":"image\/png"}],"author":"Agrima Khanna","twitter_card":"summary_large_image","twitter_image":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial-social.png","twitter_misc":{"Written by":"Agrima Khanna","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/"},"author":{"name":"Agrima Khanna","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/70424341a4f4d4236f120d7ea0488f00"},"headline":"Training a Linear Regression Model with Couchbase &#038; a Jupyter Notebook: Step-by-Step Tutorial","datePublished":"2021-10-06T07:00:39+00:00","dateModified":"2025-06-14T04:25:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/"},"wordCount":773,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png","keywords":["data visualization","document database","Machine Learning (ML)"],"articleSection":["Artificial Intelligence (AI)","Best Practices and Tutorials","Community","Couchbase Server","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/","url":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/","name":"Training a Linear Regression Model with Couchbase & a Jupyter Notebook: Step-by-Step Tutorial","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png","datePublished":"2021-10-06T07:00:39+00:00","dateModified":"2025-06-14T04:25:12+00:00","description":"Follow this step-by-step tutorial on training and testing a machine learning model for deep data insights using Jupyter Notebook and Couchbase Server.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/jupyter-notebook-couchbase-linear-regression-model-tutorial.png","width":1200,"height":628,"caption":"Learn how to build a linear regression model using a Jupyter Notebook and Couchbase in this tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/linear-regression-model-couchbase-jupyter-notebook-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Training a Linear Regression Model with Couchbase &#038; a Jupyter Notebook: Step-by-Step Tutorial"}]},{"@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\/70424341a4f4d4236f120d7ea0488f00","name":"Agrima Khanna","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/agrima-khanna-couchbase-intern.png920ff5d3b8a4939dcc5036c29574367a","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/agrima-khanna-couchbase-intern.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/agrima-khanna-couchbase-intern.png","caption":"Agrima Khanna"},"url":"https:\/\/www.couchbase.com\/blog\/author\/agrima-khanna\/"}]}},"acf":[],"authors":[{"term_id":9457,"user_id":79062,"is_guest":0,"slug":"agrima-khanna","display_name":"Agrima Khanna","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/agrima-khanna-couchbase-intern.png","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/10\/agrima-khanna-couchbase-intern.png"},"0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/12190","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\/79062"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=12190"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/12190\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/12191"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=12190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=12190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=12190"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=12190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}