Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not found Error in Naïve Bayes Project #361

Open
handyworkz opened this issue Nov 6, 2022 · 3 comments
Open

File not found Error in Naïve Bayes Project #361

handyworkz opened this issue Nov 6, 2022 · 3 comments

Comments

@handyworkz
Copy link

This is the code

import sys
from time import time
sys.path.append("C:/Users/ADWIN/Documents/GitHub/ud120-projects/tools")
from email_preprocess import preprocess


features_train, features_test, labels_train, labels_test = preprocess()


from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
t0 =time()
clf.fit(features_train, labels_train)
print ("Training time: ", round(time()-t0, 3), "s")

t1 =time()
predictions = clf.predict(features_test)
print ("Prediction time: ", round(time()-t1, 3), "s")

from sklearn.metrics import accuracy_score
accuracy = accuracy_score(labels_test, predictions)
print(accuracy)

And this, the error

c:/Users/ADWIN/Documents/GitHub/ud120-projects/naive_bayes/nb_author_id.py Traceback (most recent call last): File "c:\Users\ADWIN\Documents\GitHub\ud120-projects\naive_bayes\nb_author_id.py", line 22, in <module> features_train, features_test, labels_train, labels_test = preprocess() File "C:\Users/ADWIN/Documents/GitHub/ud120-projects/tools\email_preprocess.py", line 30, in preprocess authors_file_handler = open(authors_file, "rb") FileNotFoundError: [Errno 2] No such file or directory: '../tools/email_authors.pkl'

Anytime I try to run the code, this error pops up, I have tried moving the email_preprocess file into the naive_bayes directory but the issue persists.

Can any one help?

@Badrgamalahmed
Copy link

Badrgamalahmed commented Nov 7, 2022 via email

@kleiner-fisch
Copy link

For me the problem was that I executed the code in an IDE. Even though I ran nb_author_id.py, the working directory was the root directory of the repository.

For me it worked by first doing

import os
os.chdir("naive_bayes")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@kleiner-fisch @Badrgamalahmed @handyworkz and others