Happy birthday. Happy birthday. hello everyone today we are going to discuss about how we can check out in the stress level of any person if we have a data related to how a person is feeling okay so for example if there are people that are not feeling good or they say that we are not feeling well today or if they say that i fell into something or something like that then we'll know if whatever they are experiencing is related to stress or not so let's get it started the first thing is of course importing the libraries the first library is pandas so let's write import pandas as PD second one is numpy so let's write import numpy as NP after that I am going to bring in the data so which is available in a csv file called stress.csv so let me do that pd.read underscore csv and in this i'm going to write stress.csv so let me do that and let's run this now if we want we can also check out the data so this is the data as you can see this data has text id label confidence social stamp all of these things available with it and it is also telling us what was the problem in this for example this person had PTSD this person had assistance syndrome this person had a problem with relationships then survivor so we need to check out which of them are related to stress and which of them are not okay so the first thing that we need to do is we need to import an ltk because we are going to need some library of course to you know do our nlp work other than that we are going to clean the text with the help of re so the first thing first let's bring in the stop words from nltk so that we can use them downstream so let's write stop words here and after that let's make a stemmer so stemmer is equal to nltk dot we are going to use snowball stemmer and we are going to use the language english so snowball stemmer and in this i'm going to write english okay so let's run these and let's move forward there we go we have these packages up to date and now we are going to bring in the stop words and which will be available in nltk corpus so let's write from nltk dot corpus import star words ok and after that we are going to import string and later we are going to make a few star words so all the star words that are available in English anyways so star word is equal to set stop words dot words and in this I'm going to use the word English so let me write English here and let's do that okay so after that the next step is we are going to you know define a function to clean the text and I am just going to bring in that function so let me do that what are we doing in this function the first thing is we are making sure that everything is lowercase after that we are deleting these things then we are deleting HTML tags HTTPS things like that and after that we are going to delete these things as well and that's it and this is what is happening in this function okay so let's run this and after running this the next step is to you know bring in word cloud because we are going to use word cloud as well and for plotting we are going to use mat plotlib So let's write import matplotlib.pyplot as plt and after that let's write from word cloud import word cloud comma. comma, image color generator. So after bringing them in, what is the next step? The next step is to make a word cloud and plot it. So For that we have a very straightforward code in which we are going to bring in the data, data.text and then we are going to add the words. So these are all the words that are available in our data. Okay, so what is the next step? The next step is we can check out the label or we can just. see what the label is so let's give in a label right so for example if I say that there is a stress or not we are going to give that label so data label is equal to and in this I am going to map it with for example zero or no stress this one zero for no stress and this one for stress okay so if the value is zero there is no stress if the value is one then there is a stress so let's do that we are going to do a simple mapping for that so data label dot map and in this map i am going to tell it that zero is for no stress and one is for stress so So, let's write it in this and for 0 we say that exchange it with no stress and for 1 we say that exchange it with stress. So, this is the next step that we want to do. Okay, so after doing this labeling, we can just bring in two things now and write data is equal to them. Okay, so data is equal to data and in this we of course need only two things. One is text and the second one is label. One is text and the second one is label. okay so we can check out the data now this is the data that we have right now okay so later we can use this of course to make our predictions okay so the first thing that we need to do is we need to you know bring in the count vectorizer and train test split so counter tracer is available in skit learn as well as train test split so let me bring them up So, from sklearn.feature underscore extraction dot text import count vectorizer. Zero. okay and what is the second one the second one is train test split so for that I am going to write from sklearn dot model underscore selection import train underscore test underscore split so let's bring both of them in and let's give a value to x which is data of you know text so np dot array data and in this i am going to write text and after that I'm going to write y is equal to NP dot array and in this I'm going to write data and in this I'm going to write the second one which was label so let's do that and after that make a count vectorizer so CV is equal to count vectorizer and after that I am going to write X is equal to CV dot fit underscore transform and I'm going to give small x in this after that I'm going to perform the train test split so for that I'm going to write x train comma x test comma y train comma y test is equal to train underscore test underscore split x, y, test size so let's say that the test size is equal to 0.3 and let's say that the random state is on as well so random state is equal to 42 Let's run this and after that only a few more things are left and the last thing is we are going to bring in the Bernoulli transform in this. So from sklearn.naivebase which is of course another type of algorithm. So naivebase import Bernoulli transform.naivebase. nb and let's run this okay so yeah i was thinking that the spelling are not correct let me see it so it might be double l right here okay so after that we are going to make the model by writing model is equal to bernoulli nb you as a function okay so at the end I am going to perform the fitting so for that I am going to write model dot fit and here I am going to write X train comma Y train So, there we go, we have that and after that we can just make a prediction. So, for example, we can give a data and check what the model says. So, user is equal to let's input a data, a very simple data. Let's write text here only and let's run this. I am not feeling well okay so this is something that the user has said after that I am going to transform the data so data is equal to CV dot transform and in this I am going to write user to array so user whatever was written there to you array okay and after that i'm going to make the output so output is equal to model dot predict so model dot predict and in this i'm going to write the data and after that we can just print out the output and it says that there is no stress okay so other than that we can just put in things such as i had a trauma with my mom or my sister or something like that and check it out as well okay so this is how we develop a stress checking algorithm with the help of NLTK so for more videos like this keep watching AI sciences