Spaces:
Sleeping
Sleeping
Download export_model.py from dangminh214/Spam-Email-Classifier: direct link, hf CLI and curl.
- Browser
- Download file 679 Bytes
-
https://huggingface.co/spaces/dangminh214/Spam-Email-Classifier/resolve/main/export_model.py
- Command line
-
hf download hf://spaces/dangminh214/Spam-Email-Classifier/export_model.py
-
curl -L -o export_model.py https://huggingface.co/spaces/dangminh214/Spam-Email-Classifier/resolve/main/export_model.py
679 Bytes
| from model import SpamClassifier | |
| from sklearn.model_selection import train_test_split | |
| from test_email import emails | |
| if __name__ == "__main__": | |
| clf = SpamClassifier() | |
| df = clf.import_datasets() | |
| df = clf.preprocess(df) | |
| X = df['Message'] | |
| y = df['Category'] | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) | |
| clf.train(X_train, y_train) | |
| clf.evaluate(X_test, y_test) | |
| # Classifier Classes: "ham" "spam" | |
| for email in emails: | |
| print(f"Email: \"{email}\" => Prediction: {clf.predict(email)}") | |
| # Export model and vectorizer | |
| clf.export('spam_classifier_model.pkl', 'tfidf_vectorizer.pkl') | |