Views
No views yet
1import pandas as pd
2import joblib
3from huggingface_hub import hf_hub_download
4from sklearn.feature_extraction.text import TfidfVectorizer
5from sklearn.metrics import classification_report
6
7# Mount to drive
8from google.colab import drive
9drive.mount('/content/drive')
10
11# Load test set
12test_df = pd.read_csv("/content/drive/MyDrive/test_data_random_subset.csv", encoding="Windows-1252")
13
14# Log in w/ huggingface token
15# Token can be found in repo as Token.docx
16!huggingface-cli login
17
18# Download the model
19model = hf_hub_download(repo_id = "CIS5190FinalProj/RandomForest", filename = "best_rf_model.pkl")
20
21# Download the vectorizer
22tfidf_vectorizer = hf_hub_download(repo_id = "CIS5190FinalProj/RandomForest", filename = "tfidf_vectorizer.pkl")
23
24# Load the model
25pipeline = joblib.load(model)
26
27# Load the vectorizer
28tfidf_vectorizer = joblib.load(tfidf_vectorizer)
29
30# Extract the headlines from the test set
31X_test = test_df['title']
32
33# Apply transformation to the headlines into numerical features
34X_test_transformed = tfidf_vectorizer.transform(X_test)
35
36# Make predictions using the pipeline
37y_pred = pipeline.predict(X_test_transformed)
38
39# Extract 'labels' as target
40y_test = test_df['label']
41
42# Print classification report
43print(classification_report(y_test, y_pred))