forked from Achyuta0/Emotion-Detection-using-ML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
24 lines (18 loc) · 702 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pandas as pd
import pickle
from sklearn.metrics import accuracy_score
from sklearn.feature_extraction.text import TfidfVectorizer
# Load the test data from the CSV file
test_data = pd.read_csv('./dataset/test.csv')
# Load the trained model and vectorizer
with open('model.pkl', 'rb') as model_file:
model = pickle.load(model_file)
with open('vectorizer.pkl', 'rb') as vectorizer_file:
vectorizer = pickle.load(vectorizer_file)
# Preprocess the test data
X_test = vectorizer.transform(test_data['text'])
# Predict using the model
y_pred = model.predict(X_test)
# Evaluate the model
test_accuracy = accuracy_score(test_data['label'], y_pred)
print(f"Test accuracy: {test_accuracy}")