{"id":561,"date":"2023-07-10T16:17:56","date_gmt":"2023-07-10T16:17:56","guid":{"rendered":"https:\/\/www.w3computing.com\/articles\/?p=561"},"modified":"2023-08-23T16:21:20","modified_gmt":"2023-08-23T16:21:20","slug":"sentiment-analysis-using-python-ml","status":"publish","type":"post","link":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/","title":{"rendered":"Sentiment Analysis using Python and ML : Real-world Application"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Sentiment Analysis, often known as opinion mining, refers to the use of natural language processing, text analysis, and computational linguistics to identify and extract subjective information in source materials. Essentially, it involves determining the attitude, emotions, and opinions of the speaker or writer with respect to some topic or the overall contextual polarity of a document.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sentiment Analysis has grown in significance due to the increasing prevalence of user-generated content on the internet. It&#8217;s crucial for businesses and institutions that want to understand the public opinion towards their products, policies, or brand. By automating this process through machine learning, vast amounts of data can be analyzed swiftly, providing real-time insights and eliminating the need for manual inspection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python is one of the most popular programming languages in the world and is particularly popular among data scientists and machine learning practitioners. The reason for this is twofold. First, Python is relatively easy to learn and read, which makes it a great language for beginners and experienced developers alike. Second, Python has robust libraries like NLTK, Scikit-learn, Pandas, and Numpy that have been developed for data analysis and machine learning tasks, making it the language of choice for tasks like sentiment analysis.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Machine Learning, on the other hand, allows computers to learn and make decisions without being explicitly programmed. By training models on large datasets, machine learning can identify complex patterns and make accurate predictions. This is particularly useful for tasks like sentiment analysis where the rules are too complex to be manually programmed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will delve deeper into the field of sentiment analysis using Python and Machine Learning. We will explore fundamental concepts related to this field, setting up the Python environment for machine learning, gathering and preparing the data, building and evaluating our model, and finally, applying our model to solve real-world problems. Code examples will be provided at every step to ensure that this knowledge is not just theoretical but also practical. By the end of this article, you will have a working model that can be used to analyze sentiments from text data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding the Fundamentals<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Introduction to Natural Language Processing (NLP)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Natural Language Processing (NLP) is a branch of artificial intelligence that enables computers to understand, interpret, and generate human language. It combines computational linguistics\u2014rule-based modeling of human language\u2014with statistical, machine learning, and deep learning models. Together, these technologies enable machines to process human language in a valuable way. NLP is crucial for sentiment analysis, as it provides the tools necessary for machines to understand the subjective nuances in text data.<\/p>\n\n\n<pre class=\"wp-block-code lang-py\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-comment\"># Basic NLP example using NLTK in Python<\/span>\r\n<span class=\"hljs-keyword\">import<\/span> nltk\r\nnltk.download(<span class=\"hljs-string\">'punkt'<\/span>)\r\n<span class=\"hljs-keyword\">from<\/span> nltk.tokenize <span class=\"hljs-keyword\">import<\/span> word_tokenize\r\n\r\ntext = <span class=\"hljs-string\">\"Hello, welcome to the world of NLP\"<\/span>\r\nprint(word_tokenize(text))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Importance of Text Pre-Processing and Methods<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Text pre-processing is a crucial step in NLP and sentiment analysis. It involves cleaning and formatting the data before feeding it into a machine learning model. This includes techniques like:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>Lowercasing<\/em>: Converting all text to lowercase ensures that the algorithm does not treat the same words in different cases as different.<\/li>\n\n\n\n<li><em>Tokenization<\/em>: It breaks text into words, phrases, symbols, or other meaningful elements, which are called tokens.<\/li>\n\n\n\n<li><em>Stopword Removal<\/em>: Stopwords are common words that do not carry much meaningful information. Removing them decreases the dataset size and hence, increases processing speed.<\/li>\n\n\n\n<li><em>Stemming and Lemmatization<\/em>: These processes reduce words to their root form.<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> nltk.corpus <span class=\"hljs-keyword\">import<\/span> stopwords\r\n<span class=\"hljs-keyword\">from<\/span> nltk.stem <span class=\"hljs-keyword\">import<\/span> PorterStemmer\r\n\r\nnltk.download(<span class=\"hljs-string\">'stopwords'<\/span>)\r\n\r\nps = PorterStemmer()\r\nstop_words = set(stopwords.words(<span class=\"hljs-string\">'english'<\/span>))\r\n\r\nword_tokens = word_tokenize(text.lower())\r\nfiltered_text = &#91;ps.stem(word) <span class=\"hljs-keyword\">for<\/span> word <span class=\"hljs-keyword\">in<\/span> word_tokens <span class=\"hljs-keyword\">if<\/span> word <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-keyword\">in<\/span> stop_words]\r\n\r\nprint(filtered_text)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Introduction to Feature Extraction: Bag of Words and TF-IDF<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In machine learning, computers do not understand text, but numbers. Hence, we need to convert our text into a numerical format, a process known as feature extraction. Two popular methods are Bag of Words (BoW) and Term Frequency-Inverse Document Frequency (TF-IDF).<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Bag of Words<\/strong>: This model transforms text into the matrix of occurrence of words within a document. It focuses on whether given words occurred or not in the document, creating a &#8216;bag&#8217; of words.<\/li>\n\n\n\n<li><strong>TF-IDF<\/strong>: This method reflects how important a word is to a document in a corpus. It scales down the impact of words that occur very frequently and scales up the ones that occur rarely.<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> sklearn.feature_extraction.text <span class=\"hljs-keyword\">import<\/span> CountVectorizer, TfidfVectorizer\r\n\r\nvectorizer = CountVectorizer()\r\nX = vectorizer.fit_transform(filtered_text)\r\nprint(vectorizer.get_feature_names())\r\nprint(X.toarray())\r\n\r\ntfidf = TfidfVectorizer()\r\nY = tfidf.fit_transform(filtered_text)\r\nprint(tfidf.get_feature_names())\r\nprint(Y.toarray())<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Machine Learning Algorithms for Sentiment Analysis<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Various algorithms can be employed for sentiment analysis. Some popular choices include:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>Naive Bayes<\/em>: This is a probabilistic classifier that makes use of Bayes&#8217; Theorem, which assumes independence among predictors.<\/li>\n\n\n\n<li><em>Logistic Regression<\/em>: It models the probabilities for classification problems with two possible outcomes.<\/li>\n\n\n\n<li><em>Support Vector Machines<\/em>: SVMs are very effective when you have a huge number of features.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Each algorithm has its own advantages and disadvantages, and the choice of algorithm depends on the nature of the data and the problem at hand.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> sklearn.naive_bayes <span class=\"hljs-keyword\">import<\/span> MultinomialNB\r\n<span class=\"hljs-keyword\">from<\/span> sklearn.model_selection <span class=\"hljs-keyword\">import<\/span> train_test_split\r\n\r\n<span class=\"hljs-comment\"># Assuming Y to be the target variable<\/span>\r\nX_train, X_test, y_train, y_test = train_test_split(Y, Y, test_size=<span class=\"hljs-number\">0.2<\/span>, random_state=<span class=\"hljs-number\">42<\/span>)\r\n\r\nmodel = MultinomialNB().fit(X_train, y_train)\r\npredicted = model.predict(X_test)\r\nprint(predicted)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Setting Up Your Python Environment for Machine Learning<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Python Version Requirements<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To effectively carry out sentiment analysis using machine learning, Python 3.5 or later is recommended. This is because the latest versions of essential libraries often require newer Python versions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Necessary Libraries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python, being versatile and robust, has a plethora of libraries. However, for sentiment analysis using machine learning, the following libraries are critical:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>NLTK (Natural Language Toolkit)<\/em>: This is a leading platform for building Python programs to work with human language data.<\/li>\n\n\n\n<li><em>Scikit-learn<\/em>: A robust library for machine learning in Python. It provides simple and efficient tools for data mining and data analysis.<\/li>\n\n\n\n<li><em>Pandas<\/em>: For data manipulation and analysis.<\/li>\n\n\n\n<li><em>Numpy<\/em>: A fundamental package for scientific computing with Python.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Guide on How to Install These Libraries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can install these libraries using Python&#8217;s package installer pip. In your terminal, you would enter the following commands:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">pip install nltk\r\npip install scikit-learn\r\npip install pandas\r\npip install numpy<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;re using a Jupyter notebook, just put an exclamation mark before these commands:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">!pip install nltk\r\n!pip install scikit-learn\r\n!pip install pandas\r\n!pip install numpy<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Importing the Necessary Libraries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you have installed the necessary libraries, you can import them into your Python script as follows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> nltk\n<span class=\"hljs-keyword\">import<\/span> sklearn\n<span class=\"hljs-keyword\">import<\/span> pandas <span class=\"hljs-keyword\">as<\/span> pd\n<span class=\"hljs-keyword\">import<\/span> numpy <span class=\"hljs-keyword\">as<\/span> np<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">By importing these libraries, you now have the tools you need to build and analyze machine learning models for sentiment analysis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Gathering and Preparing the Data for Sentiment Analysis<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Sources of Datasets for Sentiment Analysis<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Datasets for sentiment analysis can come from various sources, often in the form of customer reviews, social media comments, and movie reviews. Some popular open-source sentiment analysis datasets include:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"http:\/\/ai.stanford.edu\/~amaas\/data\/sentiment\/\" target=\"_blank\" rel=\"noreferrer noopener\">IMDB movie reviews<\/a>: This is a dataset of 25,000 movies reviews from IMDB, labeled by sentiment (positive\/negative).<\/li>\n\n\n\n<li><a href=\"http:\/\/help.sentiment140.com\/for-students\/\" target=\"_blank\" rel=\"noreferrer noopener\">Twitter Sentiment Analysis Dataset<\/a>: This dataset contains 1.6 million labeled tweets for sentiment analysis.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.kaggle.com\/bittlingmayer\/amazonreviews\" target=\"_blank\" rel=\"noreferrer noopener\">Amazon Reviews for Sentiment Analysis<\/a>: This dataset consists of a few million Amazon customer reviews with star ratings to facilitate sentiment analysis tasks.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Preprocess the Data<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Preprocessing is the task of preparing your raw text data into an appropriate format for your sentiment analysis task. This usually involves:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cleaning<\/strong>: This is the process of removing unnecessary elements such as HTML tags, punctuation marks, special characters, or numbers from the text.<\/li>\n\n\n\n<li><strong>Normalization<\/strong>: It involves converting all characters in the text into lowercase, so that &#8216;word&#8217;, &#8216;Word&#8217;, and &#8216;WORD&#8217; are all considered the same.<\/li>\n\n\n\n<li><strong>Tokenization<\/strong>: This process involves breaking down the text into individual words or tokens.<\/li>\n\n\n\n<li><strong>Stemming<\/strong>: This process reduces the word to its stem or root form. For example, &#8216;running&#8217;, &#8216;runs&#8217;, &#8216;ran&#8217; are all different forms of the word &#8216;run&#8217;, and stemming would reduce all these to &#8216;run&#8217;.<\/li>\n\n\n\n<li><strong>Lemmatization<\/strong>: Similar to stemming, but lemmatization considers the context and converts the word to its meaningful base form, which is called Lemma. As a result, it is usually more accurate than stemming.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Preprocessing Operations<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a sample code that cleans, normalizes, tokenizes, and stems a text:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> nltk.corpus <span class=\"hljs-keyword\">import<\/span> stopwords\n<span class=\"hljs-keyword\">from<\/span> nltk.tokenize <span class=\"hljs-keyword\">import<\/span> word_tokenize\n<span class=\"hljs-keyword\">from<\/span> nltk.stem <span class=\"hljs-keyword\">import<\/span> PorterStemmer\n<span class=\"hljs-keyword\">import<\/span> re\n\nnltk.download(<span class=\"hljs-string\">'punkt'<\/span>)\nnltk.download(<span class=\"hljs-string\">'stopwords'<\/span>)\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">preprocess_text<\/span><span class=\"hljs-params\">(text)<\/span>:<\/span>\n    <span class=\"hljs-comment\"># Cleaning<\/span>\n    text = re.sub(<span class=\"hljs-string\">r'\\W'<\/span>, <span class=\"hljs-string\">' '<\/span>, text)\n    \n    <span class=\"hljs-comment\"># Normalization<\/span>\n    text = text.lower()\n    \n    <span class=\"hljs-comment\"># Tokenization<\/span>\n    word_tokens = word_tokenize(text)\n    \n    <span class=\"hljs-comment\"># Stopword Removal<\/span>\n    stop_words = set(stopwords.words(<span class=\"hljs-string\">'english'<\/span>))\n    word_tokens = &#91;word <span class=\"hljs-keyword\">for<\/span> word <span class=\"hljs-keyword\">in<\/span> word_tokens <span class=\"hljs-keyword\">if<\/span> word <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-keyword\">in<\/span> stop_words]\n    \n    <span class=\"hljs-comment\"># Stemming<\/span>\n    ps = PorterStemmer()\n    word_tokens = &#91;ps.stem(word) <span class=\"hljs-keyword\">for<\/span> word <span class=\"hljs-keyword\">in<\/span> word_tokens]\n    \n    <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">' '<\/span>.join(word_tokens)\n\ntext = <span class=\"hljs-string\">\"Here is an example text to show the preprocessing steps\"<\/span>\nprint(preprocess_text(text))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Remember, preprocessing steps might vary according to the requirements of your task. The above steps provide a good starting point for preparing text data for sentiment analysis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building Your Sentiment Analysis Model<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Steps to Train a Machine Learning Model for Sentiment Analysis<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once the data has been preprocessed and properly formatted, the next step is to feed it into a machine learning algorithm to create a sentiment analysis model. Here are the general steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>Splitting the dataset<\/em>: First, you need to split your dataset into a training set and a test set. The training set will be used to train the model, and the test set will be used to evaluate its performance.<\/li>\n\n\n\n<li><em>Vectorization<\/em>: After splitting the data, you&#8217;ll need to convert your text data into numerical form using techniques like Bag of Words or TF-IDF.<\/li>\n\n\n\n<li><em>Model Training<\/em>: Feed the training data into a machine learning algorithm (like Logistic Regression or Naive Bayes).<\/li>\n\n\n\n<li><em>Prediction<\/em>: Use the trained model to predict the sentiment of the test data.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Introduction to Parameter Tuning and How to Avoid Overfitting<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In machine learning, parameter tuning involves adjusting the parameters of a model to improve its accuracy. Too many parameters can lead to overfitting, where the model performs very well on the training data but poorly on new, unseen data. Techniques like cross-validation, regularization, and early stopping can be used to prevent overfitting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Training the Model and Parameter Tuning<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a simple example of how to train a model using logistic regression and perform parameter tuning:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> sklearn.model_selection <span class=\"hljs-keyword\">import<\/span> train_test_split\n<span class=\"hljs-keyword\">from<\/span> sklearn.feature_extraction.text <span class=\"hljs-keyword\">import<\/span> TfidfVectorizer\n<span class=\"hljs-keyword\">from<\/span> sklearn.linear_model <span class=\"hljs-keyword\">import<\/span> LogisticRegression\n<span class=\"hljs-keyword\">from<\/span> sklearn.metrics <span class=\"hljs-keyword\">import<\/span> accuracy_score\n<span class=\"hljs-keyword\">from<\/span> sklearn.model_selection <span class=\"hljs-keyword\">import<\/span> GridSearchCV\n\n<span class=\"hljs-comment\"># Assuming `reviews` is your preprocessed text data and `labels` are the sentiments<\/span>\nX_train, X_test, y_train, y_test = train_test_split(reviews, labels, test_size=<span class=\"hljs-number\">0.2<\/span>, random_state=<span class=\"hljs-number\">42<\/span>)\n\n<span class=\"hljs-comment\"># Convert text data into TF-IDF vectors<\/span>\nvectorizer = TfidfVectorizer()\nX_train = vectorizer.fit_transform(X_train)\nX_test = vectorizer.transform(X_test)\n\n<span class=\"hljs-comment\"># Create a Logistic Regression model<\/span>\nlr = LogisticRegression()\n\n<span class=\"hljs-comment\"># Define the parameter values that should be searched<\/span>\nparam_grid = {<span class=\"hljs-string\">'C'<\/span>: &#91;<span class=\"hljs-number\">0.001<\/span>, <span class=\"hljs-number\">0.01<\/span>, <span class=\"hljs-number\">0.1<\/span>, <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">100<\/span>, <span class=\"hljs-number\">1000<\/span>] }\n\n<span class=\"hljs-comment\"># Instantiate the grid<\/span>\ngrid = GridSearchCV(lr, param_grid, cv=<span class=\"hljs-number\">10<\/span>, scoring=<span class=\"hljs-string\">'accuracy'<\/span>)\n\n<span class=\"hljs-comment\"># Fit the grid with data<\/span>\ngrid.fit(X_train, y_train)\n\n<span class=\"hljs-comment\"># View the best parameters<\/span>\nprint(<span class=\"hljs-string\">\"Best parameters: \"<\/span>, grid.best_params_)\n\n<span class=\"hljs-comment\"># Predict the sentiment for test data<\/span>\ny_pred = grid.predict(X_test)\n\n<span class=\"hljs-comment\"># Print the accuracy of the model<\/span>\nprint(<span class=\"hljs-string\">\"Accuracy: \"<\/span>, accuracy_score(y_test, y_pred))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">How to Interpret the Model Output<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The output of a sentiment analysis model is usually a polarity score or a class label indicating the sentiment. In binary sentiment analysis, the output is either positive or negative. In multi-class sentiment analysis, the output could be positive, negative, or neutral. In the case of a regression model, the output could be a continuous value ranging from extremely negative to extremely positive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The performance of the model can be evaluated using metrics like accuracy, precision, recall, F1-score, or Area Under the ROC Curve (AUC-ROC).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Evaluating the Sentiment Analysis Model<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Using a Validation Set to Evaluate the Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">After training the model, it&#8217;s important to evaluate its performance on a separate validation set that the model hasn&#8217;t seen during training. This helps ensure that the model is able to generalize well to unseen data, and it gives a good indication of how the model will perform when deployed in the real world.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation of Evaluation Metrics: Accuracy, Precision, Recall, F1-score<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>Accuracy<\/em>: This is the most intuitive performance measure. It&#8217;s the ratio of the number of correct predictions to the total number of predictions.<\/li>\n\n\n\n<li><em>Precision<\/em>: Precision is the ratio of correctly predicted positive observations to the total predicted positive observations. High precision relates to the low false positive rate.<\/li>\n\n\n\n<li><em>Recall (Sensitivity)<\/em>: This is the ratio of correctly predicted positive observations to all actual positives.<\/li>\n\n\n\n<li><em>F1-score<\/em>: The F1 score is the weighted average of Precision and Recall. It tries to find the balance between precision and recall.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Calculating Evaluation Metrics<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s how you can calculate these metrics using Python&#8217;s <code><strong>scikit-learn<\/strong><\/code> library:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\n\n<span class=\"hljs-comment\"># Assuming `y_test` are the true labels and `y_pred` are the predicted labels<\/span>\naccuracy = accuracy_score(y_test, y_pred)\nprecision = precision_score(y_test, y_pred, average=<span class=\"hljs-string\">'weighted'<\/span>)\nrecall = recall_score(y_test, y_pred, average=<span class=\"hljs-string\">'weighted'<\/span>)\nf1 = f1_score(y_test, y_pred, average=<span class=\"hljs-string\">'weighted'<\/span>)\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">'Accuracy: '<\/span>, accuracy)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">'Precision: '<\/span>, precision)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">'Recall: '<\/span>, recall)\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">'F1 score: '<\/span>, f1)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this code snippet, we use <code><strong>average='weighted'<\/strong><\/code> to calculate metrics for multi-class classification tasks. It accounts for class imbalance by computing the average of binary metrics in which each class\u2019s score is weighted by its presence in the true data sample.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Applying Your Sentiment Analysis Model to Real-world Problems<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Examples of Real-world Applications of Sentiment Analysis<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Sentiment analysis has a wide range of applications across various domains:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>Customer Sentiment Analysis<\/em>: Businesses can use sentiment analysis to understand customer feedback on their products or services and use this to improve customer experience.<\/li>\n\n\n\n<li><em>Social Media Monitoring<\/em>: Sentiment analysis can be used to track public opinion about different topics over time, which can be beneficial for marketing, political campaigns, and more.<\/li>\n\n\n\n<li><em>Market Research and Analysis<\/em>: Companies can use sentiment analysis to study market trends, evaluate consumer opinions on different products, and understand the impact of marketing strategies.<\/li>\n\n\n\n<li><em>Healthcare<\/em>: Sentiment analysis can be used to understand patient feedback about treatments, doctors, and health services, which can aid in improving healthcare service delivery.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Making Predictions with the Trained Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once your model is trained, you can use it to predict the sentiment of new, unseen text data. Here&#8217;s a simple example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Let's assume you have a new review<\/span>\nnew_review = <span class=\"hljs-string\">\"This product is really amazing!\"<\/span>\n\n<span class=\"hljs-comment\"># Remember to apply the same preprocessing steps to your new review<\/span>\nprocessed_review = preprocess_text(new_review)\n\n<span class=\"hljs-comment\"># Vectorize the review<\/span>\nreview_vector = vectorizer.transform(&#91;processed_review])\n\n<span class=\"hljs-comment\"># Use the trained model to predict the sentiment<\/span>\npredicted_sentiment = grid.predict(review_vector)\n\n<span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"The predicted sentiment is: \"<\/span>, predicted_sentiment&#91;<span class=\"hljs-number\">0<\/span>])<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">In this example, we&#8217;re predicting the sentiment of a new review using the trained model. The <code><strong>preprocess_text<\/strong><\/code> function is the same one we defined earlier for preprocessing the training data. This ensures that the new review is preprocessed in the same way as the training data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sentiment analysis plays a crucial role in many business applications and has been increasingly adopted in various domains such as marketing, politics, healthcare, and more. Being proficient in sentiment analysis techniques not only expands your data science toolkit but also gives you a solid footing to solve real-world problems effectively. With the advancements in AI and Machine Learning, the future of sentiment analysis is undoubtedly promising, with vast possibilities for newer applications and improvements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sentiment Analysis, often known as opinion mining, refers to the use of natural language processing, text analysis, and computational linguistics to identify and extract subjective information in source materials. Essentially, it involves determining the attitude, emotions, and opinions of the speaker or writer with respect to some topic or the overall contextual polarity of a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[4,6],"tags":[],"class_list":["post-561","post","type-post","status-publish","format-standard","category-programming-languages","category-python","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sentiment Analysis using Python and ML : Real-world Application<\/title>\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.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sentiment Analysis using Python and ML : Real-world Application\" \/>\n<meta property=\"og:description\" content=\"Sentiment Analysis, often known as opinion mining, refers to the use of natural language processing, text analysis, and computational linguistics to identify and extract subjective information in source materials. Essentially, it involves determining the attitude, emotions, and opinions of the speaker or writer with respect to some topic or the overall contextual polarity of a [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-10T16:17:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-23T16:21:20+00:00\" \/>\n<meta name=\"author\" content=\"w3compadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"w3compadmin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/\"},\"author\":{\"name\":\"w3compadmin\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"headline\":\"Sentiment Analysis using Python and ML : Real-world Application\",\"datePublished\":\"2023-07-10T16:17:56+00:00\",\"dateModified\":\"2023-08-23T16:21:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/\"},\"wordCount\":2057,\"commentCount\":0,\"articleSection\":[\"Programming Languages\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/\",\"name\":\"Sentiment Analysis using Python and ML : Real-world Application\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\"},\"datePublished\":\"2023-07-10T16:17:56+00:00\",\"dateModified\":\"2023-08-23T16:21:20+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/sentiment-analysis-using-python-ml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Articles Home\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programming Languages\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/programming-languages\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python\",\"item\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/programming-languages\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Sentiment Analysis using Python and ML : Real-world Application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/\",\"name\":\"Developer Articles Hub\",\"description\":\"\",\"alternateName\":\"Developer Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/#\\\/schema\\\/person\\\/a550b3e20d78bb4f79b7c6b7b53f0561\",\"name\":\"w3compadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1781957457\",\"url\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1781957457\",\"contentUrl\":\"https:\\\/\\\/www.w3computing.com\\\/articles\\\/wp-content\\\/litespeed\\\/avatar\\\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1781957457\",\"caption\":\"w3compadmin\"},\"sameAs\":[\"http:\\\/\\\/w3computing.com\\\/articles\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sentiment Analysis using Python and ML : Real-world Application","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.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/","og_locale":"en_US","og_type":"article","og_title":"Sentiment Analysis using Python and ML : Real-world Application","og_description":"Sentiment Analysis, often known as opinion mining, refers to the use of natural language processing, text analysis, and computational linguistics to identify and extract subjective information in source materials. Essentially, it involves determining the attitude, emotions, and opinions of the speaker or writer with respect to some topic or the overall contextual polarity of a [&hellip;]","og_url":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/","article_published_time":"2023-07-10T16:17:56+00:00","article_modified_time":"2023-08-23T16:21:20+00:00","author":"w3compadmin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"w3compadmin","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/#article","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/"},"author":{"name":"w3compadmin","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"headline":"Sentiment Analysis using Python and ML : Real-world Application","datePublished":"2023-07-10T16:17:56+00:00","dateModified":"2023-08-23T16:21:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/"},"wordCount":2057,"commentCount":0,"articleSection":["Programming Languages","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/","url":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/","name":"Sentiment Analysis using Python and ML : Real-world Application","isPartOf":{"@id":"https:\/\/www.w3computing.com\/articles\/#website"},"datePublished":"2023-07-10T16:17:56+00:00","dateModified":"2023-08-23T16:21:20+00:00","author":{"@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561"},"breadcrumb":{"@id":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.w3computing.com\/articles\/sentiment-analysis-using-python-ml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Articles Home","item":"https:\/\/www.w3computing.com\/articles\/"},{"@type":"ListItem","position":2,"name":"Programming Languages","item":"https:\/\/www.w3computing.com\/articles\/programming-languages\/"},{"@type":"ListItem","position":3,"name":"Python","item":"https:\/\/www.w3computing.com\/articles\/programming-languages\/python\/"},{"@type":"ListItem","position":4,"name":"Sentiment Analysis using Python and ML : Real-world Application"}]},{"@type":"WebSite","@id":"https:\/\/www.w3computing.com\/articles\/#website","url":"https:\/\/www.w3computing.com\/articles\/","name":"Developer Articles Hub","description":"","alternateName":"Developer Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.w3computing.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.w3computing.com\/articles\/#\/schema\/person\/a550b3e20d78bb4f79b7c6b7b53f0561","name":"w3compadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1781957457","url":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1781957457","contentUrl":"https:\/\/www.w3computing.com\/articles\/wp-content\/litespeed\/avatar\/bd481d404e42caa2763662a3bfe825f8.jpg?ver=1781957457","caption":"w3compadmin"},"sameAs":["http:\/\/w3computing.com\/articles"]}]}},"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"w3compadmin","author_link":"https:\/\/www.w3computing.com\/articles\/author\/w3compadmin\/"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/561","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/comments?post=561"}],"version-history":[{"count":14,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/561\/revisions"}],"predecessor-version":[{"id":575,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/posts\/561\/revisions\/575"}],"wp:attachment":[{"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/media?parent=561"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/categories?post=561"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.w3computing.com\/articles\/wp-json\/wp\/v2\/tags?post=561"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}