<?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 Shrey Shah on Medium]]></title>
        <description><![CDATA[Stories by Shrey Shah on Medium]]></description>
        <link>https://medium.com/@shahshrey?source=rss-7e1766f0d30d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PfoYmptWa_oTLdYSUT3zog.jpeg</url>
            <title>Stories by Shrey Shah on Medium</title>
            <link>https://medium.com/@shahshrey?source=rss-7e1766f0d30d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:55:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shahshrey/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[How we automated the design process in Autodesk Inventor!]]></title>
            <link>https://shahshrey.medium.com/how-did-we-automate-the-design-process-in-autodesk-inventor-384b9aa362e7?source=rss-7e1766f0d30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/384b9aa362e7</guid>
            <category><![CDATA[inventor]]></category>
            <category><![CDATA[c]]></category>
            <category><![CDATA[vb-net]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[autodesk]]></category>
            <dc:creator><![CDATA[Shrey Shah]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 19:50:46 GMT</pubDate>
            <atom:updated>2023-03-15T19:51:05.789Z</atom:updated>
            <content:encoded><![CDATA[<p>I work at a kitchen cabinet manufacturing company as a design engineer. The company offers fully customized cabinets to customers. But designing and manufacturing custom cabinets can be challenging. We use <a href="https://www.ptc.com/en/blogs/cad/parametric-vs-direct-modeling-which-side-are-you-on#:~:text=What%20Is%20Parametric%20Modeling%3F,in%20families%20of%20product%20parts.">Parametric model</a>ling to build custom cabinets.</p><p>We use Autodesk Inventor to design and validate all the kitchen cabinets. One of the reasons why we use Inventor is that with <a href="https://knowledge.autodesk.com/support/inventor/learn-explore/caas/CloudHelp/cloudhelp/2018/ENU/Inventor-Help/files/GUID-AB9EE660-299E-408F-BBE1-AFE44C723F59-htm.html">iLogic</a>, parametric models are easy to build. But a kitchen has many cabinets, with many custom dimensions, and parameters.</p><p>So how do you automate the whole kitchen design process? In this blog, I will talk about how I created some Inventor add-ins to automate the design process, where you fill out an excel spreadsheet with the list of cabinets you want with their parameters and run the add-in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*GSz3RcscUyl-XkSPkQKRLQ.gif" /><figcaption>¨Parametric modelling in Inventor with iLogic example”</figcaption></figure><p>Here I will explain a time study I performed to compare the improvements. For an average kitchen, there are usually between 10 and 20 cabinets. A typical kitchen design process is as below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ewjvFetbM01WgSn6o5OKA.png" /><figcaption>A typical kitchen production release process</figcaption></figure><p>It used to take on average 2 to 3 hours to create a new custom kitchen. You can see the breakdown below,</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fdatawrapper.dwcdn.net%2Fw68rB%2F4%2F&amp;display_name=Datawrapper&amp;url=https%3A%2F%2Fdatawrapper.dwcdn.net%2Fw68rB%2F4%2F&amp;image=https%3A%2F%2Fdatawrapper.dwcdn.net%2Fw68rB%2Fplain-s.png%3Fv%3D4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=dwcdn" width="600" height="446" frameborder="0" scrolling="no"><a href="https://medium.com/media/1690b8f0fb99c1264a98f11caa0725ce/href">https://medium.com/media/1690b8f0fb99c1264a98f11caa0725ce/href</a></iframe><p>To eliminate the repetitive steps in the design process, we built the add-ins for Inventor. And now the process looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*eYVIimm0LFVfYyAYhswYzw.png" /><figcaption>An automated process</figcaption></figure><p>Now let me walk you through the process. First, a user has to fill out the spreadsheet like below, (<em>Note- The string parameters are case-sensitive.) </em>It’s more like a shopping cart. You decide which cabinets you want, how many you want, and what parameters you need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XUA-Wo1dw8E-uH_TiADKA.png" /><figcaption>A spreadsheet as input for a new project</figcaption></figure><p>Now open a form called “Run Excel” from the add-in tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*AwZ03V54I5WivMulCByZSw.png" /><figcaption>Add-ins on the Inventor Ribbon</figcaption></figure><p>Now, select the project (like a catalogue) and copy the spreadsheet. Once the form is filled-up, hit the “OK” button. The program will start running silently. In a few minutes, the kitchen assembly will be complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*FYubN6Nsr-XxsmlOEKOdcg.png" /><figcaption>Excel Runner Form</figcaption></figure><p>There are other modules on the add-ins as well, like “Label Maker”, “Drawing Generator”, and “Hardware Suppressor”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*eo71cMGLwmRzfzs85i5MRg.png" /><figcaption>Assembly add-ins</figcaption></figure><p>We compared the time after implementing the add-ins and now it takes an average of 30–40 mins to create an average custom kitchen.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fdatawrapper.dwcdn.net%2FPUowV%2F3%2F&amp;display_name=Datawrapper&amp;url=https%3A%2F%2Fdatawrapper.dwcdn.net%2FPUowV%2F3%2F&amp;image=https%3A%2F%2Fdatawrapper.dwcdn.net%2FPUowV%2Fplain-s.png%3Fv%3D3&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=dwcdn" width="600" height="446" frameborder="0" scrolling="no"><a href="https://medium.com/media/84abc8de1b81d0f0440711da2558eb91/href">https://medium.com/media/84abc8de1b81d0f0440711da2558eb91/href</a></iframe><p>Future scope- We can further automate the process by replacing the manual excel input with an XML input, which is fed from ERP. Add-ins will be triggered as soon as a new XML file is created from ERP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=384b9aa362e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-time Reddit VADER Sentiment Analysis for Term Tracking in “worldnews” Subreddit!]]></title>
            <link>https://medium.com/data-science/real-time-reddit-vader-sentiment-analysis-for-term-tracking-in-worldnews-subreddit-bbd366d477c0?source=rss-7e1766f0d30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbd366d477c0</guid>
            <category><![CDATA[dash]]></category>
            <category><![CDATA[reddit]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Shrey Shah]]></dc:creator>
            <pubDate>Sat, 11 Jul 2020 05:11:38 GMT</pubDate>
            <atom:updated>2020-07-11T21:31:52.391Z</atom:updated>
            <content:encoded><![CDATA[<h4>Collecting Reddit Data using Streaming Reddit API with PRAW, POSTGRESQL, and Dash in Python.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvhPtKJKeHmbcXO4vWFHBg.jpeg" /></figure><p>In this brief tutorial, we will learn how to extract live 7stream data from Reddit using the Reddit API in Python and apply sentiment analysis. Reddit has a large userbase (<a href="https://www.statista.com/statistics/272014/global-social-networks-ranked-by-number-of-users/">almost 450 million</a>), and one of the most active subreddit is “<a href="https://www.reddit.com/r/worldnews/">worldnews</a>”. (<a href="https://redditmetrics.com/top">almost 25 million subscribers</a>). It’s good to know what people are talking about on this large platform.</p><figure><img alt="http://sentiment-reddit.herokuapp.com/" src="https://cdn-images-1.medium.com/max/1024/1*XF6JH3bsFJDbINd0fHUJpA.png" /><figcaption><a href="http://sentiment-reddit.herokuapp.com/">http://sentiment-reddit.herokuapp.com/</a></figcaption></figure><p><strong>You can try this </strong><a href="https://github.com/ZeroPanda/Reddit-Sentiment"><strong>code </strong></a><strong>on your computer.</strong></p><p><strong>Step One:</strong></p><p>The very first thing is to set up an app on your Reddit account. <a href="https://www.storybench.org/how-to-scrape-reddit-with-python/">Felippe Rodrigues</a> has a good tutorial on how to do so. Once you have the following information, you are good to move directly to python.</p><pre>reddit = praw.Reddit(client_id=&#39;PERSONAL_USE_SCRIPT_14_CHARS&#39;, \<br>                     client_secret=&#39;SECRET_KEY_27_CHARS &#39;, \<br>                     user_agent=&#39;YOUR_APP_NAME&#39;, \<br>                     username=&#39;YOUR_REDDIT_USER_NAME&#39;, \<br>                     password=&#39;YOUR_REDDIT_LOGIN_PASSWORD&#39;)</pre><p><strong>Step two:</strong></p><p>If you want to run this app on a local computer, you don’t need this step. It is time to set up a database account. I have used PostgreSQL since Heroku has great support for PostgreSQL. Create an app on Heroku and set up the database. <a href="https://medium.com/@vapurrmaid/getting-started-with-heroku-postgres-and-pgadmin-run-on-part-2-90d9499ed8fb">Gregory </a>has a good tutorial on that. Once you have the credentials, you can fill in the app.py and reddit_stream.py.</p><p>conn = psycopg2.connect(host = *****.compute-1.amazonaws.com, database = *********, password = ********)</p><p><strong>Step three:</strong></p><p>Install all the requirements from requirements.txt</p><p>Fill the values of conn and reddit in app.py and reddit_stream.py. On your local computer, run Reddit streaming app on the command prompt using simply</p><p>python reddit_stream.py</p><p>The script above streams the live threads from Reddit, and comments and replies for that thread and uses VADER Sentiment Analyser to provide the sentiment score. We use the compound sentiment score to store and display.</p><p>While the script is running and the database is filling up, let’s now display our app. To do so, simply run the app with the server. Use another command prompt for this code.</p><p>python app.py runserver</p><p>Do your modification in the app to display the graphs you want. <a href="https://dash.plotly.com/">Dash </a>has some pretty graphs, well-made documents and a nice community to help.</p><p><strong>Conclusion</strong></p><p>We scraped the data from Reddit and applied VADER Sentiment analysis on the text. We are using PostgreSQL to save our data and Dash app to display and deploy our app. If you think you can do this better way, please give it a chance.</p><h3><strong>Resources:</strong></h3><ul><li><a href="http://sentiment-reddit.herokuapp.com/">Real-Time Reddit Monitor</a></li><li><a href="https://github.com/ZeroPanda/Reddit-Sentiment">ZeroPanda/Reddit-Sentiment</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbd366d477c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/real-time-reddit-vader-sentiment-analysis-for-term-tracking-in-worldnews-subreddit-bbd366d477c0">Real-time Reddit VADER Sentiment Analysis for Term Tracking in “worldnews” Subreddit!</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Predicting the probability of SARS CoV-2 result using Multiple Logistic regressing in R and Python]]></title>
            <link>https://medium.com/data-science/predicting-the-probability-of-sars-cov-2-result-using-multiple-logistic-regressing-in-r-and-python-874cf9185d62?source=rss-7e1766f0d30d------2</link>
            <guid isPermaLink="false">https://medium.com/p/874cf9185d62</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[logistic-regression]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[r]]></category>
            <category><![CDATA[covid19]]></category>
            <dc:creator><![CDATA[Shrey Shah]]></dc:creator>
            <pubDate>Wed, 20 May 2020 21:31:22 GMT</pubDate>
            <atom:updated>2020-05-21T21:30:51.351Z</atom:updated>
            <content:encoded><![CDATA[<h3>Predicting the probability of SARS CoV-2 result using Multiple Logistic Regression in R and Python</h3><h4>Classifying the SARS CoV-2 patients and what variables affect the result.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XPBuKze0VjjgNp-AaLvS3g.jpeg" /><figcaption>Source: <a href="https://www.vexels.com/vectors/preview/191360/covid-19-background-design?ref=vexelsck&amp;tap_s=576618-2da5a0">VEXELS</a></figcaption></figure><p><strong><em>Note from the editors:</em></strong><em> </em><a href="http://towardsdatascience.com/"><em>Towards Data Science</em></a><em> is a Medium publication primarily based on the study of data science and machine learning. We are not health professionals or epidemiologists, and the opinions of this article should not be interpreted as professional advice. To learn more about the coronavirus pandemic, you can click </em><a href="https://www.who.int/emergencies/diseases/novel-coronavirus-2019/situation-reports"><em>here</em></a><em>.</em></p><h4><strong>Introduction</strong></h4><p>About two months ago, Brazil’s Hospital Israelita Albert Einstein published open data on <a href="https://www.kaggle.com/einsteindata4u/covid19">Kaggle </a>so that it can help to understand the novel Coronavirus better. So, I attempted to use this dataset to predict the probability of having SARS CoV-2 and to check what variables affect the most predicting SARS CoV-2 result.</p><p><strong>Background</strong></p><p>Until March 27, the state of São Paulo had recorded 1,223 confirmed cases of COVID-19, with 68 related deaths, while the county of São Paulo, with a population of approximately 12 million people and where Hospital Israelita Albert Einstein is located, had 477 confirmed cases and 30 associated death, as of March 23. Both the state and the county of São Paulo decided to establish quarantine and social distancing measures, that will be enforced at least until early April, to slow the virus spread.</p><p><strong>Dataset</strong></p><p>This dataset contains anonymized data from patients seen at the Hospital Israelita Albert Einstein, at São Paulo, Brazil, and who had samples collected to perform the SARS-CoV-2 RT-PCR and additional laboratory tests during a visit to the hospital.</p><p>The dataset has a total of 5644 rows and 111 columns.</p><p><strong>Variables(predictors) used in the analysis</strong></p><p>This article will not be enough to explain all the variables used. So, I will talk about some important predictors on the fly.</p><p>For the data preparation, I’ve used Pandas from Python. and for the logistic regression analysis, I’ve used R. Let’s now jump to the data preparation.</p><h4><strong>Data Preparation</strong></h4><p>The first glance at the dataset and I found many <em>NaN </em>values. This issue of missing values must be corrected before moving forward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ncjjx_lRUetyjL6LJ27G3g.png" /><figcaption>Values count by each column sorted in descending order</figcaption></figure><p>From here, I am separating the dataset into two subsets, named condition and disease. (they’re just names and don’t represent anything) The orange marked ones are the disease subset and green marked ones are the condition subset.</p><p>The missing values in variables <em>Neutrophils</em> and <em>Proteina C reativa </em>must be imputed. I’ve used KNNImputer to impute the missing values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfc8e3fdc5b015de0068058fac4e1882/href">https://medium.com/media/dfc8e3fdc5b015de0068058fac4e1882/href</a></iframe><p>For both the dataset, our target variable is <em>SARS_CoV2_exam_result.</em> The dataset disease has all the categorical predictors and the dataset condition has all the continuous numeric predictors.</p><p>For categorical variables, 0 is no disease detected and 1 is disease detected.</p><h4><strong>Analysis</strong></h4><p>From here, I will use R for our analysis. So let’s begin with the disease dataset.</p><p><strong>Disease dataset analysis</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmCHg9ECGQ7iYNEgfROZjQ.png" /><figcaption>disease dataset summary</figcaption></figure><p>I have to skip <em>Parainfluenza 2</em> as there are no cases for it. Now let’s plot the CramerV’s correlation plot to check the correlation between categorical variables.</p><pre># CramerV Correlation to check for any correlation between catagorical variables<br># Except Patient&#39;s age, all other variables are catagorical(binary)<br>&gt;disease.corr = PairApply(disease[,names(disease) != &quot;Patient_Age_Quantile&quot;],cramerV, symmetric = TRUE)<br># Displaying correlation with variable SARS_COV2_Result<br>&gt;disease.corr[,2]<br># Correlation plot<br>&gt;corrplot(disease.corr, method = &quot;square&quot;, type = &quot;lower&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hb19EUdF4zUq2r0pmEtPrg.png" /><figcaption>disease dataset correlation plot</figcaption></figure><p>The most significant predictor here seems <em>Rhinovirus_OR_Enterovirus</em> on our target with the correlation value of 0.1517. (not really significant) Now let’s divide dataset in 80% training and 20% test.</p><pre># Dividing Train/Test data with 80% training and 20% test<br>&gt;sample_size &lt;- floor(0.8 * nrow(disease))<br>&gt;train &lt;- sample(nrow(disease), size = sample_size)<br>&gt;disease.train &lt;- as.data.frame(disease[train,])<br>&gt;disease.test &lt;- as.data.frame(disease[-train,])</pre><p>Our dataset is not ready for logistic regression analysis.</p><pre># Logistic regression considering top predictors<br>&gt;disease.function = paste(&quot;SARS_COV2_Result&quot;, &quot;~&quot;, &quot;Patient_Age_Quantile + Rhinovirus_OR_Enterovirus&quot;)<br>disease.glm = glm(as.formula(disease.function), data = disease.train , family = binomial)<br>&gt;summary(disease.glm)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*VaE5VKchO1ovoQ-ylLthrQ.png" /><figcaption>summary of disease glm</figcaption></figure><p>Here P-value for both predictors <em>Patient_Age_Quantile</em> and <em>Rhinovirus_OR_Enterovirus</em> show great promise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*PCshgx4WIPbZQ0RqZLpudQ.png" /></figure><p>From the equation above, we can say that if a person has Rhinovirus, he/she has less likelihood of having SARS CoV2.</p><p>I’ve used 10-fold cross-validation to verify our model. The next step is to predict the values on the test dataset and preparing the confusion matrix.</p><pre># 10 fold cross-validation to verify the model<br>&gt;cv.glm(disease.train,disease.glm,K=10)$delta[1]</pre><pre># Predicting on test data based on training set<br>&gt;disease.glm.predict &lt;- predict(disease.glm,disease.test,type = &quot;response&quot;)<br>&gt;summary(disease.glm.predict)<br># Mean predict results for SARS Cov2 Results diagnosis<br>&gt;tapply(disease.glm.predict, disease.test$SARS_COV2_Result, mean)</pre><pre># Confusion matrix for threshold of 1%<br>&gt;disease.confusion = table(disease.test$SARS_COV2_Result, disease.glm.predict &gt; 0.01)<br>&gt;disease.confusion</pre><pre># False negative error(Type II error)<br>&gt;disease.type2error = disease.confusion[1,1]/<br>(disease.confusion[1,1]+disease.confusion[2,2])<br>&gt;disease.type2error</pre><p>I’ve put a tight threshold(1%) to minimize the type-II error. The model must minimize the number of falsely undetected patients. 60% of patients who have COVID-19 will be falsely detected negative from the model, which is quite high.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*seRna3g2waWvr0OqDLNHYA.png" /></figure><p>And as predicted, ROC curve is okayish.</p><pre># Plotting ROCR curve<br>&gt;disease.ROCRpred = prediction(disease.glm.predict, &gt;disease.test$SARS_COV2_Result)<br>&gt;disease.ROCRperf = performance(disease.ROCRpred, &quot;tpr&quot;, &quot;fpr&quot;)<br>&gt;par(mfrow=c(1,2))<br>&gt;plot(disease.ROCRperf, colorize=TRUE, &gt;print.cutoffs.at=seq(0,1,by=0.1), text.adj=c(-0.2,1.7))</pre><pre># Probability of SARS vs Rhinovirus plot<br>&gt;disease.predicted.data &lt;- data.frame(<br>  probability.of.having.SARS=disease.glm.predict,<br>  Rhinovirus=disease.test$Rhinovirus_OR_Enterovirus)<br>&gt;disease.predicted.data &lt;- disease.predicted.data[<br>  order(disease.predicted.data$probability.of.having.SARS, decreasing=FALSE),]<br>&gt;disease.predicted.data$rank &lt;- 1:nrow(disease.predicted.data)</pre><pre>&gt;plot(probability.of.having.SARS ~ Rhinovirus,disease.predicted.data, type = &quot;l&quot;, lwd = 2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*rKIjDoynbLEJWy6PVJ2EvA.png" /><figcaption>ROC plot and Probability of SARS vs Rhinovirus plot</figcaption></figure><p>The symptoms of Rhinovirus are close to the SARS CoV-2 virus and mostly found in the nose (<a href="https://en.wikipedia.org/wiki/Rhinovirus">Rhinovirus</a>). Therefore, the probability of having SARS decreases as Rhinovirus is detected.</p><p><strong>Condition dataset analysis</strong></p><p>Condition dataset has all numeric predictors, values taken from the blood samples. The data look normal from the summary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iOU5Z0qCOonM1JnEhT3R4A.png" /><figcaption>condition dataset summary</figcaption></figure><p>Repeating the same steps to apply logistic regression on the higher correlated predictors on the target variable.</p><pre># attaching the final dataset<br>&gt;attach(condition)</pre><pre># Correlation between varables<br>&gt;condition.corr = cor(condition)<br>&gt;condition.corr[,2]<br># Correlation plot<br>&gt;corrplot(condition.corr, method = &quot;square&quot;, type = &quot;lower&quot;)</pre><pre># Dividing Train/Test data with 80% training dataset<br>&gt;sample_size &lt;- floor(0.8 * nrow(condition))<br>&gt;train_ind &lt;- sample(nrow(condition), size = sample_size)<br>&gt;condition.train &lt;- as.data.frame(condition[train_ind,])<br>&gt;condition.test &lt;- as.data.frame(condition[-train_ind,])</pre><pre># Logistic regression considering all the variables on the targer variable SARS_COV2_Result<br>&gt;condition.function = paste(&quot;SARS_COV2_Result&quot;, &quot;~&quot;, &quot;Patient_Age_Quantile + Leukocytes + Eosinophils + Red_blood_cell_distribution_width_RDW + Platelets + Proteina_C_reativa_mg_dL&quot;)<br>&gt;condition.glm = glm(as.formula(condition.function), data = &gt;condition.train , family = binomial)<br>&gt;summary(condition.glm)</pre><pre># 10 fold cross-validation to verify the model<br>&gt;cv.glm(condition.train,condition.glm,K=10)$delta[1]</pre><pre># Predicting on test data based on training set<br>&gt;condition.glm.predict &lt;- predict(condition.glm,condition.test,type = &quot;response&quot;)<br>&gt;summary(condition.glm.predict)<br>&gt;tapply(condition.glm.predict, condition.test$SARS_COV2_Result, mean)</pre><pre># Confusion matrix for threshold of 1%<br>&gt;condition.confusion = table(condition.test$SARS_COV2_Result, condition.glm.predict &gt; 0.01)<br>&gt;condition.confusion</pre><pre># False negative error rate (Type II error)<br>&gt;condition.type2error = condition.confusion[1,1]/ (condition.confusion[1,1]+condition.confusion[2,2])<br>&gt;condition.type2error</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLO5WeML0AJsDptvFGLPPA.png" /><figcaption>condition dataset correlation plot</figcaption></figure><p>Here we see some highly correlated variables. However, we only consider the predictors who have a high correlation to the target variable. So for the analysis, I will use <em>Patient_Age_Quantile , Leukocytes , Eosinophils , Red_blood_cell_distribution_width_RDW , Platelets , and Proteina_C_reativa_mg_dL </em>predictors. Let’s take a look at the glm summary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*b_g8X0UdjdfmyvqEDOuUzQ.png" /><figcaption>condition dataset glm summary</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQbxtO8whYKuwU1zoVgguA.png" /></figure><p>Let’s predict the error on our test dataset. With this model, 30 cases out of 121 cases gave false results and the ROC curve is better than the previous model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fd95lNlUevCidWFGg-a2MQ.png" /></figure><pre># Plotting ROCR curve<br>&gt;condition.ROCRpred = prediction(condition.glm.predict,    condition.test$SARS_COV2_Result)<br>&gt;condition.ROCRperf = performance(condition.ROCRpred, &quot;tpr&quot;, &quot;fpr&quot;)<br>&gt;plot(condition.ROCRperf, colorize=TRUE, print.cutoffs.at=seq(0,1,by=0.1), text.adj=c(-0.2,1.7))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*1nXh6ll9N0Nr8mmBl19DPg.png" /><figcaption>condition dataset ROC curve</figcaption></figure><p>Plotting the results,</p><pre># Creating a dataframe with variables and predicted values of SARS results<br>&gt;condition.predict.dataframe &lt;- data.frame(<br>  probability.of.having.SARS=condition.glm$fitted.values,<br>  Leukocytes=condition.train$Leukocytes,<br>  Patient_Age_Quantile = condition.train$Patient_Age_Quantile,<br>  Eosinophils = condition.train$Eosinophils,<br>  Red_blood_cell_distribution_width_RDW = &gt;condition.train$Red_blood_cell_distribution_width_RDW,<br>  Platelets = condition.train$Platelets,<br>  Proteina_C_reativa_mg_dL = &gt;condition.train$Proteina_C_reativa_mg_dL)</pre><pre>&gt;plot1 = ggplot(data=condition.predict.dataframe, aes(x=Patient_Age_Quantile, y=probability.of.having.SARS)) +<br>  geom_point(aes(color=Patient_Age_Quantile), size=4)<br>&gt;plot2 = ggplot(data=condition.predict.dataframe, aes(x=Leukocytes, y=probability.of.having.SARS)) +<br>  geom_point(aes(color=Leukocytes), size=4)<br>&gt;plot3 = ggplot(data=condition.predict.dataframe, aes(x=Red_blood_cell_distribution_width_RDW, y=probability.of.having.SARS)) +<br>  geom_point(aes(color=Red_blood_cell_distribution_width_RDW), size=4)<br>&gt;plot4 = ggplot(data=condition.predict.dataframe, aes(x=Eosinophils, y=probability.of.having.SARS)) +<br>  geom_point(aes(color=Eosinophils), size=4)<br>&gt;plot5 = ggplot(data=condition.predict.dataframe, aes(x=Platelets, y=probability.of.having.SARS)) +<br>  geom_point(aes(color=Platelets), size=4)<br>&gt;plot6 = ggplot(data=condition.predict.dataframe, aes(x=Proteina_C_reativa_mg_dL, y=probability.of.having.SARS)) +<br>  geom_point(aes(color=Proteina_C_reativa_mg_dL), size=4)<br># Plotting the values<br>&gt;grid.arrange(plot1, plot2, plot3, plot4, plot5, plot6, ncol=3 , nrow = 2)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9XpoQqOjwGOatIRSG2mPTQ.png" /><figcaption>Probability of having SARS vs predictors</figcaption></figure><p>We can see that <em>patient&#39;s age quantile </em>and <em>Proteina C reativa</em> have a positive correlation, and the rests have a negative correlation with the probability of the target variable.</p><p><strong>Investigation of the predictors separately</strong></p><p>Some of the predictors show great promise when analyzed separately. Those predictors are,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*GvnJ1FWL2S-eMvpXKk-O1g.png" /></figure><p>I will now create a function that analyzes each of those variables to see their effects.</p><pre># Plotting Seperate probability graphs<br>&gt;plotting.function &lt;- function(var,variableORrank){<br>  condition.sep.function = paste(&quot;SARS_COV2_Result&quot;, &quot;~&quot;, as.character(var))<br>  condition.sep.glm = glm(as.formula(condition.sep.function), data = condition.train , family = binomial)<br>  print(summary(condition.sep.glm))<br>  cv.glm(condition.train,condition.sep.glm,K=10)$delta[1]<br>  <br>  condition.predicted.data &lt;- data.frame(<br>    probability.of.SARS=condition.sep.glm$fitted.values,<br>    variable=condition.train[,as.character(var)])<br>  <br>  condition.predicted.data &lt;- condition.predicted.data[<br>    order(condition.predicted.data$variable, decreasing=FALSE),]<br>  <br>  condition.predicted.data$rank &lt;- 1:nrow(condition.predicted.data)<br>  <br>  ggplot(data=condition.predicted.data, aes(x= variable, y=probability.of.SARS)) +<br>    geom_point(aes(color=variable), size=3) +<br>    xlab(as.character(var)) +<br>    ylab(&quot;Probability of having SARS CoV-2&quot;) +<br>    scale_colour_gradient(low = &quot;darkgreen&quot;, high = &quot;darkred&quot;, na.value = NA) +<br>    ggtitle(coef(summary(condition.sep.glm))[,&#39;Pr(&gt;|z|)&#39;])<br>}</pre><pre>&gt;plotfun1 = plotting.function(&quot;Platelets&quot;)<br>&gt;plotfun2 = plotting.function(&quot;Monocytes&quot;)<br>&gt;plotfun3 = plotting.function(&quot;Hemoglobin&quot;)<br>&gt;plotfun4 = plotting.function(&quot;Red_blood_cells&quot;)<br>&gt;plotfun5 = plotting.function(&quot;Mean_platelet_volume&quot;)<br>&gt;grid.arrange(plotfun1, plotfun2, plotfun3, plotfun4, plotfun5, ncol=3 , nrow = 2)</pre><p>And the results are,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRDbBhi6RD4XhK0DQqQafQ.png" /><figcaption>Prob of having SARS vs single predictor analysis (Graph titles are the Pr(&gt;|z|) values, the lower the better) (monocytes are a type of white blood cells and hemoglobin is an iron-containing oxygen-transport metalloprotein)</figcaption></figure><p>Except for <em>platelets</em>, all predictors have a positive correlation on the probability of having SARS CoV-2.</p><h3><strong>Conclusion</strong></h3><p>For the hospitals, it is important to distinguish between a person with Rhinovirus and a person with COVID-19. Separating patients with Rhinovirus and COVID-19 will make the process a lot faster.</p><p>High %vol of white blood cells indicate that the body is fighting against the virus.</p><p>While having the virus, the body is not producing enough platelets which help to stop bleeding.</p><p>With the given patient’s blood data, the model can predict the probability of having SARS CoV-2.</p><h3><strong>Code used in the analysis</strong></h3><p><a href="https://github.com/ZeroPanda/COVID-19-Regression-Analysis">ZeroPanda/COVID-19-Regression-Analysis</a></p><h3><strong>References</strong></h3><p><a href="http://faculty.marshall.usc.edu/gareth-james/ISL/ISLR%20Seventh%20Printing.pdf">An Introduction to Statistical Learning with Applications in R</a>; Gareth James, Daniela Witten, Trevor Hastie, Robert Tibshirani</p><ul><li><a href="https://www.kaggle.com/einsteindata4u/covid19">Diagnosis of COVID-19 and its clinical spectrum</a></li><li><a href="https://www.wikipedia.org/">Wikipedia, the free encyclopedia</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=874cf9185d62" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-the-probability-of-sars-cov-2-result-using-multiple-logistic-regressing-in-r-and-python-874cf9185d62">Predicting the probability of SARS CoV-2 result using Multiple Logistic regressing in R and Python</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>