-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Comments
You can see this code
from sklearn.naive_bayes import GaussianNB
""" this is the code to accompany the Lesson 1 (Naive Bayes) mini-project
use a Naive Bayes Classifier to identify emails by their authors
authors and labels: Sara has label 0 Chris has label 1
"""
import sysfrom time import timesys.path.append("../tools/")from
email_preprocess import preprocess
### features_train and features_test are the features for the
training### and testing datasets, respectively### labels_train and
labels_test are the corresponding item labelsfeatures_train,
features_test, labels_train, labels_test = preprocess()
clf = GaussianNB()t0 = time()clf.fit(features_train,labels_train)print
'training time',round(time()-t0,3) ,'s't0 =
time()clf.score(features_test,labels_test)print 'predicting time',
round(time()-t0,3),'s'
في الأحد، ٦ نوفمبر ٢٠٢٢ ٩:١٠ ص HandyWorkZ ***@***.***> كتب:
… 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?
—
Reply to this email directly, view it on GitHub
<#361>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AWXGB6OI2U2LOKZ4PINLJSDWG5KV7ANCNFSM6AAAAAARYJJYIY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
For me the problem was that I executed the code in an IDE. Even though I ran 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
This is the code
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?
The text was updated successfully, but these errors were encountered: