Model training, Evaluation, and Prediction

Once analysis and vectorization is done. We can now explore any machine learning model to train the data. But before that perform the train-test split.

Python3




from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, data['label'],
                                                    test_size=0.33,
                                                    stratify=data['label'],
                                                    random_state = 42)


Now we can train any model, Let’s explore the Decision Tree for the prediction.

Python3




from sklearn.tree import DecisionTreeClassifier
  
model = DecisionTreeClassifier(random_state=0)
model.fit(X_train,y_train)
  
#testing the model
pred = model.predict(X_train)
print(accuracy_score(y_train,pred))


Output :

0.9244351339218914

Let’s see the confusion matrix for the results.

Python3




from sklearn import metrics
cm = confusion_matrix(y_train,pred)
  
cm_display = metrics.ConfusionMatrixDisplay(confusion_matrix = cm, 
                                            display_labels = [False, True])
  
cm_display.plot()
plt.show()


Output : 

 

Flipkart Reviews Sentiment Analysis using Python

This article is based on the analysis of the reviews and ratings user gives on Flipkart to make others aware of their experience and moreover about the quality of the product and brand. So, by analyzing that data we can tell the users a lot about the products and also the ways to enhance the quality of the product. 

Today we will be using Machine Learning to analyze that data and make it more efficient to understand and prediction ready.

Our task is to predict whether the review given is positive or negative.

Before starting the code, download the dataset by clicking this link.

Similar Reads

Importing Libraries and Datasets

The libraries used are :...

Preprocessing and cleaning the reviews

...

Analysis of the Dataset

...

Converting text into Vectors

...

Model training, Evaluation, and Prediction

As, the real data is multi-labelled, so firstly explore those labels then we will convert them into 2 classes....

Conclusion

...

Contact Us