0% found this document useful (0 votes)
3 views1 page

CLP 2

The document outlines a process for training a Naive Bayes classifier using a dataset of titles and their corresponding types. It involves data preprocessing, splitting the dataset into training and testing sets, vectorizing the text data, and fitting the classifier. Finally, it evaluates the model's performance using a classification report and accuracy score.

Uploaded by

Md Asaduzzaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

CLP 2

The document outlines a process for training a Naive Bayes classifier using a dataset of titles and their corresponding types. It involves data preprocessing, splitting the dataset into training and testing sets, vectorizing the text data, and fitting the classifier. Finally, it evaluates the model's performance using a classification report and accuracy score.

Uploaded by

Md Asaduzzaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import pandas as pd

from sklearn.model_selection import train_test_split


from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import classification_report, accuracy_score

file_path = 'dataset.csv' # Adjust the path as needed


dataset = pd.read_csv('/content/drive/MyDrive/dataset.csv')

dataset.rename(columns=lambda x: x.strip(), inplace=True)

X = dataset['Title']
y = dataset['Type']

X_train, X_test, y_train, y_test = train_test_split(X, y,


test_size=0.2, random_state=42)

vectorizer = CountVectorizer()
X_train_vec = vectorizer.fit_transform(X_train)
X_test_vec = vectorizer.transform(X_test)

nb_classifier = MultinomialNB()
nb_classifier.fit(X_train_vec, y_train)

y_pred = nb_classifier.predict(X_test_vec)

classification_results = classification_report(y_test, y_pred)


accuracy = accuracy_score(y_test, y_pred)

print("Classification Report:\n", classification_results)


print("Accuracy:", accuracy)

You might also like