<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jenny Zhou on Medium]]></title>
        <description><![CDATA[Stories by Jenny Zhou on Medium]]></description>
        <link>https://medium.com/@zjy9493?source=rss-34d7415e3458------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*qd3tutFPPO9yN-kUthiqQA.jpeg</url>
            <title>Stories by Jenny Zhou on Medium</title>
            <link>https://medium.com/@zjy9493?source=rss-34d7415e3458------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 12:11:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zjy9493/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NLP: Simple Language Detector using Naive Bayes]]></title>
            <link>https://medium.com/@zjy9493/nlp-simple-language-detector-using-naive-bayes-2ef3a78d144c?source=rss-34d7415e3458------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ef3a78d144c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Jenny Zhou]]></dc:creator>
            <pubDate>Sat, 04 Jan 2020 21:05:12 GMT</pubDate>
            <atom:updated>2020-01-04T21:22:51.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p-1edT3hQiG8Q74E" /><figcaption>Photo by <a href="https://unsplash.com/@epicantus?utm_source=medium&amp;utm_medium=referral">Daria Nepriakhina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Natural Language Processing (NLP) is how we make machines learn human language of communication.</p><p>This is the note when I review the NLP knowledge and help me clear my head.</p><h3><strong>Project background and main content</strong></h3><p>This project is a simple text classification project using Naive Bayes.</p><p><strong>Content:</strong></p><ol><li>Data preprocessing: remove extraneous content from text to improve the quality of the data using regular expression.</li><li>Vector the text data.</li><li>Applying Naive Bayes to build classifier.</li></ol><h3><strong>Data Description</strong></h3><p>The data is from Twitter including 6 languages: English, French, German, Spanish, Italian and Dutch.</p><p>All right! Let’s jump into the project!</p><h3>Load data</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f42602a50d63fb7ccaaa886fa704ede7/href">https://medium.com/media/f42602a50d63fb7ccaaa886fa704ede7/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IgHbmlxurlCEUhPzl49a_Q.png" /></figure><h3>Data preprocessing</h3><p>Firstly, let’ s split the dataset into training and testing set.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a83c4cd6e69f3f8db1c4f86650809851/href">https://medium.com/media/a83c4cd6e69f3f8db1c4f86650809851/href</a></iframe><h4>Data cleaning</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5eee78327d13bcc451d17bd7800a23d6/href">https://medium.com/media/5eee78327d13bcc451d17bd7800a23d6/href</a></iframe><h4><strong>Vector representation of the document</strong></h4><p>I used two methods: they can be used in converting human readable English text into a language machine can understand.</p><ol><li>CountVectorizer()</li><li>TfidfVectorizer()</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1e02a4960265f81f3810fab11664fce/href">https://medium.com/media/d1e02a4960265f81f3810fab11664fce/href</a></iframe><h4>Build Naive Bayes model</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10a7364de8458d5a45136ce2be62d096/href">https://medium.com/media/10a7364de8458d5a45136ce2be62d096/href</a></iframe><p>MultinomialNB(alpha=1.0, class_prior=None, fit_prior=True)</p><pre>classifier.score(vec.transform(X_test), y_test)</pre><pre>0.9907366563740626</pre><p>Give an example to test the classifier:</p><pre>classifier.predict(vec.transform([&quot;my name is MaxMa&quot;]))</pre><p>array([&#39;en&#39;], dtype=&#39;&lt;U2&#39;)</p><p>Putting them together and packaging functions for the later use：</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa4133281bcace95885a59a2138c06f1/href">https://medium.com/media/fa4133281bcace95885a59a2138c06f1/href</a></iframe><p>Let’s call the functions to test them.</p><pre>language_detector = LanguageDetector()<br>language_detector.fit(list(X_train), y_train)<br>print(language_detector.predict(&#39;This is an English sentence&#39;))<br>print(language_detector.score(list(X_test), y_test))</pre><p>Result:[&#39;en&#39;] 0.992501102779003</p><h4>Save model and loading</h4><p>Save model:</p><pre>model_path = &quot;my_model/language_detector.model&quot;<br>language_detector.save_model(model_path)</pre><p>Load model:</p><pre>new_language_detector = LanguageDetector()<br>new_language_detector.load_model(model_path)<br><br># using model to predict<br>new_language_detector.predict(&quot;10 der welt sind bei&quot;)</pre><p>Result:array([&#39;de&#39;], dtype=&#39;&lt;U2&#39;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ef3a78d144c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>