import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score, confusion_matrix, precision_score, recall_score

# Read the data
msg = pd.read_csv('document.csv', names=['message', 'label'])

# Check the number of instances
print("Total Instances of Dataset: ", msg.shape[0])

# Convert the labels to numbers
msg['labelnum'] = msg['label'].map({'pos': 1, 'neg': 0})

# Drop the rows with missing values in the target variable
msg = msg.dropna(axis=0, how='any', subset=['labelnum'])

# Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(msg['message'], msg['labelnum'], test_size=0.25)

# Create a CountVectorizer object
count_v = CountVectorizer()

# Fit the CountVectorizer object to the training data
count_v.fit(X_train)

# Transform the training and testing data
X_train_dm = count_v.transform(X_train)
X_test_dm = count_v.transform(X_test)

# Create an MLPClassifier object
clf = MLPClassifier(solver='lbfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1)

# Fit the MLPClassifier object to the training data
clf.fit(X_train_dm, y_train)

# Predict the labels for the testing data
pred = clf.predict(X_test_dm)

# Calculate the accuracy, recall, precision, and confusion matrix
accuracy = accuracy_score(y_test, pred)
recall = recall_score(y_test, pred)
precision = precision_score(y_test, pred)
confusion_matrix = confusion_matrix(y_test, pred)

# Print the results
print('Accuracy: ', accuracy)
print('Recall: ', recall)
print('Precision: ', precision)
print('Confusion Matrix: \n', confusion_matrix)


document.csv:-
I love this
sandwich,pos This
is an
amazingplace,pos
I feel very good about these
beers,pos This is my best
work,pos
What an awesome view,pos
I do not like this
restaurant,neg I am
tired of this stuff,neg
I can't deal with
this,neg He is
my sworn
enemy,neg My
boss is
horrible,neg
This is an awesome place,pos
I do not like the taste of
this juice,neg I love to
dance,pos
I am sick and tired of this
place,neg What a great
holiday,pos
That is a bad locality to stay,neg
We will have good fun
tomorrow,pos I went to my
enemy's house today,neg






output:-
Total Instances of Dataset: 28
Accuracy: 0.6666666666666666
Recall: 1.0
Precision: 0.6666666666666666
Confusion Matrix:
 [[0 1]
 [0 2]]