Open himanshujosfi opened 1 year ago
import pickle mnb.fit(X_train,y_train) y_pred2 = mnb.predict(X_test) pickle.dump(tfidf,open('vectorizer.pkl','wb')) pickle.dump(mnb,open('model.pkl','wb'))
"Use this with dum and create its work"
File "/Users/anushka/anaconda3/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
exec(code, module.dict)
File "/Users/anushka/PycharmProjects/mail/main.py", line 49, in
# importing vectorizer from sklearn.feature_extraction.text import TfidfVectorizer tf_idf = TfidfVectorizer(max_features=3500)
# create vectors of transformed text feature and then stored it in x variable x = tf_idf.fit_transform(df["transformed_text"]).toarray() y = df["target"].values
# now try to train MultinomialNB(), it will work from sklearn.naive_bayes import MultinomialNB model = MultinomialNB() model.fit(x_train, y_train) y_pred = model.predict(x_test) print(accuracy_score(y_test, y_pred)) print(precision_score(y_test, y_pred))
Hope you understand
how to resolve not fitted error for the Spam classifier Project?? Anyone can please help me
Exact what error u are facing Please share
On Mon, 15 Apr 2024 at 6:13 PM, Priti Samse(Government college of Enginnering,Aurangabad) @.***> wrote:
how to resolve not fitted error for the Spam classifier Project?? Anyone can please help me
— Reply to this email directly, view it on GitHub https://github.com/campusx-official/sms-spam-classifier/issues/7#issuecomment-2056764279, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVCE43EAVYPPZHC2ZIAEN3DY5PDOZAVCNFSM6AAAAAAZH2RZQSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJWG43DIMRXHE . You are receiving this because you modified the open/close state.Message ID: @.***>
File Load Error for model.pkl C:\Users\DELL\OneDrive\Desktop\numpy project\model.pkl is not UTF-8 encoded
this happen for both the files i.e. vectorizer.pkl and model.pkl
NotFittedError: The TF-IDF vectorizer is not fitted Traceback:
File "C:\Users\DELL\PycharmProjects\SMS Spam Project\venv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 542, in _run_script
exec(code, module.dict)
File "C:\Users\DELL\PycharmProjects\SMS Spam Project\app.py", line 42, in
and this is the error after streamlit running
import pandas as pd import joblib from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.svm import SVC from sklearn.naive_bayes import MultinomialNB from sklearn.ensemble import ExtraTreesClassifier, VotingClassifier from sklearn.model_selection import train_test_split
data = pd.read_csv('spam.csv', encoding='latin-1') data = data[['v1', 'v2']] data.columns = ['label', 'text'] data['label'] = data['label'].map({'ham': 0, 'spam': 1})
x_train, x_test, y_train, y_test = train_test_split(data['text'], data['label'], test_size=0.2, random_state=42)
tfidf_vectorizer = TfidfVectorizer(max_features=3500) x_train_tfidf = tfidf_vectorizer.fit_transform(x_train)
svc = SVC(kernel='sigmoid', gamma=1.0, probability=True) mnb = MultinomialNB() etc = ExtraTreesClassifier(n_estimators=50, random_state=2)
voting = VotingClassifier(estimators=[('svm', svc), ('nb', mnb), ('et', etc)], voting='soft') voting.fit(x_train_tfidf, y_train)
joblib.dump(voting, 'spam_classifier.pkl') joblib.dump(tfidf_vectorizer, 'tfidf_vectorizer.pkl')
I've used joblib instead of pickle and it worked. Hope it works for you.
Can you plz help how to sole this problem "NotFittedError: This MultinomialNB instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator." plz respond