<?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 Shruti Nk on Medium]]></title>
        <description><![CDATA[Stories by Shruti Nk on Medium]]></description>
        <link>https://medium.com/@potatoinpyjamas?source=rss-1336b5ab615b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NWBaYD4pEBQRIKcQLNr1rw.jpeg</url>
            <title>Stories by Shruti Nk on Medium</title>
            <link>https://medium.com/@potatoinpyjamas?source=rss-1336b5ab615b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:01:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@potatoinpyjamas/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[Disease Prediction: With RFC and Flask]]></title>
            <link>https://medium.com/ieee-ras-vit/disease-prediction-with-rfc-and-flask-1608885ef4c5?source=rss-1336b5ab615b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1608885ef4c5</guid>
            <category><![CDATA[random-forest-classifiers]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Shruti Nk]]></dc:creator>
            <pubDate>Sun, 22 Nov 2020 06:23:36 GMT</pubDate>
            <atom:updated>2020-11-22T06:40:38.876Z</atom:updated>
            <content:encoded><![CDATA[<p>Machine learning has always fascinated me. The ability to analyse large amounts of data and then being able to obtain conclusive results effeciently is what makes it such a sought out skill. The beauty of this is however when we are actually able to put the concepts to use and implement them on real life problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/0*BocNihzpQZGyVFdI.png" /></figure><p>Which brings me to this article. Here I will guide you through a model that gives a probable estimation of a disease contracted on the basis of the three entered symptoms. I trained this model using the Random Forest Classifier which I then linked to a Flask framework.</p><p>So let’s get started!</p><h3>Model</h3><p>The data obtained from the dataset was fairly clean and was already sorted into training and testing csv files.</p><pre>train = pd.read_csv(&quot;training_data.csv&quot;,error_bad_lines = False)<br>test = pd.read_csv(&quot;test_data.csv&quot;,error_bad_lines = False)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XOvCNTg2N1jzkKmhaeqxeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1A1IYmWsQdFMF4DB5dJ40w.png" /></figure><p>The data set had 132 symptoms linked to 41 diseases.</p><p>I then proceeded to split the data into x and y.</p><pre>y_test = test.prognosis<br>x_test = test.drop(&#39;prognosis&#39;,axis = 1)</pre><h4>Visualisation</h4><p>To visualise the data we are dealing with, I dedcided to make a simple count plot.</p><pre>f,ax = plt.subplots(figsize=(75,16))<br>sns.countplot(y_train,label=&quot;Count&quot;,ax = ax)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yp_yXSe4wOo74qL4RQX9lw.png" /><figcaption>countplot for the column prognosis</figcaption></figure><p>On observing the data. I was able to conclude that no normalisation was required as the values were distributed evenly.</p><h4>Model Training</h4><p>This seemed to be a fairly starightforward classification problem so I used the Random Forest Classification algorithm to train and test my model.</p><pre>clf_rf = RandomForestClassifier(random_state=43)      <br>clr_rf = clf_rf.fit(x_train,y_train)</pre><h4>Accuracy</h4><pre>ac = accuracy_score(y_test,clf_rf.predict(x_test))</pre><p>The model gives us an accuracy of <strong>97.62%</strong></p><p>Before we move on however, there is one important step remaining. To link the model to Flask, you should first write it into a pickle file which is then read by the Flask app.</p><p>Luckily for us, all we need to do is import the pickle library and use the dump function to write into the file.</p><pre>pickle.dump(clr_rf,open(&#39;model.pkl&#39;,&#39;wb&#39;))</pre><p>And with that you are done with the first section!</p><h3>Flask</h3><p>Flask is one of the most popular frameworks used and is honestly quite easy to implement. Well, incase you do not know what a framework is, it is nothing but a code library that makes a developer’s life easier when building reliable, scalable and maintainable web applications by providing reusable code or extensions for common operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*P4oqMX5pziNLZ_i1u_1x3A.png" /><figcaption>A simple flask application</figcaption></figure><p>Now that we have gone over the basic definition, let’s get down to creating this framework. First let’s ensure we read the data stored in the pickle file so that we can access it here as well.</p><pre>model = pickle.load(open(&#39;model.pkl&#39;, &#39;rb&#39;))</pre><p><strong>Routing</strong></p><p>Next let’s draw our attention to the <em>@app.route(). </em>Here I will be using it twice. First for returning my HTML page and the second for returning the accuracy value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*YzW7SU0E0haex5ITT3xw9A.png" /><figcaption>returns the html page</figcaption></figure><p>Since the input type is in the form of a string, all I have done is taken in the values from the form and then convereted it into a 2D binary array so that I can feed those values into my predict function.</p><pre>if request.method == &#39;POST&#39;:<br>    col = x_test.columns<br>    inputt = [str(x) for x in request.form.values()]<br>    b = [0]*132<br>    for x in range(0, 132):<br>        for y in inputt:<br>            if (col[x] == y):<br>                b[x] = 1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QWYJhni02iu67GfSBKhajg.png" /><figcaption>returns the accuracy value in the html page</figcaption></figure><p>Don’t forget to add-in this last condition to ensure that you application runs smoothly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*rKzKayiyUIMcliUllo1-Og.png" /></figure><p>And with that you are done with the second part!</p><h3>HTML</h3><p>This is by far the easiest of the three. Now all that you are left to do is design an HTML page to improve the user experience. Incase you have no prior HTML knowledge, you can just pick up one of the many templates and tweak it a bit.</p><h4>1st tweak</h4><p>To be done wherever you want your accuracy statement to be displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*QvyjZ8Zmvm4FaHt9UF02ew.png" /></figure><p>If you remember, in the second routing statement, we assigned the predicted value to this variable and then returned it. This value then gets called and displayed on your HTML.</p><h4>2nd tweak</h4><p>Ensure you have your form with an action defined as predict and the method as post. This will help you read in your values which the user enters into the HTML and then send it to your Flask app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*MBsBZN6_BDp4wrAaSIet3A.png" /></figure><p>And with this you have completed all the three steps and should be able to successfully link your Flask app to your ML model.</p><p>This is how mine turned out 🍕</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nHaQTV5CmfPq1Ic7.png" /><figcaption>home page with the option to enter 3 symptoms</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QYPK_3X3cplUbqEo.png" /><figcaption>use css and js to make your page interactive ✨</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*1g2GHnY_o6vd8ZIeVILfOA.png" /><figcaption>click on predict to give you a probable diagnosis!</figcaption></figure><p><em>All the codes are available on my github.</em></p><p><a href="https://github.com/PotatoinPyjamas/Disease-Prediction"><em>https://github.com/PotatoinPyjamas/Disease-Prediction</em></a></p><p><em>If you liked the article please don’t hesitate to show your ❤ .</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1608885ef4c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ieee-ras-vit/disease-prediction-with-rfc-and-flask-1608885ef4c5">Disease Prediction: With RFC and Flask</a> was originally published in <a href="https://medium.com/ieee-ras-vit">IEEE-RAS VIT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>