{"id":81103,"date":"2021-06-14T12:44:32","date_gmt":"2021-06-14T07:14:32","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=81103"},"modified":"2026-06-03T15:22:17","modified_gmt":"2026-06-03T09:52:17","slug":"python-sentiment-analysis","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/","title":{"rendered":"Sentiment Analysis using Python [with source code]"},"content":{"rendered":"<p><strong>Sentiment Analysis<\/strong> &#8211; One of the most popular projects in the industry. Every customer facing industry (retail, telecom, finance, etc.) is interested in identifying their customers&#8217; sentiment, whether they think positive or negative about them.<\/p>\n<p>Python sentiment analysis is a methodology for analyzing a piece of text to discover the sentiment hidden within it. It accomplishes this by combining machine learning and natural language processing (NLP). Sentiment analysis allows you to examine the feelings expressed in a piece of text.<\/p>\n<h3>About Sentiment Analysis<\/h3>\n<p>In this machine learning project, we build a binary text classifier to classify the sentiment behind the text. We use the various NLP preprocessing techniques to clean the data and utilize the LSTM layers to build the text classifier.<\/p>\n<h3>Python Sentiment Analysis Dataset<\/h3>\n<p>The dataset contains more than 14000 tweets data samples classified into 3 types: positive, negative, neutral<\/p>\n<p>Please download the dataset for python sentiment analysis project: <a href=\"https:\/\/www.kaggle.com\/crowdflower\/twitter-airline-sentiment\"><strong>Project Dataset<\/strong><\/a><\/p>\n<h3>Tools and Libraries used<\/h3>\n<ul>\n<li>Python &#8211; 3.x<\/li>\n<li>Pandas &#8211; 1.2.4<\/li>\n<li>Matplotlib &#8211; 3.3.4<\/li>\n<li>TensorFlow &#8211; 2.4.1<\/li>\n<\/ul>\n<p>To install the above modules into your local machine, run the following command in your command line.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install pandas matplotlib tensorflow<\/pre>\n<h3>Download Sentiment Analysis Python Code<\/h3>\n<p>Please download the source code of python sentiment analysis project: <a href=\"https:\/\/drive.google.com\/file\/d\/17GOhXkCyjVg008yJwNeVYIkSPXqknGgn\/view?usp=drive_link\"><strong>Sentiment Analysis Project Code<\/strong><\/a><\/p>\n<h3>Sentiment Analysis with Python<\/h3>\n<p>To build a machine learning model to accurately classify whether customers are saying positive or negative<\/p>\n<h3>Steps to build Sentiment Analysis Text Classifier in Python<\/h3>\n<h4>1. Data Preprocessing<\/h4>\n<p>As we are dealing with the text data, we need to preprocess it using word embeddings.<\/p>\n<p>Let&#8217;s see what our data looks like.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import pandas as pd\r\ndf = pd.read_csv(\".\/DesktopDataFlair\/Sentiment-Analysis\/Tweets.csv\")<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/dataset-head.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81122\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/dataset-head.png\" alt=\"dataset head\" width=\"1263\" height=\"439\" \/><\/a><\/p>\n<p>We only need the text and sentiment column.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">review_df = df[['text','airline_sentiment']]\r\n\r\nprint(review_df.shape)\r\nreview_df.head(5)<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/dataset-head-sentiment-label.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81123\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/dataset-head-sentiment-label.png\" alt=\"dataset head sentiment label\" width=\"1263\" height=\"253\" \/><\/a><\/p>\n<p>There are more than 14,000 data samples in the sentiment analysis dataset.<\/p>\n<p>Let&#8217;s check the column names.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">df.columns<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/df-column-names.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81124\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/df-column-names.png\" alt=\"df column names\" width=\"1263\" height=\"141\" \/><\/a><\/p>\n<p>We don&#8217;t really need neutral reviews in our dataset for this binary classification problem. So, drop those rows from the dataset.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">review_df = review_df[review_df['airline_sentiment'] != 'neutral']\r\n\r\nprint(review_df.shape)\r\nreview_df.head(5)<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/filtered-data.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81125\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/filtered-data.png\" alt=\"filtered data\" width=\"1263\" height=\"258\" \/><\/a><\/p>\n<p>Check the values of the airline_sentiment column.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">review_df[\"airline_sentiment\"].value_counts()<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/sentiment-label-count.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81126\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/sentiment-label-count.png\" alt=\"sentiment label count\" width=\"1263\" height=\"157\" \/><\/a><\/p>\n<p>The labels for this dataset are categorical. Machines understand only numeric data. So, convert the categorical values to numeric using the factorize() method. This returns an array of numeric values and an Index of categories.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sentiment_label = review_df.airline_sentiment.factorize()\r\nsentiment_label<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/factorize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81127\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/factorize.png\" alt=\"factorize\" width=\"1263\" height=\"139\" \/><\/a><\/p>\n<p>If you observe, the 0 here represents positive sentiment and the 1 represents negative sentiment.<\/p>\n<p>Now, the major part in python sentiment analysis. We should transform our text data into something that our machine learning model understands. Basically, we need to convert the text into an array of vector embeddings. Word embeddings are a beautiful way of representing the relationship between the words in the text.<\/p>\n<p>To do this, we first give each of the unique words a unique number and then replace that word with the number assigned.<\/p>\n<p>First, retrieve all the text data from the dataset.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">tweet = review_df.text.values<\/pre>\n<p>Now, before proceeding ahead in python sentiment analysis project let&#8217;s tokenize all the words in the text with the help of Tokenizer. In tokenization, we break down all the words\/sentences of a text into small parts called tokens.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from tensorflow.keras.preprocessing.text import Tokenizer\r\n\r\ntokenizer = Tokenizer(num_words=5000)\r\n\r\ntokenizer.fit_on_texts(tweet)<\/pre>\n<p>The fit_on_texts() method creates an association between the words and the assigned numbers. This association is stored in the form of a dictionary in the tokenizer.word_index attribute.<\/p>\n<p>Now, replace the words with their assigned numbers using the text_to_sequence() method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">encoded_docs = tokenizer.texts_to_sequences(tweet)<\/pre>\n<p>Each of the sentences in the dataset is not of equal length. Use padding to pad the sentences to have equal length.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from tensorflow.keras.preprocessing.sequence import pad_sequences\r\n\r\npadded_sequence = pad_sequences(encoded_docs, maxlen=200)<\/pre>\n<h4>2. Build the Text Classifier<\/h4>\n<p>For sentiment analysis project, we use LSTM layers in the machine learning model. The architecture of our model consists of an embedding layer, an LSTM layer, and a Dense layer at the end. To avoid overfitting, we introduced the Dropout mechanism in-between the LSTM layers.<\/p>\n<p>LSTM stands for Long Short Term Memory Networks. It is a variant of Recurrent Neural Networks. Recurrent Neural Networks are usually used with sequential data such as text and audio. Usually, while computing an embedding matrix, the meaning of every word and its calculations (which are called hidden states) are stored. If the reference of a word, let&#8217;s say a word is used after 100 words in a text, then all these calculations RNNs cannot store in its memory. That&#8217;s why RNNs are not capable of learning these long-term dependencies.<\/p>\n<p>LSTMs on the other hand work well with such text. LSTM networks work well with time-series data.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/rnn-lstm.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81142\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/rnn-lstm.jpg\" alt=\"rnn lstm\" width=\"1500\" height=\"800\" \/><\/a><\/p>\n<p>Dropout is one of the regularization techniques. It is used to avoid overfitting. In the dropout mechanism, we drop some neurons randomly. The layer takes an argument, a number between 0 and 1 that represents the probability to drop the neurons. This creates a robust model avoiding overfitting.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from tensorflow.keras.models import Sequential\r\nfrom tensorflow.keras.layers import LSTM,Dense, Dropout, SpatialDropout1D\r\nfrom tensorflow.keras.layers import Embedding\r\n\r\n\r\nembedding_vector_length = 32\r\nmodel = Sequential()\r\nmodel.add(Embedding(vocab_size, embedding_vector_length, input_length=200))\r\nmodel.add(SpatialDropout1D(0.25))\r\nmodel.add(LSTM(50, dropout=0.5, recurrent_dropout=0.5))\r\nmodel.add(Dropout(0.2))\r\nmodel.add(Dense(1, activation='sigmoid'))\r\nmodel.compile(loss='binary_crossentropy',optimizer='adam', metrics=['accuracy'])\r\n\r\nprint(model.summary())<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/sentiment-model-summary.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81128\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/sentiment-model-summary.png\" alt=\"sentiment model summary\" width=\"1263\" height=\"415\" \/><\/a><\/p>\n<h4>3. Train the sentiment analysis model<\/h4>\n<p>Train the sentiment analysis model for 5 epochs on the whole dataset with a batch size of 32 and a validation split of 20%.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">history = model.fit(padded_sequence,sentiment_label[0],validation_split=0.2, epochs=5, batch_size=32)<\/pre>\n<p>The output while training looks like below:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/training-epochs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81129\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/training-epochs.png\" alt=\"training epochs\" width=\"1263\" height=\"334\" \/><\/a><\/p>\n<p>The python sentiment analysis model obtained 96% accuracy on the training set and 94.33% accuracy on the test set.<\/p>\n<p>Let&#8217;s plot these metrics using the matplotlib.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import matplotlib.pyplot as plt\r\n\r\nplt.plot(history.history['accuracy'], label='acc')\r\nplt.plot(history.history['val_accuracy'], label='val_acc')\r\nplt.legend()\r\nplt.show()\r\n\r\nplt.savefig(\"Accuracy plot.jpg\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/accuracy-plot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81130\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/accuracy-plot.png\" alt=\"accuracy plot\" width=\"1263\" height=\"324\" \/><\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">plt.plot(history.history['loss'], label='loss')\r\nplt.plot(history.history['val_loss'], label='val_loss')\r\n\r\nplt.legend()\r\nplt.show()\r\n\r\nplt.savefig(\"Loss plt.jpg\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/loss-plot.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81131\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/loss-plot.png\" alt=\"loss plot\" width=\"1263\" height=\"316\" \/><\/a><\/p>\n<h4>Let&#8217;s execute sentiment analysis model<\/h4>\n<p>Define a function that takes a text as input and outputs its prediction label.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def predict_sentiment(text):\r\n    tw = tokenizer.texts_to_sequences([text])\r\n    tw = pad_sequences(tw,maxlen=200)\r\n    prediction = int(model.predict(tw).round().item())\r\n    print(\"Predicted label: \", sentiment_label[1][prediction])\r\n\r\n\r\ntest_sentence1 = \"I enjoyed my journey on this flight.\"\r\npredict_sentiment(test_sentence1)\r\n\r\ntest_sentence2 = \"This is the worst flight experience of my life!\"\r\npredict_sentiment(test_sentence2)\r\n\r\n<\/pre>\n<h3>Python Sentiment Analysis Output<\/h3>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/python-sentiment-analysis-model-output-predictions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81132\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/06\/python-sentiment-analysis-model-output-predictions.png\" alt=\"python sentiment analysis model output predictions\" width=\"1263\" height=\"181\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>We have successfully developed python sentiment analysis model. In this machine learning project, we built a binary text classifier that classifies the sentiment of the tweets into positive and negative. We obtained more than 94% accuracy on validation.<\/p>\n<p>This is an interesting project which helps businesses across the domains to understand customers sentiment \/ feeling towards their brands.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sentiment Analysis &#8211; One of the most popular projects in the industry. Every customer facing industry (retail, telecom, finance, etc.) is interested in identifying their customers&#8217; sentiment, whether they think positive or negative about&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":81144,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[210],"tags":[203,3397,3588,3589,3590,3591,3592],"class_list":["post-81103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-machine-learning","tag-ml-project","tag-python-sentiment-analysis","tag-sentiment-analysis","tag-sentiment-analysis-in-python","tag-sentiment-analysis-ml","tag-sentiment-analysis-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sentiment Analysis using Python [with source code] - TechVidvan<\/title>\n<meta name=\"description\" content=\"Sentiment analysis project in python. Develop machine learning model with LSTM, Pandas and TensorFlow to classify customers&#039; sentiment as positive or negative\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/\" \/>\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 [with source code] - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Sentiment analysis project in python. Develop machine learning model with LSTM, Pandas and TensorFlow to classify customers&#039; sentiment as positive or negative\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-14T07:14:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-03T09:52:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/python-sentiment-analysis-machine-learning-project.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sentiment Analysis using Python [with source code] - TechVidvan","description":"Sentiment analysis project in python. Develop machine learning model with LSTM, Pandas and TensorFlow to classify customers' sentiment as positive or negative","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:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/","og_locale":"en_US","og_type":"article","og_title":"Sentiment Analysis using Python [with source code] - TechVidvan","og_description":"Sentiment analysis project in python. Develop machine learning model with LSTM, Pandas and TensorFlow to classify customers' sentiment as positive or negative","og_url":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-06-14T07:14:32+00:00","article_modified_time":"2026-06-03T09:52:17+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/python-sentiment-analysis-machine-learning-project.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Sentiment Analysis using Python [with source code]","datePublished":"2021-06-14T07:14:32+00:00","dateModified":"2026-06-03T09:52:17+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/"},"wordCount":899,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/python-sentiment-analysis-machine-learning-project.jpg","keywords":["machine learning","ML project","python sentiment analysis","sentiment analysis","sentiment analysis in python","sentiment analysis ml","Sentiment analysis project"],"articleSection":["Machine Learning Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/","url":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/","name":"Sentiment Analysis using Python [with source code] - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/python-sentiment-analysis-machine-learning-project.jpg","datePublished":"2021-06-14T07:14:32+00:00","dateModified":"2026-06-03T09:52:17+00:00","description":"Sentiment analysis project in python. Develop machine learning model with LSTM, Pandas and TensorFlow to classify customers' sentiment as positive or negative","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/python-sentiment-analysis-machine-learning-project.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/06\/python-sentiment-analysis-machine-learning-project.jpg","width":1200,"height":628,"caption":"python sentiment analysis machine learning project"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-sentiment-analysis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Sentiment Analysis using Python [with source code]"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":false,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=81103"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81103\/revisions"}],"predecessor-version":[{"id":448068,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/81103\/revisions\/448068"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/81144"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=81103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=81103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=81103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}