{"id":5875,"date":"2020-03-24T17:41:26","date_gmt":"2020-03-24T13:11:26","guid":{"rendered":"https:\/\/shahaab-co.ir\/mag\/?p=5875"},"modified":"2025-12-23T19:31:16","modified_gmt":"2025-12-23T16:01:16","slug":"supervised-learning-and-naive-bayes-classification-part-2-coding","status":"publish","type":"post","link":"https:\/\/shahaab-co.com\/mag\/edu\/ml\/supervised-learning-and-naive-bayes-classification-part-2-coding\/","title":{"rendered":"\u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0646\u0638\u0627\u0631\u062a \u0634\u062f\u0647 \u0648 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u2013 \u0628\u062e\u0634 \u062f\u0648\u0645 : \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc"},"content":{"rendered":"<p style=\"text-align: justify;\"><strong>\u062a\u0648\u062c\u0647<\/strong> : \u0627\u06af\u0631 \u0628\u062e\u0634 \u0627\u0648\u0644 \u06cc\u0639\u0646\u06cc \u0646\u0638\u0631\u06cc\u0647 \u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u0631\u0627 \u0645\u0637\u0627\u0644\u0639\u0647 \u0646\u06a9\u0631\u062f\u0647 \u0627\u06cc\u062f\u060c \u0628\u0647 \u0634\u0645\u0627 \u067e\u06cc\u0634\u0646\u0647\u0627\u062f \u0645\u06cc \u200c\u06a9\u0646\u06cc\u0645 \u06a9\u0647 <a href=\"https:\/\/shahaab-co.ir\/mag\/edu\/ml\/supervised-learning-and-naive-bayes-classification-part-1-theory\/\" target=\"_blank\" rel=\"noopener\">\u0622\u0646 \u0631\u0627 \u0645\u0637\u0627\u0644\u0639\u0647 \u06a9\u0646\u06cc\u062f<\/a>.<\/p>\n<div class=\"clear\"><\/div><div style=\"margin-top:20px; margin-bottom:20px;\" class=\"divider divider-normal\"><\/div>\n<p><strong>\u0645\u0642\u0627\u0644\u0647 \u0645\u0631\u062a\u0628\u0637 :<\/strong><\/p>\n<ul>\n<li><strong><a href=\"https:\/\/shahaab-co.ir\/mag\/edu\/ml\/supervised-learning-and-naive-bayes-classification-part-1-theory\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0646\u0638\u0627\u0631\u062a \u0634\u062f\u0647 \u0648 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u2013 \u0628\u062e\u0634 \u0627\u0648\u0644 : \u0646\u0638\u0631\u06cc\u0647<\/a><\/strong><\/li>\n<li><strong><a href=\"https:\/\/shahaab-co.ir\/mag\/edu\/ml\/supervised-learning-and-naive-bayes-classification-part-2-coding\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0646\u0638\u0627\u0631\u062a \u0634\u062f\u0647 \u0648 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u2013 \u0628\u062e\u0634 \u062f\u0648\u0645 : \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc<\/a><\/strong><\/li>\n<li><strong><a href=\"https:\/\/shahaab-co.ir\/mag\/edu\/support-vector-machine-part1-theory\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u0645\u0627\u0634\u06cc\u0646 \u0628\u0631\u062f\u0627\u0631 \u067e\u0634\u062a\u06cc\u0628\u0627\u0646 ( SVM ) \u2013 \u0628\u062e\u0634 \u0627\u0648\u0644 : \u0646\u0638\u0631\u06cc\u0647<\/a><\/strong><\/li>\n<li><strong><a href=\"https:\/\/shahaab-co.ir\/mag\/edu\/ml\/support-vector-machine-part2-coding\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u0645\u0627\u0634\u06cc\u0646 \u0628\u0631\u062f\u0627\u0631 \u067e\u0634\u062a\u06cc\u0628\u0627\u0646 ( SVM ) \u2013 \u0628\u062e\u0634 \u062f\u0648\u0645 : \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc<\/a><\/strong><\/li>\n<\/ul>\n<div class=\"clear\"><\/div><div style=\"margin-top:20px; margin-bottom:20px;\" class=\"divider divider-normal\"><\/div>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0627\u06cc\u0646 \u0642\u0633\u0645\u062a \u0645\u0627 \u06a9\u062a\u0627\u0628\u062e\u0627\u0646\u0647 sklearn \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u062e\u0648\u0627\u0647\u06cc\u0645 \u06a9\u0631\u062f. sklearn \u062f\u0631 \u067e\u0627\u06cc\u062a\u0648\u0646 \u0627\u0645\u06a9\u0627\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u0647\u0627\u06cc <a href=\"https:\/\/shahaab-co.ir\/mag\/tag\/%db%8c%d8%a7%d8%af%da%af%db%8c%d8%b1%db%8c-%d9%85%d8%a7%d8%b4%db%8c%d9%86\/\" target=\"_blank\" rel=\"noopener\">\u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0645\u0627\u0634\u06cc\u0646<\/a> \u0639\u0645\u0648\u0645\u06cc \u0645\u0627\u0646\u0646\u062f \u00a0\u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u0631\u0627 \u0641\u0631\u0627\u0647\u0645 \u0645\u06cc \u06a9\u0646\u062f. ( \u0647\u0645\u0686\u0646\u06cc\u0646 \u0634\u0627\u0645\u0644 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u0647\u0627\u06cc \u062f\u06cc\u06af\u0631 \u0645\u0627\u0646\u0646\u062f SVM \u0646\u06cc\u0632 \u0647\u0633\u062a \u2026 \u06a9\u0647 \u0628\u062e\u0634\u06cc \u0627\u0632 \u067e\u0633\u062a \u200c\u0647\u0627\u06cc \u0622\u06cc\u0646\u062f\u0647 \u0628\u0631\u0631\u0633\u06cc \u062e\u0648\u0627\u0647\u06cc\u0645 \u06a9\u0631\u062f) \u067e\u0633 \u062f\u0627\u0634\u062a\u0646 \u0622\u0646\u060c \u0634\u0645\u0627 \u0631\u0627 \u0627\u0632 \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u062f\u0633\u062a\u06cc \u0648 \u0627\u062c\u0631\u0627\u06cc \u00a0\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u062e\u0644\u0627\u0635 \u0645\u06cc\u200c \u06a9\u0646\u062f.<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" width=\"1024\" height=\"619\" src=\"https:\/\/shahaab-co.ir\/mag\/wp-content\/uploads\/2020\/03\/\u06a9\u062f-\u0646\u0648\u06cc\u0633\u06cc-\u0628\u06cc\u0632-\u0633\u0627\u062f\u0647-sklearn-1024x619.png\" alt=\"\u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 sklearn\" class=\"wp-image-5876\" title=\"\" srcset=\"https:\/\/shahaab-co.com\/mag\/wp-content\/uploads\/2020\/03\/\u06a9\u062f-\u0646\u0648\u06cc\u0633\u06cc-\u0628\u06cc\u0632-\u0633\u0627\u062f\u0647-sklearn-1024x619.png 1024w, https:\/\/shahaab-co.com\/mag\/wp-content\/uploads\/2020\/03\/\u06a9\u062f-\u0646\u0648\u06cc\u0633\u06cc-\u0628\u06cc\u0632-\u0633\u0627\u062f\u0647-sklearn-300x181.png 300w, https:\/\/shahaab-co.com\/mag\/wp-content\/uploads\/2020\/03\/\u06a9\u062f-\u0646\u0648\u06cc\u0633\u06cc-\u0628\u06cc\u0632-\u0633\u0627\u062f\u0647-sklearn-768x464.png 768w, https:\/\/shahaab-co.com\/mag\/wp-content\/uploads\/2020\/03\/\u06a9\u062f-\u0646\u0648\u06cc\u0633\u06cc-\u0628\u06cc\u0632-\u0633\u0627\u062f\u0647-sklearn.png 1641w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>\u0628\u0647 \u06cc\u06a9 \u0645\u0631\u062f \u0628\u0631\u0646\u0627\u0645\u0647 \u0627\u06cc \u0628\u062f\u0647\u06cc\u062f\u060c \u0627\u0648 \u0631\u0627 \u06cc\u06a9 \u0631\u0648\u0632 \u062e\u0633\u062a\u0647 \u06a9\u0646\u06cc\u062f.<br> \u0628\u0647 \u06cc\u06a9 \u0645\u0631\u062f \u0628\u0631\u0646\u0627\u0645\u0647 \u0646\u0648\u06cc\u0633\u06cc \u06cc\u0627\u062f \u0628\u062f\u0647\u06cc\u062f\u060c \u0627\u0648 \u0631\u0627 \u06cc\u06a9 \u0639\u0645\u0631 \u062e\u0633\u062a\u0647 \u06a9\u0646\u06cc\u062f.<\/figcaption><\/figure><\/div>\n\n\n<h2 style=\"text-align: justify;\"><strong>\u062a\u0645\u0631\u06cc\u0646 \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0627\u06cc\u0646 \u062a\u0645\u0631\u06cc\u0646\u060c \u0645\u0627 \u0645\u062f\u0644 \u0631\u0627 \u0628\u0627 \u0645\u062c\u0645\u0648\u0639\u0647 \u200c\u0627\u06cc \u0627\u0632 \u0627\u06cc\u0645\u06cc\u0644\u200c\u0647\u0627\u06cc \u0639\u0644\u0627\u0645\u062a \u200c\u06af\u0630\u0627\u0631\u06cc \u0634\u062f\u0647 \u0628\u0627 \u0639\u0646\u0648\u0627\u0646 \u0647\u0631\u0632\u0646\u0627\u0645\u0647 ( Spam ) \u06cc\u0627 \u063a\u06cc\u0631 \u0647\u0631\u0632\u0646\u0627\u0645\u0647 ( Not Spam ) \u0622\u0645\u0648\u0632\u0634 \u062e\u0648\u0627\u0647\u06cc\u0645 \u062f\u0627\u062f. \u06f7\u06f0\u06f2 \u0627\u06cc\u0645\u06cc\u0644 \u0628\u0647 \u0637\u0648\u0631 \u0645\u0633\u0627\u0648\u06cc \u0628\u06cc\u0646 \u0647\u0631\u0632\u0646\u0627\u0645\u0647 \u0648 \u063a\u06cc\u0631\u0647\u0631\u0632\u0646\u0627\u0645\u0647 \u062a\u0642\u0633\u06cc\u0645 \u0634\u062f\u0647\u200c \u0627\u0633\u062a. \u0633\u067e\u0633\u060c \u0645\u0627 \u0645\u062f\u0644 \u0631\u0627 \u0628\u0631 \u0631\u0648\u06cc \u06f2\u06f6\u06f0 \u0627\u06cc\u0645\u06cc\u0644 \u0622\u0632\u0645\u0627\u06cc\u0634 \u062e\u0648\u0627\u0647\u06cc\u0645 \u06a9\u0631\u062f. \u0645\u0627 \u0627\u0632 \u0645\u062f\u0644 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0634 \u200c\u0628\u06cc\u0646\u06cc \u062f\u0633\u062a\u0647 \u06cc \u0627\u06cc\u0646 \u0627\u06cc\u0645\u06cc\u0644\u200c \u0647\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0647 \u0648 \u062f\u0642\u062a \u0645\u062f\u0644 \u0631\u0627 \u0628\u0627 \u06a9\u0644\u0627\u0633\u0647 \u200c\u0628\u0646\u062f\u06cc \u0635\u062d\u06cc\u062d \u06a9\u0647 \u0642\u0628\u0644\u0627\u064b \u0645\u06cc \u200c\u062f\u0627\u0646\u06cc\u0645 &nbsp;\u0645\u0642\u0627\u06cc\u0633\u0647 \u0645\u06cc \u200c\u06a9\u0646\u06cc\u0645.<\/p>\n<p style=\"text-align: justify;\">\u0627\u06cc\u0646 \u06cc\u06a9 \u0646\u0645\u0648\u0646\u0647 \u06a9\u0644\u0627\u0633\u06cc\u06a9 \u0627\u0632 \u062f\u0627\u062f\u0647 \u06a9\u0627\u0648\u06cc \u0627\u0633\u062a.<\/p>\n<h2 style=\"text-align: justify;\"><strong>\u067e\u06cc\u0634 \u0646\u06cc\u0627\u0632 \u0647\u0627 :<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0627\u06cc\u0646 \u0622\u0645\u0648\u0632\u0634 \u0641\u0631\u0636 \u0645\u06cc \u200c\u0634\u0648\u062f \u06a9\u0647 \u0642\u0628\u0644\u0627 \u062a\u0645\u0631\u06cc\u0646 \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u0628\u0631 \u0631\u0648\u06cc \u0644\u06cc\u0646\u0648\u06a9\u0633 \u062f\u0628\u06cc\u0627\u0646 \u0627\u0646\u062c\u0627\u0645 \u062f\u0627\u062f\u0647 \u0627\u06cc\u062f. \u062f\u0633\u062a\u0648\u0631\u0627\u0644\u0639\u0645\u0644 \u0646\u0635\u0628 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0628\u0633\u062a\u0647 \u0628\u0647 \u0633\u06cc\u0633\u062a\u0645\u200c \u0639\u0627\u0645\u0644\u06cc \u06a9\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u062f \u0645\u062a\u0641\u0627\u0648\u062a \u0628\u0627\u0634\u062f\u060c \u0628\u0627 \u0627\u06cc\u0646 \u062d\u0627\u0644\u060c \u06a9\u062f <a href=\"https:\/\/shahaab-co.ir\/mag\/tag\/%d9%be%d8%a7%db%8c%d8%aa%d9%88%d9%86\/\" target=\"_blank\" rel=\"noopener\">\u067e\u0627\u06cc\u062a\u0648\u0646<\/a> \u06cc\u06a9 \u200c\u0633\u0627\u0646 \u0628\u0627\u0642\u06cc \u0645\u06cc\u200c \u0645\u0627\u0646\u062f.<\/p>\n<ul style=\"text-align: justify;\">\n<li>\u0646\u0635\u0628 \u067e\u0627\u06cc\u062a\u0648\u0646<\/li>\n<li>\u0646\u0635\u0628 pip<\/li>\n<li>\u0646\u0635\u0628 sklearn \u0627\u0632 \u067e\u0627\u06cc\u062a\u0648\u0646 : pip install scikit-learn<\/li>\n<li>\u0646\u0635\u0628 numpy: pip install numpy<\/li>\n<li>\u0646\u0635\u0628 SciPy : pip install scipy<\/li>\n<\/ul>\n<h2 style=\"text-align: justify;\"><strong>\u06f0- \u062f\u0627\u0646\u0644\u0648\u062f<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u0645\u0646 \u06cc\u06a9 \u0645\u062e\u0632\u0646 \u062f\u0631 \u06af\u06cc\u062a \u0647\u0627\u0628 \u0628\u0631\u0627\u06cc \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647\u200c \u0647\u0627 \u0648 \u06a9\u062f \u0646\u0645\u0648\u0646\u0647 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0631\u062f\u0647\u200c \u0627\u0645. \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u0627\u0632 <a href=\"https:\/\/github.com\/savanpatel\/machine-learning-101\" target=\"_blank\" rel=\"noopener\">\u0627\u06cc\u0646\u062c\u0627<\/a> \u0622\u0646 \u0631\u0627 \u062f\u0627\u0646\u0644\u0648\u062f \u06a9\u0646\u06cc\u062f (\u0627\u0632 \u067e\u0648\u0634\u0647 \u06cc chapter 1 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u06cc\u062f ). \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0627\u06cc \u06a9\u0647 \u0627\u0631\u0627\u0626\u0647 \u0634\u062f\u0647 \u0647\u0645\u06cc\u0646 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0627\u06cc \u0627\u0633\u062a \u06a9\u0647 \u062f\u0631 \u0627\u06cc\u0646 \u0628\u062e\u0634 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f. \u0645\u0646 \u067e\u06cc\u0634\u0646\u0647\u0627\u062f \u0645\u06cc\u200c \u06a9\u0646\u0645 \u06a9\u0647 \u0627\u06cc\u0646 \u0645\u0642\u0627\u0644\u0647 \u0631\u0627 \u062f\u0646\u0628\u0627\u0644 \u06a9\u0646\u06cc\u062f \u0648 \u062e\u0648\u062f\u062a\u0627\u0646 \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u062f\u0647\u06cc\u062f. \u062f\u0631 \u0635\u0648\u0631\u062a\u06cc \u06a9\u0647 \u0634\u06a9\u0633\u062a \u062e\u0648\u0631\u062f\u06cc\u062f\u060c \u0645\u06cc \u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u0627\u0632 <a href=\"https:\/\/github.com\/savanpatel\/machine-learning-101\/blob\/master\/chapter1\/code\/classifier.py\" target=\"_blank\" rel=\"noopener\">\u0646\u0633\u062e\u0647 \u06cc \u0645\u0646<\/a> \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0647 \u06cc\u0627 \u0628\u0647 \u0622\u0646 \u0631\u062c\u0648\u0639 \u06a9\u0646\u06cc\u062f.<\/p>\n<h2 style=\"text-align: justify;\"><strong>\u06f1- \u067e\u0627\u0644\u0627\u06cc\u0634 \u0648 \u0622\u0645\u0627\u062f\u0647\u200c \u0633\u0627\u0632\u06cc \u062f\u0627\u062f\u0647 \u200c\u0647\u0627<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u0645\u0627 \u062f\u0648 \u067e\u0648\u0634\u0647 \u06cc \u0627\u06cc\u0645\u06cc\u0644 \u0647\u0627\u06cc \u0622\u0632\u0645\u0627\u06cc\u0634 ( test-mails ) \u0648 \u0627\u06cc\u0645\u06cc\u0644 \u0647\u0627\u06cc \u0622\u0645\u0648\u0632\u0634 ( train-mails ) \u062f\u0627\u0631\u06cc\u0645. \u0645\u0627 \u0627\u0632 \u0627\u06cc\u0645\u06cc\u0644 \u0647\u0627\u06cc \u0622\u0645\u0648\u0632\u0634 \u0628\u0631\u0627\u06cc \u0622\u0645\u0648\u0632\u0634 \u0645\u062f\u0644 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u062e\u0648\u0627\u0647\u06cc\u0645 &nbsp;\u06a9\u0631\u062f. \u0646\u0645\u0648\u0646\u0647 \u062f\u0627\u062f\u0647\u200c \u0647\u0627\u06cc \u0627\u06cc\u0645\u06cc\u0644 \u0646\u0645\u0648\u0646\u0647 \u0628\u0647 \u0627\u06cc\u0646 \u0634\u06a9\u0644 \u0627\u0633\u062a:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">Subject: re : 2 . 882 s - &gt; np np\n&gt; deat : sun , 15 dec 91 2 : 25 : 2 est &gt; : michael &lt; mmorse @ vm1 . yorku . ca &gt; &gt; subject : re : 2 . 864 query &gt; &gt; wlodek zadrozny ask \" anything interest \" &gt; construction \" s &gt; np np \" . . . second , &gt; much relate : consider construction form &gt; discuss list late reduplication ? &gt; logical sense \" john mcnamara name \" tautologous thus , &gt; level , indistinguishable \" , , here ? \" . ' john mcnamara name ' tautologous support those logic-base semantics irrelevant natural language . sense tautologous ? supplies value attribute follow attribute value . fact value name-attribute relevant entity ' chaim shmendrik ' , ' john mcnamara name ' false . tautology , . ( reduplication , either . )\n<\/pre>\n<p style=\"text-align: justify;\">\u062e\u0637 \u0627\u0648\u0644 \u0645\u0648\u0636\u0648\u0639 \u0627\u0633\u062a \u0648 \u0645\u062d\u062a\u0648\u0627 \u0627\u0632 \u062e\u0637 \u0633\u0648\u0645 \u0634\u0631\u0648\u0639 \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<p style=\"text-align: justify;\">\u0627\u06af\u0631 \u0647\u0631 \u06cc\u06a9 \u0627\u0632 \u0627\u06cc\u0645\u06cc\u0644 \u0647\u0627\u06cc \u0622\u0645\u0648\u0632\u0634 \u06cc\u0627 \u0627\u06cc\u0645\u06cc\u0644 \u0647\u0627\u06cc \u0622\u0632\u0645\u0627\u06cc\u0634\u06cc \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0646\u06cc\u062f\u060c \u0645\u062a\u0648\u062c\u0647 \u062e\u0648\u0627\u0647\u06cc\u062f \u0634\u062f \u06a9\u0647 \u0646\u0627\u0645 \u0641\u0627\u06cc\u0644 \u0647\u0627 \u062f\u0648 \u0627\u0644\u06af\u0648 \u062f\u0627\u0631\u0646\u062f :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">number-numbermsg[number].txt : example 3-1msg1.txt (this are non spam emails)\nOR\nspmsg[Number].txt : example spmsga162.txt (these files are of spam emails).\n<\/pre>\n<p style=\"text-align: justify;\">\u0627\u0648\u0644\u06cc\u0646 \u0642\u062f\u0645 \u0628\u0631\u0627\u06cc \u06a9\u0627\u0631 \u062f\u0627\u062f\u0647 \u06a9\u0627\u0648\u06cc \u060c \u067e\u0627\u0644\u0627\u06cc\u0634 \u0648 \u0622\u0645\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0631\u0627\u06cc \u06cc\u06a9 \u0645\u062f\u0644 \u0627\u0633\u062a. \u0647\u0646\u06af\u0627\u0645 \u067e\u0627\u0644\u0627\u06cc\u0634 \u060c \u06a9\u0644\u0645\u0627\u062a \u060c \u0639\u0628\u0627\u0631\u0627\u062a \u0648 \u0646\u0645\u0627\u062f \u0647\u0627\u06cc\u06cc \u06a9\u0647 \u0646\u06cc\u0627\u0632\u06cc \u0628\u0647 \u0622\u0646 \u0647\u0627 \u0646\u062f\u0627\u0631\u06cc\u0645 \u0631\u0627 \u0627\u0632 \u0645\u062a\u0646 \u062d\u0630\u0641 \u0645\u06cc \u06a9\u0646\u06cc\u0645.<\/p>\n<p style=\"text-align: justify;\">\u0627\u06cc\u0646 \u0645\u062a\u0646 \u0631\u0627 \u062f\u0631 \u0646\u0638\u0631 \u0628\u06af\u06cc\u0631\u06cc\u062f:<\/p>\n<p style=\"text-align: justify;\">\u201cHi, this is Alice. Hope you are doing well and enjoying your vacation.\u201d<\/p>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u06a9\u0644\u0645\u0627\u062a\u06cc \u0645\u0627\u0646\u0646\u062f \u0647\u0633\u062a\u0645\u060c \u0627\u06cc\u0646\u060c \u0628\u0627\u0634\u062f\u060c \u0648 \u063a\u06cc\u0631\u0647 \u0648\u0627\u0642\u0639\u0627\u064b \u062f\u0631 \u062a\u062c\u0632\u06cc\u0647 \u0648 \u062a\u062d\u0644\u06cc\u0644 \u06a9\u0645\u06a9\u06cc \u0646\u0645\u06cc \u06a9\u0646\u0646\u062f. \u0686\u0646\u06cc\u0646 \u06a9\u0644\u0645\u0627\u062a\u06cc \u0646\u06cc\u0632 \u06a9\u0644\u0645\u0627\u062a \u062a\u0648\u0642\u0641 (Stop Words) \u0646\u0627\u0645\u06cc\u062f\u0647 \u0645\u06cc \u0634\u0648\u0646\u062f. \u0627\u0632 \u0627\u06cc\u0646 \u0631\u0648\u060c \u062f\u0631 \u0627\u06cc\u0646 \u062a\u0645\u0631\u06cc\u0646\u060c \u0645\u0627 \u06f3\u06f0\u06f0\u06f0 \u06a9\u0644\u0645\u0647 \u0627\u06cc \u0627\u0632 \u0641\u0631\u0647\u0646\u06af \u0644\u063a\u062a \u06a9\u0647 \u0628\u06cc\u0634\u062a\u0631\u06cc\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0631\u0627 \u062f\u0627\u0631\u0646\u062f \u0631\u0627 \u062f\u0631 \u0627\u06cc\u0645\u06cc\u0644 \u0647\u0627 \u062f\u0631 \u0646\u0638\u0631 \u0645\u06cc \u06af\u06cc\u0631\u06cc\u0645. \u0645\u0637\u0627\u0628\u0642 \u06a9\u062f \u062f\u0627\u062f\u0647 \u0634\u062f\u0647 \u0627\u06cc\u0646 \u06a9\u0627\u0631 \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<p style=\"text-align: justify;\">\u0628\u0639\u062f \u0627\u0632 \u067e\u0627\u0644\u0627\u06cc\u0634\u060c \u0622\u0646\u0686\u0647 \u0646\u06cc\u0627\u0632 \u062f\u0627\u0631\u06cc\u0645 \u0627\u06cc\u0646 \u0627\u0633\u062a \u06a9\u0647 \u0628\u0627\u06cc\u062f \u0645\u0627\u062a\u0631\u06cc\u0633\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u062a\u06a9\u0631\u0627\u0631 \u0647\u0631 \u06a9\u0644\u0645\u0647 \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u0645.<\/p>\n<p style=\"text-align: justify;\">\u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0645\u062b\u0627\u0644 \u0627\u06af\u0631 \u0645\u0637\u0644\u0628 \u067e\u0633 \u0627\u0632 \u067e\u0627\u0644\u0627\u06cc\u0634 \u062d\u0627\u0648\u06cc \u0627\u06cc\u0646 \u0645\u062a\u0646 \u0627\u0633\u062a: \u201cHi, this is Alice. Happy Birthday Alice\u201d\u060c \u062a\u06a9\u0631\u0627\u0631 \u06a9\u0644\u0645\u0627\u062a \u0628\u0647 \u0635\u0648\u0631\u062a \u0632\u06cc\u0631 \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">word      :   Hi this is Alice Happy Birthday\nfrequency :   1   1    1  2      1      1\n<\/pre>\n<p style=\"text-align: justify;\">\u0648 \u0645\u0627 \u0628\u0631\u0627\u06cc \u0647\u0631 \u0645\u062f\u0631\u06a9 \u0628\u0647 \u0627\u06cc\u0646 \u0645\u0627\u062a\u0631\u06cc\u0633 \u0646\u06cc\u0627\u0632 \u062f\u0627\u0631\u06cc\u0645. \u062a\u0627\u0628\u0639 extract_features ( \u0628\u062e\u0634 \u06f2 ) \u0632\u06cc\u0631\u060c \u0627\u06cc\u0646 \u06a9\u0627\u0631 \u0631\u0627 \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u062f\u0647\u062f \u0648 \u0633\u067e\u0633 \u06a9\u0644\u0645\u0627\u062a\u06cc \u06a9\u0647 \u06a9\u0645\u062a\u0631 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u0646\u062f \u0631\u0627 \u0627\u0632 \u0647\u0631 \u0645\u0637\u0644\u0628 \u062d\u0630\u0641 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def make_Dictionary(root_dir):\n   all_words = []\n   emails = [os.path.join(root_dir,f) for f in os.listdir(root_dir)]\n   for mail in emails:\n        with open(mail) as m:\n            for line in m:\n                words = line.split()\n                all_words += words\n   dictionary = Counter(all_words)\n   # if you have python version 3.x use commented version.\n   # list_to_remove = list(dictionary)\n   list_to_remove = dictionary.keys()\n   for item in list_to_remove:\n       # remove if numerical. \n       if item.isalpha() == False:\n            del dictionary[item]\n        elif len(item) == 1:\n            del dictionary[item]\n    # consider only most 3000 common words in dictionary.\n   dictionary = dictionary.most_common(3000)\n   return dictionary\n<\/pre>\n<p style=\"text-align: justify;\">\u062a\u0627\u0628\u0639 make_Dictionary \u0641\u0627\u06cc\u0644 \u0647\u0627\u06cc \u0627\u06cc\u0645\u06cc\u0644 \u0631\u0627 \u0627\u0632 \u06cc\u06a9 \u067e\u0648\u0634\u0647 \u0645\u06cc \u062e\u0648\u0627\u0646\u062f \u0648 \u0641\u0631\u0647\u0646\u06af \u0646\u0627\u0645\u0647 \u0627\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0647\u0645\u0647 \u06cc \u06a9\u0644\u0645\u0627\u062a \u0627\u06cc\u062c\u0627\u062f \u0645\u06cc \u06a9\u0646\u062f. \u0628\u0639\u062f \u060c \u0645\u0627 \u06a9\u0644\u0645\u0627\u062a\u06cc \u06a9\u0647 \u0637\u0648\u0644 \u06f1 \u062f\u0627\u0631\u0646\u062f \u06cc\u0627 \u0627\u0632 \u0646\u0638\u0631 \u0627\u0644\u0641\u0628\u0627\u06cc\u06cc \u062f\u0631\u0633\u062a \u0646\u06cc\u0633\u062a\u0646\u062f \u0631\u0627 \u062d\u0630\u0641 \u0645\u06cc \u06a9\u0646\u06cc\u0645.<\/p>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0622\u062e\u0631 \u0645\u0627 \u0641\u0642\u0637 \u06f3\u06f0\u06f0\u06f0 \u06a9\u0644\u0645\u0647 \u0645\u062a\u062f\u0627\u0648\u0644 \u0631\u0627 \u0627\u0633\u062a\u062e\u0631\u0627\u062c \u0645\u06cc \u06a9\u0646\u06cc\u0645.<\/p>\n<h2 style=\"text-align: justify;\"><strong>\u06f2- <\/strong><strong>\u0627\u0633\u062a\u062e\u0631\u0627\u062c <\/strong><strong>\u0648\u06cc\u0698\u06af\u06cc \u0647\u0627 \u0648 \u0645\u0627\u062a\u0631\u06cc\u0633 \u0628\u0631\u0686\u0633\u0628 \u0645\u0631\u0628\u0648\u0637\u0647<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u0633\u067e\u0633 \u0628\u0627 \u06a9\u0645\u06a9 \u0641\u0631\u0647\u0646\u06af \u0644\u063a\u062a \u060c \u0645\u0627 \u06cc\u06a9 \u0628\u0631\u0686\u0633\u0628 \u0648 \u0645\u0627\u062a\u0631\u06cc\u0633 \u062a\u06a9\u0631\u0627\u0631 \u06a9\u0644\u0645\u0647 \u062a\u0648\u0644\u06cc\u062f \u0645\u06cc \u06a9\u0646\u06cc\u0645 :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">word      :   Hi this is Alice Happy Birthday\nfrequency :   1   1    1  2      1      1\nword      :   Hi this is Alice Happy Birthday\nfrequency :   1   1    1  2      1      1\n<\/pre>\n<p style=\"text-align: justify;\">\n<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">def extract_features(mail_dir):\n  files = [os.path.join(mail_dir,fi) for fi in os.listdir(mail_dir)]\n  features_matrix = np.zeros((len(files),3000))\n  train_labels = np.zeros(len(files))\n  count = 0;\n  docID = 0;\n  for fil in files:\n    with open(fil) as fi:\n      for i,line in enumerate(fi):\n        if i == 2:\n          words = line.split()\n          for word in words:\n            wordID = 0\n            for i,d in enumerate(dictionary):\n              if d[0] == word:\n                wordID = i\n                features_matrix[docID,wordID] = words.count(word)\n      train_labels[docID] = 0;\n      filepathTokens = fil.split('\/')\n      lastToken = filepathTokens[len(filepathTokens) - 1]\n      if lastToken.startswith(\"spmsg\"):\n          train_labels[docID] = 1;\n          count = count + 1\n      docID = docID + 1\n  return features_matrix, train_labels\n<\/pre>\n<h2 style=\"text-align: justify;\"><strong>\u06f3- \u0622\u0645\u0648\u0632\u0634 \u0648 \u067e\u06cc\u0634 \u0628\u06cc\u0646\u06cc \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u062f\u0631 <\/strong><strong>sklearn<\/strong><\/h2>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.naive_bayes.GaussianNB.html\" target=\"_blank\" rel=\"noopener\">\u0645\u0633\u062a\u0646\u062f\u0627\u062a<\/a> \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u062f\u0631sklearn &nbsp;\u0628\u0627 \u0635\u0631\u0627\u062d\u062a \u062f\u0631 \u0645\u0648\u0631\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0648 \u067e\u0627\u0631\u0627\u0645\u062a\u0631\u0647\u0627\u06cc \u0622\u0646 \u062a\u0648\u0636\u06cc\u062d \u062f\u0627\u062f\u0647 \u0627\u0633\u062a.<\/p>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0648\u0627\u0642\u0639 \u060c \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u062f\u0631 Sklearn \u0633\u0647 \u06af\u0632\u06cc\u0646\u0647 \u0628\u0631\u0627\u06cc \u0622\u0645\u0648\u0632\u0634 \u0645\u062f\u0644 \u0627\u0631\u0627\u0626\u0647 \u0645\u06cc \u062f\u0647\u062f:<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/scikit-learn.org\/stable\/modules\/naive_bayes.html\" target=\"_blank\" rel=\"noopener\">\u06af\u0627\u0648\u0633\u06cc :<\/a> \u062f\u0631 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f \u0648 \u0641\u0631\u0636 \u0645\u06cc \u06a9\u0646\u062f \u06a9\u0647 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627 \u0627\u0632 \u062a\u0648\u0632\u06cc\u0639 \u0639\u0627\u062f\u06cc \u067e\u06cc\u0631\u0648\u06cc \u0645\u06cc \u06a9\u0646\u0646\u062f.<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/scikit-learn.org\/stable\/modules\/naive_bayes.html\" target=\"_blank\" rel=\"noopener\">\u0686\u0646\u062f \u062c\u0645\u0644\u0647 \u0627\u06cc :<\/a> \u0628\u0631\u0627\u06cc \u0634\u0645\u0627\u0631\u0634 \u0647\u0627\u06cc \u06af\u0633\u0633\u062a\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f. \u0628\u0631\u0627\u06cc \u0645\u062b\u0627\u0644 \u060c \u0628\u06af\u0630\u0627\u0631\u06cc\u062f \u0628\u06af\u0648\u06cc\u06cc\u0645 \u060c \u0645\u0627 \u06cc\u06a9 \u0645\u0633\u0627\u0644\u0647 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0645\u062a\u0646 \u062f\u0627\u0631\u06cc\u0645. \u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0645\u06cc \u062a\u0648\u0627\u0646 \u0631\u0648\u0634 \u0647\u0627\u06cc \u0628\u0631\u0646\u0648\u0644\u06cc \u0631\u0627 \u062f\u0631 \u0646\u0638\u0631 \u06af\u0631\u0641\u062a \u06a9\u0647 \u06cc\u06a9 \u0642\u062f\u0645 \u062c\u0644\u0648\u062a\u0631 \u0627\u0633\u062a \u0648 \u0628\u0647 \u062c\u0627\u06cc &#8220;\u06a9\u0644\u0645\u0647 \u0627\u06cc \u06a9\u0647 \u062f\u0631 \u0645\u0637\u0644\u0628 \u0631\u062e \u0645\u06cc \u062f\u0647\u062f&#8221; \u060c &#8221; \u062a\u0639\u062f\u0627\u062f \u062f\u0641\u0639\u0627\u062a \u0645\u0634\u0627\u0647\u062f\u0647 \u06a9\u0644\u0645\u0647 \u062f\u0631 \u0645\u0637\u0644\u0628 &#8221; \u0631\u0627 \u0645\u062d\u0627\u0633\u0628\u0647 \u0645\u06cc \u06a9\u0646\u06cc\u0645 \u060c \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 &#8221; \u062a\u0639\u062f\u0627\u062f \u062f\u0641\u0639\u0627\u062a\u06cc \u06a9\u0647 \u0627\u062a\u0641\u0627\u0642 x_i \u062f\u0631 \u0637\u0648\u0644 n \u0622\u0632\u0645\u0627\u06cc\u0634 \u067e\u06cc\u0634 \u0645\u06cc \u0622\u06cc\u062f. &#8220;<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/scikit-learn.org\/stable\/modules\/naive_bayes.html\" target=\"_blank\" rel=\"noopener\">\u0628\u0631\u0646\u0648\u0644\u06cc :<\/a> \u0627\u06af\u0631 \u0628\u0631\u062f\u0627\u0631\u0647\u0627\u06cc \u0648\u06cc\u0698\u06af\u06cc \u0634\u0645\u0627 \u0628\u0627\u06cc\u0646\u0631\u06cc \u0628\u0627\u0634\u0646\u062f (\u0645\u062b\u0644\u0627 \u0635\u0641\u0631 \u0648 \u06cc\u06a9) \u0645\u062f\u0644 binomial \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f. \u06cc\u06a9\u06cc \u0627\u0632 \u06a9\u0627\u0631\u0628\u0631\u062f \u0647\u0627\u06cc \u0622\u0646 \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0645\u062a\u0646 \u0628\u0627 \u0645\u062f\u0644 \u00ab\u062f\u0633\u062a\u0647 \u06cc \u06a9\u0644\u0645\u0627\u062a\u00bb \u0628\u0627\u0634\u062f \u06a9\u0647 \u06f1 \u0648 \u06f0 \u0628\u0647 \u062a\u0631\u062a\u06cc\u0628 &#8220;\u06a9\u0644\u0645\u0647 \u062f\u0631 \u0645\u0637\u0644\u0628 \u0631\u062e \u0645\u06cc \u062f\u0647\u062f&#8221; \u0648 &#8220;\u06a9\u0644\u0645\u0647 \u062f\u0631 \u0645\u0637\u0644\u0628 \u0631\u062e \u0646\u0645\u06cc \u062f\u0647\u062f&#8221; \u0647\u0633\u062a\u0646\u062f.<\/p>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0627\u06cc\u0646 \u062a\u0645\u0631\u06cc\u0646 \u0627\u0632 \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u06cc \u06af\u0627\u0648\u0633\u06cc \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u062e\u0648\u0627\u0647\u06cc\u0645 \u06a9\u0631\u062f. \u06a9\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0634\u062f\u0647 \u0628\u0647 \u0635\u0648\u0631\u062a \u0632\u06cc\u0631 \u0645\u06cc \u0628\u0627\u0634\u062f.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">TRAIN_DIR = \"..\/train-mails\"\nTEST_DIR = \"..\/test-mails\"\ndictionary = make_Dictionary(TRAIN_DIR)\n# using functions mentioned above.\nfeatures_matrix, labels = extract_features(TRAIN_DIR)\ntest_feature_matrix, test_labels = extract_features(TEST_DIR)\nfrom sklearn.naive_bayes import GaussianNB\nmodel = GaussianNB()\n#train model\nmodel.fit(features_matrix, labels)\n#predict\npredicted_labels = model.predict(test_feature_matrix)\n<\/pre>\n<h2 style=\"text-align: justify;\"><strong>\u06f4- \u0627\u0645\u062a\u06cc\u0627\u0632 \u062f\u0642\u062a<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u062f\u0631 \u0645\u0631\u062d\u0644\u0647 \u0628\u0639\u062f \u060c \u0645\u0627 \u0646\u0645\u0631\u0647 \u062f\u0642\u062a \u0631\u0627 \u0628\u0631\u0627\u06cc \u0628\u0631\u0686\u0633\u0628 \u0647\u0627\u06cc \u067e\u06cc\u0634 \u0628\u06cc\u0646\u06cc \u0634\u062f\u0647 \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc \u06a9\u0646\u06cc\u0645. \u0646\u0645\u0631\u0647 \u062f\u0642\u062a\u060c \u062f\u0631\u0635\u062f \u067e\u06cc\u0634 \u0628\u06cc\u0646\u06cc \u0647\u0627\u06cc \u0635\u062d\u06cc\u062d \u0627\u0633\u062a. \u0645\u062c\u062f\u062f\u0627\u064b \u060c sklearn \u0628\u0631\u0627\u06cc \u0645\u062d\u0627\u0633\u0628\u0647 \u062f\u0642\u06cc\u0642 \u0646\u0645\u0631\u0647 \u062f\u0642\u062a \u060c \u062a\u0648\u0627\u0628\u0639 \u0627\u062c\u0631\u0627\u06cc\u06cc \u062e\u0648\u0628\u06cc \u0627\u0631\u0627\u0626\u0647 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">from sklearn.metrics import accuracy_score\naccuracy = accuracy_score(test_labels, predicted_labels)\n<\/pre>\n<h2 style=\"text-align: justify;\"><strong>\u06f5- \u062c\u0645\u0639 \u0628\u0646\u062f\u06cc<\/strong><\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import os\nimport numpy as np\nfrom collections import Counter\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.metrics import accuracy_score\ndef make_Dictionary(root_dir):\n   all_words = []\n   emails = [os.path.join(root_dir,f) for f in os.listdir(root_dir)]\n    for mail in emails:\n        with open(mail) as m:\n            for line in m:\n                words = line.split()\n                all_words += words\n    dictionary = Counter(all_words)\n    list_to_remove = dictionary.keys()\n    for item in list_to_remove:\n        if item.isalpha() == False:\n            del dictionary[item]\n        elif len(item) == 1:\n            del dictionary[item]\n    dictionary = dictionary.most_common(3000)\n    return dictionary\ndef extract_features(mail_dir):\n  files = [os.path.join(mail_dir,fi) for fi in os.listdir(mail_dir)]\n  features_matrix = np.zeros((len(files),3000))\n  train_labels = np.zeros(len(files))\n  count = 0;\n  docID = 0;\n  for fil in files:\n    with open(fil) as fi:\n      for i,line in enumerate(fi):\n        if i == 2:\n          words = line.split()\n          for word in words:\n            wordID = 0\n            for i,d in enumerate(dictionary):\n              if d[0] == word:\n                wordID = i\n                features_matrix[docID,wordID] = words.count(word)\n      train_labels[docID] = 0;\n      filepathTokens = fil.split('\/')\n      lastToken = filepathTokens[len(filepathTokens) - 1]\n      if lastToken.startswith(\"spmsg\"):\n          train_labels[docID] = 1;\n          count = count + 1\n      docID = docID + 1\n  return features_matrix, train_labels\nTRAIN_DIR = \"..\/train-mails\"\nTEST_DIR = \"..\/test-mails\"\ndictionary = make_Dictionary(TRAIN_DIR)\nprint \"reading and processing emails from file.\"\nfeatures_matrix, labels = extract_features(TRAIN_DIR)\ntest_feature_matrix, test_labels = extract_features(TEST_DIR)\nmodel = GaussianNB()\nprint \"Training model.\"\n#train model\nmodel.fit(features_matrix, labels)\npredicted_labels = model.predict(test_feature_matrix)\nprint \"FINISHED classifying. accuracy score : \"\nprint accuracy_score(test_labels, predicted_labels)<\/pre>\n<p style=\"text-align: justify;\">\u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u06a9\u062f \u0646\u0648\u0634\u062a\u0647 \u0634\u062f\u0647 \u0631\u0627 <a href=\"https:\/\/github.com\/savanpatel\/machine-learning-101\/blob\/master\/chapter1\/code\/classifier.py\" target=\"_blank\" rel=\"noopener\">\u0627\u06cc\u0646\u062c\u0627<\/a> \u0645\u0634\u0627\u0647\u062f\u0647 \u06a9\u0646\u06cc\u062f.<\/p>\n<p style=\"text-align: justify;\">\u0646\u0645\u0631\u0647 \u06cc \u062f\u0642\u062a\u06cc \u06a9\u0647 \u0627\u0632 \u0627\u06cc\u0646 \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u06af\u0631\u0641\u062a\u06cc\u062f \u0631\u0627 \u0628\u0631\u0627\u06cc \u0645\u0627 \u062f\u0631 \u0628\u062e\u0634 \u0646\u0638\u0631\u0627\u062a \u0628\u0646\u0648\u06cc\u0633\u06cc\u062f.<\/p>\n<p style=\"text-align: justify;\">\n<\/p><h2 style=\"text-align: justify;\"><strong>\u062a\u06a9\u0627\u0644\u06cc\u0641\u06cc \u0628\u0631\u0627\u06cc \u0634\u0645\u0627<\/strong><\/h2>\n<ol style=\"text-align: justify;\">\n<li>\u0645\u062f\u0644 \u0647\u0627\u06cc \u062f\u06cc\u06af\u0631 \u0631\u0627 \u0627\u0645\u062a\u062d\u0627\u0646 \u06a9\u0646\u06cc\u062f. \u0686\u0646\u062f \u062c\u0645\u0644\u0647 \u0648 \u0628\u0631\u0646\u0648\u0644\u06cc \u061b \u0633\u067e\u0633 \u0646\u0645\u0631\u0647 \u06cc \u062f\u0642\u062a \u0631\u0627 \u062f\u0631 \u0631\u0648\u0634 \u0647\u0627\u06cc \u0645\u062e\u062a\u0644\u0641 \u0645\u0642\u0627\u06cc\u0633\u0647 \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u0633\u0639\u06cc \u06a9\u0646\u06cc\u062f \u062a\u0639\u062f\u0627\u062f \u062a\u06a9\u0631\u0627\u0631 \u06a9\u0644\u0645\u0627\u062a \u0631\u0627 \u0627\u0632 \u06f3\u06f0\u06f0\u06f0 \u0628\u0647 \u0645\u0642\u062f\u0627\u0631 \u0628\u0632\u0631\u06af \u062a\u0631 \u0648 \u06a9\u0648\u0686\u06a9 \u062a\u0631 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f \u0648 \u0646\u0645\u0648\u062f\u0627\u0631 \u062f\u0642\u062a \u0631\u0627 \u0631\u0633\u0645 \u06a9\u0646\u06cc\u062f.<\/li>\n<\/ol>\n<h2 style=\"text-align: justify;\"><strong>\u0646\u062a\u06cc\u062c\u0647<\/strong><\/h2>\n<p style=\"text-align: justify;\">\u0628\u06cc\u0632 \u0633\u0627\u062f\u0647\u060c \u0645\u0633\u062a\u0642\u0644 \u0628\u0648\u062f\u0646 \u0631\u0627 \u062f\u0631 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627 \u0645\u0648\u0631\u062f \u0646\u0638\u0631 \u0642\u0631\u0627\u0631 \u0645\u06cc \u062f\u0647\u062f. \u0645\u062b\u0644\u0627 \u0641\u0631\u0636 \u0645\u06cc \u06a9\u0646\u062f \u062a\u0639\u062f\u0627\u062f \u0648\u0642\u0648\u0639 \u06cc\u06a9 \u06a9\u0644\u0645\u0647 \u06cc\u0627 \u0648\u06cc\u0698\u06af\u06cc \u0645\u0633\u062a\u0642\u0644 \u0627\u0632 \u062f\u06cc\u06af\u0631\u06cc \u0627\u0633\u062a. \u0627\u0645\u0627 \u062f\u0631 \u0632\u0646\u062f\u06af\u06cc \u0648\u0627\u0642\u0639\u06cc \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0627\u06cc\u0646\u06af\u0648\u0646\u0647 \u0646\u0628\u0627\u0634\u062f (\u0645\u0639\u0645\u0648\u0644\u0627 \u0628\u0639\u062f \u0627\u0632 \u06a9\u0644\u0645\u0647 \u06cc \u0635\u0628\u062d\u060c \u0628\u062e\u06cc\u0631 \u0645\u06cc \u0622\u06cc\u062f). \u0627\u0645\u06cc\u062f\u0648\u0627\u0631\u0645 \u06a9\u0647 \u0628\u062e\u0634 \u0627\u0648\u0644 (<a href=\"https:\/\/shahaab-co.ir\/mag\/edu\/ml\/supervised-learning-and-naive-bayes-classification-part-1-theory\/\" target=\"_blank\" rel=\"noopener\">\u0645\u0642\u0627\u0644\u0647 \u06cc \u0646\u0638\u0631\u06cc\u0647<\/a> \u0648 \u0627\u06cc\u0646 \u0645\u0642\u0627\u0644\u0647) \u062f\u06cc\u062f \u062e\u0648\u0628\u06cc \u0627\u0632 \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u0628\u0647 \u0634\u0645\u0627 \u062f\u0627\u062f\u0647 \u0628\u0627\u0634\u062f.<\/p>\n<h4><strong>\u0628\u06cc\u0634\u062a\u0631 \u0628\u062e\u0648\u0627\u0646\u06cc\u062f :<\/strong><\/h4>\n\n<ul class=\"wp-block-latest-posts__list wp-block-latest-posts\"><li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/shahaab-co.com\/mag\/news\/tesla-vision-ai-lane-detection\/\">\u062a\u0633\u0644\u0627 \u0648\u06cc\u0698\u0646 \u0686\u06cc\u0633\u062a \u0648 \u062e\u0648\u062f\u0631\u0648\u0647\u0627\u06cc \u062a\u0633\u0644\u0627 \u0686\u06af\u0648\u0646\u0647 \u062e\u0637\u0648\u0637 \u062c\u0627\u062f\u0647 \u0631\u0627 \u062a\u0634\u062e\u06cc\u0635 \u0645\u06cc\u200c\u062f\u0647\u0646\u062f\u061f<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/shahaab-co.com\/mag\/news\/offline-ai-for-mobile\/\">\u0647\u0648\u0634 \u0645\u0635\u0646\u0648\u0639\u06cc \u0622\u0641\u0644\u0627\u06cc\u0646 \u0628\u0631\u0627\u06cc \u06af\u0648\u0634\u06cc<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/shahaab-co.com\/mag\/news\/which-ai-is-working-now\/\">\u06a9\u062f\u0627\u0645 \u0647\u0648\u0634 \u0645\u0635\u0646\u0648\u0639\u06cc \u0627\u0644\u0627\u0646 \u06a9\u0627\u0631 \u0645\u06cc\u06a9\u0646\u0647\u061f<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/shahaab-co.com\/mag\/news\/how-to-find-hidden-spy-cameras-in-hotels\/\">\u062f\u0648\u0631\u0628\u06cc\u0646 \u0647\u0627\u06cc \u062c\u0627\u0633\u0648\u0633\u06cc \u062f\u0631 \u0647\u062a\u0644 \u0647\u0627! \u0686\u06af\u0648\u0646\u0647 \u067e\u06cc\u062f\u0627\u06cc\u0634\u0627\u0646 \u06a9\u0646\u06cc\u0645\u061f<\/a><\/li>\n<li><a class=\"wp-block-latest-posts__post-title\" href=\"https:\/\/shahaab-co.com\/mag\/news\/how-autonomous-vehicles-see-surroundings\/\">\u062e\u0648\u062f\u0631\u0648\u0647\u0627\u06cc \u0628\u062f\u0648\u0646 \u0633\u0631\u0646\u0634\u06cc\u0646 \u0686\u06af\u0648\u0646\u0647 \u0645\u062d\u06cc\u0637 \u0627\u0637\u0631\u0627\u0641 \u0631\u0627 \u0645\u06cc \u0628\u06cc\u0646\u0646\u062f\u061f<\/a><\/li>\n<\/ul>\n\n<a href=\"#\" class=\"shortc-button small blue \">\u0645\u0646\u0628\u0639<\/a> <a href=\"https:\/\/medium.com\/machine-learning-101\/chapter-1-supervised-learning-and-naive-bayes-classification-part-2-coding-5966f25f1475\" class=\"shortc-button small gray \" target=\"_blank\" rel=\"noopener\">Medium<\/a>\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-right kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;right&quot;,&quot;id&quot;:&quot;5875&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;\u0627\u0645\u062a\u06cc\u0627\u0632 \u062f\u0647\u06cc\u062f!&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 \u0627\u0645\u062a\u06cc\u0627\u0632)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;\u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0646\u0638\u0627\u0631\u062a \u0634\u062f\u0647 \u0648 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u2013 \u0628\u062e\u0634 \u062f\u0648\u0645 : \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} \u0627\u0645\u062a\u06cc\u0627\u0632)&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-left: 5px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\">\u0627\u0645\u062a\u06cc\u0627\u0632 \u062f\u0647\u06cc\u062f!<\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u062a\u0648\u062c\u0647 : \u0627\u06af\u0631 \u0628\u062e\u0634 \u0627\u0648\u0644 \u06cc\u0639\u0646\u06cc \u0646\u0638\u0631\u06cc\u0647 \u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u0631\u0627 \u0645\u0637\u0627\u0644\u0639\u0647 \u0646\u06a9\u0631\u062f\u0647 \u0627\u06cc\u062f\u060c \u0628\u0647 \u0634\u0645\u0627 \u067e\u06cc\u0634\u0646\u0647\u0627\u062f \u0645\u06cc \u200c\u06a9\u0646\u06cc\u0645 \u06a9\u0647 \u0622\u0646 \u0631\u0627 \u0645\u0637\u0627\u0644\u0639\u0647 \u06a9\u0646\u06cc\u062f. \u0645\u0642\u0627\u0644\u0647 \u0645\u0631\u062a\u0628\u0637 : \u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0646\u0638\u0627\u0631\u062a \u0634\u062f\u0647 \u0648 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u2013 \u0628\u062e\u0634 \u0627\u0648\u0644 : \u0646\u0638\u0631\u06cc\u0647 \u06cc\u0627\u062f\u06af\u06cc\u0631\u06cc \u0646\u0638\u0627\u0631\u062a \u0634\u062f\u0647 \u0648 \u06a9\u0644\u0627\u0633\u0647 \u0628\u0646\u062f\u06cc \u0628\u06cc\u0632 \u0633\u0627\u062f\u0647 \u2013 \u0628\u062e\u0634 \u062f\u0648\u0645 : \u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u0645\u0627\u0634\u06cc\u0646 &hellip;<\/p>\n","protected":false},"author":7,"featured_media":5883,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[195,18],"tags":[84,147,152,126],"class_list":["post-5875","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-ml","category-edu","tag-84","tag-147","tag-152","tag-126"],"_links":{"self":[{"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/posts\/5875","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/comments?post=5875"}],"version-history":[{"count":1,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/posts\/5875\/revisions"}],"predecessor-version":[{"id":16845,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/posts\/5875\/revisions\/16845"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/media\/5883"}],"wp:attachment":[{"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/media?parent=5875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/categories?post=5875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shahaab-co.com\/mag\/wp-json\/wp\/v2\/tags?post=5875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}