<?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 Adnan Khan on Medium]]></title>
        <description><![CDATA[Stories by Adnan Khan on Medium]]></description>
        <link>https://medium.com/@adnankhanx?source=rss-122f963ab5da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uoIeRcC_aCeinPfuMKd8AA.jpeg</url>
            <title>Stories by Adnan Khan on Medium</title>
            <link>https://medium.com/@adnankhanx?source=rss-122f963ab5da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 13:39:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adnankhanx/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[Snowflake — part 1]]></title>
            <link>https://medium.com/analytics-vidhya/snowflake-part-1-93787172ea1f?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/93787172ea1f</guid>
            <category><![CDATA[snowflake-computing]]></category>
            <category><![CDATA[data-ware-housing]]></category>
            <category><![CDATA[snowflake]]></category>
            <category><![CDATA[snowflakedb]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Sat, 20 Jan 2024 07:08:39 GMT</pubDate>
            <atom:updated>2024-01-20T07:13:36.630Z</atom:updated>
            <content:encoded><![CDATA[<h3>Snowflake — History, Architecture &amp; Features</h3><p>In this guide about the snowflake, we will explore the background, how it come to existence, its architecture, and the features of the snowflake. I’ll posting more in this series continuation for further dig down into snowflake (SF) features.</p><h3><strong>History!!!</strong></h3><p>Before diving deep into the snowflake, I thought to bring some history about the snowflake.</p><p>Snowflake was founded back in 2012 in San Mateo, California. Its name was decided by the founder, because of their love for snow sports. For keeping it two years in stealth mode, it was publicly launched in October,2014.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTABuSthkRifjt5ZMP_dDA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dariuscotoi?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Darius Cotoi</a> on <a href="https://unsplash.com/photos/snow-flak-illustration-d8cKjamtQH4?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h3><strong>Snowflake</strong></h3><p>Snowflake is a cloud-based data warehousing solution. It’s built from scratch(cloud-native), optimized for cloud (AWS/GCP/Azure).</p><p>Snowflake is SaaS (Software as a Service) product or DWaaS (Data Warehouse as a Service) with ANSI SQL support, where there’s no software, infrastructure or upgrades are managed, instead Snowflake will take care for this and will be available to you.</p><p>With Pay-as-you-go model, storage &amp; compute decoupled you will be charged for compute and storage separately, can scale as needed independent of each other.</p><p>If this doesn’t make sense now don’t worry and stick together, we will discuss each of these concepts ahead.</p><h3><strong>Architecture</strong></h3><p>Before discussing the architecture let’s first explore the layers</p><ul><li><strong>Storage Layer</strong>: Underneath utilizes the cloud storage for storing.</li><li><strong>Query Processing Layer</strong>: Also called virtual warehouse, provides the compute.</li><li><strong>Cloud Service Layer</strong>: Responsible for multiple tasks like controlling Account Access, generating query plan and others.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*CvlaVlxdU_5rQnej.png" /><figcaption>Photo by <a href="https://www.snowflake.com/">Snowflake</a></figcaption></figure><p>Let&#39;s deep dive into each of the layer.</p><ul><li><strong>Storage Layer</strong><br>As the name says itself is responsible for storing the data. The snowflake is responsible for reorganizing the data into its internal optimized columnar format, which is immutable. Under the hood the snowflake utilizes the cloud storage (AWS S3, Azure Blob, Google Cloud Storage), and the user cannot access the data except SQL. Each table is divided into micro-partitions which contains the portion of the data.</li><li><strong>Compute / Query Processing Layer<br></strong>The processing of the query happens at this layer by using the “virtual warehouse”, which a compute resource and provides the required resources like memory, CPU to perform the operations.<br>Multi-cluster architecture can also be created that means you can activate multiple virtual warehouses at the same time which are independent of each other and cannot affect the performance of the other warehouse.</li><li><strong>Cloud Service Layer<br></strong>This layer is responsible for multiple activities which are carried out by the snowflake under the hood like authentication of the user &amp; access control, management of the infrastructure, metadata management, query processing &amp; optimization, and Security.</li></ul><h3><strong>Snowflake Features</strong></h3><p><strong>1- Near-Zero Mangement:<br></strong>Snowflake is a cloud-native warehousing platform, which offer near-zero management by eliminating the need of the administrative overhead. Plenty of the things related to the management is handled by snowflake internally which allows the organization to focus more on the data instead of the management.</p><p><strong>2- Time-travel</strong><br>Time travel is a native Change Data Capture (CDC) feature to ensuring the continued availability of the data that has been changed or deleted. Historical data in permanent databases and database objects can be queried, cloned or restored for a maximum of 90 days. Whereas data in transient and temporary objects can be accessed maximum up to 24 hours.<br>The time-travel retention period is by default enabled for each of the snowflake accounts and the default is 24 hours; however it can altered as per the requirements.</p><pre>Alter database DEMODB SET DATA_RETENTION_TIME_IN_DAYS = 90;</pre><p>The three ways to go back in the time-travel:<br>1- Specific time in past<br>2- Going back certain amount of time from now<br>3- Query ID (SF assign unique query id each time you execute query).</p><p><strong>3- Fail-safe:</strong><br>Once the maximum time-travel period ends the data is moved to fail-safe state which can be recovered by snowflake employees up to seven days later.</p><p><strong><em>Note</em></strong><em>: The time-travel feature for temporary and transient objects is 24 hours and there’s no fail-safe state for them. The difference is that transient data isn’t once the session end and default session-timeout in snowflake is 4 hours.</em></p><p><strong>4- Replication and Failover:</strong><br>Snowflake supports replication across region and across cloud platforms, which enables an organization to replicate databases between snowflake accounts. The objects are replicated physically which incurs the additional storage cost for the any cloned object along with data transfer and compute charges.</p><p><strong>5- Zero-copy cloning:<br></strong>This feature allows to duplicate the data without actually creating the physical copy, which avoids storage cost. Changes made to the cloned object are local to the cloned object and will not affect the source. Similarly, the changes made to the source after cloning will not affect the clone.</p><p><strong>6- Snow task:<br></strong>The built-in schedular to schedule your queries or stored procedures with snowflake by using the time in minutes alternatively you can provide the time in CRON format.</p><p><strong>7- Data masking:<br></strong>Snowflake provides a feature to mask the data either dynamically, statically or conditionally. Data masking is column-based security, which allows to hide the sensitive information from the user that are unauthorized to view the sensitive information inside the table.</p><p><strong>8- Row-level security:<br></strong>Row-level security allows user to only show the limited number of rows to the user based on the region or role thresholds. Suppose in sales table the employees can only see the sales from their region and not the other regions in that case we can apply the row-level security.</p><p>There’re plenty of other features that snowflake offers like performance, scalability, availability, sharing and collaboration along with the other mentioned above.</p><p>If you want to learn more about the snowflake there’re great resources out there. I’ll mention few of them below:<br>1. <a href="https://docs.snowflake.com/">Snowflake Documentation</a><br>2. <a href="https://www.youtube.com/@DataEngineering">(4) Data Engineering Simplified — YouTube</a><br>3. <a href="https://www.snowflake.com/resource/snowflake-definitive-guide/">Snowflake: The Definitive Guide from O’Reilly</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93787172ea1f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/snowflake-part-1-93787172ea1f">Snowflake — part 1</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embed Power BI Visualization in Website]]></title>
            <link>https://medium.com/analytics-vidhya/embed-power-bi-visualization-in-website-8ef8be9c3977?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ef8be9c3977</guid>
            <category><![CDATA[report]]></category>
            <category><![CDATA[power-bi-tutorials]]></category>
            <category><![CDATA[dashboard]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[embedding]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Sat, 16 Jul 2022 07:45:44 GMT</pubDate>
            <atom:updated>2022-07-16T07:52:51.546Z</atom:updated>
            <content:encoded><![CDATA[<p>Explore how to embed Power BI visualization in website by following four easy steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtJeCka-IbI3z1HfoX8scg.jpeg" /><figcaption>Source: <a href="https://unsplash.com/@lukechesser">Luke Chesser</a></figcaption></figure><p>I assume that you’re aware of the Power BI Desktop and Power BI Services, and you do have account as well. If not you can easily Create your account <a href="https://powerbi.microsoft.com/en-au/">here</a> and download the Power BI desktop.</p><p>I was practicing the Power BI and came with an Idea to build a decomposition tree (a visualization) Which shows my Name, Domain and skills I do have. Finding it difficult to understand? No worries, The below Image represent what it will looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F_F4Yctryolxkp9rChHVjg.jpeg" /><figcaption>End result we want to achieve</figcaption></figure><p>The steps we will follow</p><p>1- Dataset<br>2- Import in power BI and visualize<br>3- Publish to Power BI Services<br>4- Embed in Website</p><p>1- <strong>Dataset</strong><br> As you’re working on your own skills so you have to make dataset on your own. It not difficult as we only need few data-points for this. My dataset only include three columns U<strong>sername</strong>, D<strong>omain</strong> and S<strong>kills. </strong>Once the dataset is ready it will looks something like this</p><pre>| Username | Domain           | Skills  |<br>| ---      | ---              | ---     |<br>| Adnan    | Data Engineering |  ETL    |<br>| Adnan    | Data Science     |  Python |</pre><p><strong>2- Import in Power BI<br></strong>Now that you’ve your dataset you can import in Power BI by using <strong>Get Data</strong> option. Select the dataset you’ve saved in previous step and select import if not any cleansing required, make sure that Username, Domain and Skills are header in Power BI table. Once you imported the data you can play around like you want. Now your Power BI interface will look this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HtY2F9ClQrOQOUEn6E2P5w.jpeg" /><figcaption>Power BI Interface</figcaption></figure><p>As in start we mentioned we will work on decomposition tree, from visualization pane select decomposition tree, drag and drop the columns from dataset into decomposition Analyze and explain by fields as shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UXDOGiItqV6iQujUq9_6GA.jpeg" /><figcaption>Decomposition tree</figcaption></figure><p>Now rename the username column in Analyze field to your name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keL8l2tU13pkNC0ydOKEbg.jpeg" /></figure><p><strong>3- Publish</strong><br>Now we got what exactly we wanted you can play around different parameters to set the colors of Bar, change headers etc. Once all the changes are done publish it to Power BI services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60N6DfH2s8igjvg5uRwWSg.png" /><figcaption>Publishing Report</figcaption></figure><p>The report is published to your desired workspace. Workspace is nothing but an environment where multiple people can work together on a report based on role assigned to them.</p><p><strong>4- Embedding in website</strong><br>Now go to <a href="https://app.powerbi.com/">Power BI Service</a> and open the report you published, click on File in top menu select Embed report and select to Website or portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7n88kxa9qoRTnUT3Vh0Nw.png" /><figcaption>Embedding Report</figcaption></figure><p>Note: If you want to be visible to public you can use select the <strong>Publish to web(Public) </strong>but for it you will require an administrator permission or access. As I don’t have that so I’m selecting <strong>Website or Portal</strong> option.</p><p>After selecting the Website or Portal option popup will appear from where you can copy the link</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*Dt6s8gbRZs2TnxVN49DeoQ.png" /><figcaption>Link to Embed Report</figcaption></figure><p>you can use this link to embed report in your website. I already have the one so I’ll integrate it in it. Simply pasted this code website and bamm!!! we’re done. The end result will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwHYf8dYnz17xxzzYvCUnA.jpeg" /><figcaption>Website view</figcaption></figure><p>This embedded visualization is interactive and behave in a similar fashion as it was in Power BI Desktop. Easy peasy? follow back to not miss the upcoming articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef8be9c3977" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/embed-power-bi-visualization-in-website-8ef8be9c3977">Embed Power BI Visualization in Website</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Done with your first ML project with in 3 minutes! SONAR- Mine VS Rock]]></title>
            <link>https://adnankhanx.medium.com/done-with-your-first-ml-project-with-in-5-minutes-sonar-mine-vs-rock-325cbad69aa1?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/325cbad69aa1</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Mon, 28 Jun 2021 14:05:26 GMT</pubDate>
            <atom:updated>2021-06-28T14:08:42.612Z</atom:updated>
            <content:encoded><![CDATA[<p>Applying ML over the simpler problems isn’t that much difficult you just need to remember some steps to perform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Gv4JdRIRoFjZyZ7.jpg" /><figcaption>Source Tribune.com.pk</figcaption></figure><p><strong>Problem</strong></p><p>You’re a Pirate or Captain of Marine but I think Pirate will suit you and planning to attack the Diamond mine under water near some country, that country has protected the Diamond mine with some <strong>Mines</strong>(explosion) and <strong>Rocks </strong>it’s difficult to differentiate to find out which one is Mine and which one is Rock. But the luck here is you have data and you can different among them which one is Mine and which one is Rock.</p><p><strong>Step 1</strong></p><p>Just import all the required dependencies you can read about individual library, Just by going through the documentation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9023a13beeb8ccd04dfefe59e74ca5d8/href">https://medium.com/media/9023a13beeb8ccd04dfefe59e74ca5d8/href</a></iframe><p><strong>Step 2</strong></p><p>Read the data through file by using pandas. Our data is stored in csv format so we will use .read-csv. It will simply read the values from CSV formatted file and stored it as a Data frame.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52289c0d6a9e1e850c35b9f654090087/href">https://medium.com/media/52289c0d6a9e1e850c35b9f654090087/href</a></iframe><p>Our data look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HEl1vQmq6uKtMGZYbSoV9g.png" /></figure><p><strong>Step 3</strong></p><p>Know about your data the more you know the better you will handle the handle. However the following dataset don’t contain any information about the columns but still you can note the distribution of data and summary of the data and detect outliers in dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e337ee731fe4084aa9150a7de0aab48f/href">https://medium.com/media/e337ee731fe4084aa9150a7de0aab48f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hpb8giQyp-236sE9Lc_24g.png" /></figure><p><strong>Step 4</strong></p><p>Lets find the distribution of the target variable. If the data isn’t distributed then take appropriate steps to equally distribute the data.<br>You can see that distributed is slightly imbalance but its acceptable. Almost none of the data is equally distributed.</p><p><strong>R</strong> in target variable represent <strong>Rock</strong> and <strong>M</strong> represent <strong>Mine.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eb7bac50f58f93d5426e36daf001447/href">https://medium.com/media/4eb7bac50f58f93d5426e36daf001447/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*7LUBvzJFjdiCffeGCQVmjw.png" /></figure><p><strong>Step 5</strong></p><p>Separate the <strong>target </strong>and <strong>features </strong>in a dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ed54a3d2e8a304db53fa91c94e95ea6/href">https://medium.com/media/9ed54a3d2e8a304db53fa91c94e95ea6/href</a></iframe><p><strong>step 6</strong></p><p>Split the data into train and test set. The train set will be utilized for the training the model and test set will be used to validate the model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1369c122cd01f3827e3315ee5b13b23d/href">https://medium.com/media/1369c122cd01f3827e3315ee5b13b23d/href</a></iframe><p><strong>step 7</strong></p><p>Select your model there isn’t any hard and fast rule to select model you have to try multiple models and select the one which outperform among others. However we’re just using Logistic regression you can find the intuition behind Logistic Regression through google.</p><p>Model is fitted over the data and then making predictions over the test data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd7389cda9b80797ce2a421c39494316/href">https://medium.com/media/cd7389cda9b80797ce2a421c39494316/href</a></iframe><p><strong>step 8</strong></p><p>Model evaluate helps you in figuring out the best model there’re different metrics used for Classification and Regression. As this problem is related to classification so we can use different metrics like confusion matrix, F1-Score and some others. You can read about the classification metrics <a href="https://medium.com/geekculture/metrics-for-classification-confusion-matrix-43ee441d2947?source=---------1----------------------------">here</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/467df8a0ca595a65c07334f12f5a3036/href">https://medium.com/media/467df8a0ca595a65c07334f12f5a3036/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*jRmOtnrVrdx1RVXDhmeLfw.png" /><figcaption>Confusion Matrix</figcaption></figure><p>Tada!!! That’s all it you’re done with your beginner level ML Project.</p><p><strong>Conclusion</strong></p><p>This project was related to classification of Rocks vs Mines. You simply perform some statistical operation and data separation to train and evaluate your model.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=325cbad69aa1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Metrics for Classification- Confusion Matrix]]></title>
            <link>https://medium.com/geekculture/metrics-for-classification-confusion-matrix-43ee441d2947?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/43ee441d2947</guid>
            <category><![CDATA[recall]]></category>
            <category><![CDATA[f1-score]]></category>
            <category><![CDATA[precision]]></category>
            <category><![CDATA[confusion-matrix]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Fri, 18 Jun 2021 13:34:30 GMT</pubDate>
            <atom:updated>2021-06-25T12:22:09.830Z</atom:updated>
            <content:encoded><![CDATA[<p>All you should know about the confusion matrix to evaluate your classification model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*qqnh0GmmMQh2Qoi9" /><figcaption>unsplash.com</figcaption></figure><p><em>True Positive, False Positive, True Negative, False Negative</em>? Tired of searching them out again and again and still don’t remember it? No problem that happened to most of the beginners but once you have the better understanding about the intuition behind it you get comfortable with these terminologies.</p><p>So let’s get started with Confusion Matrix which is the base. Better the understanding of Confusion Matrix the more easy will be the understanding of all the metrics. What actually is <strong>Confusion Matrix</strong>?</p><p><strong>Confusion Matrix</strong></p><p>As it name refers it confuses the people :D (That was joke) I will try to make it simple instead of writing the original definition</p><blockquote>A confusion matrix is basically a metrics to evaluate your classification ML model. It’s a square matrix whose dimensions are totally depended upon the number of classes.</blockquote><p>Let suppose you’re classifying the animals as <strong>cat vs dog</strong>. In that case the dimension will be 2 and if you increase the categories to <strong>cat vs dog vs monkey</strong> then dimension will increase to 3. With the increase in the number of classes in target variable the dimensions will keep increasing accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*T1bjQ-MKmaAUlggWWqK7Qg.png" /><figcaption>CONFUSION MATRIX</figcaption></figure><p>So what actually is <em>True Positive, False Positive, True Negative, False Negative? </em>Lets understand it through the example of <strong>cat</strong> vs <strong>dog</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*_WBcmwACS2gcBImMmQMzVg.png" /></figure><p>So True positive is when class if <strong>positive</strong> and model classified it as <strong>positive</strong>, True Negative is when class is <strong>negative</strong> and model classified it as <strong>negative. </strong>Similarly the <strong>positive </strong>class classified by model as <strong>negative </strong>is <strong>False Positive</strong> and <strong>negative </strong>class classified by model as <strong>positive </strong>is <strong>False Negative. </strong>I hope you have the understanding of these terminologies by now. If still not go through it again as it’s base.</p><p>In Python, That’s how you can create a confusion matrix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f122959f8076130bb94d6f395210c0a7/href">https://medium.com/media/f122959f8076130bb94d6f395210c0a7/href</a></iframe><p>Accuracy</p><p>The ratio of classes classified correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*1gIAtsLqL3-967PjniYm-Q.png" /></figure><p>The formula for Accuracy is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*zxINzw-AyDK5yLoAA5wSuQ.png" /><figcaption>ACCURACY FORMULA</figcaption></figure><p>By using Scikit-Learn you can compute accuracy of the model like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11a6fde32e689cce313e52c107b0e586/href">https://medium.com/media/11a6fde32e689cce313e52c107b0e586/href</a></iframe><p>But the question here’s that is the accuracy better metric to evaluate model. Yes until you have completely balanced classes, However incase of unbalanced classes using accuracy score isn’t the good option which cause the problem called as <strong>High Accuracy Paradox.</strong></p><p><strong>High Accuracy Paradox?</strong></p><blockquote>Accuracy is misleading when dealing with imbalance classes.</blockquote><p>Consider the Medical scenario this time suppose out of 100 patients 5 of them have disease and 95 don’t. Model predictions are below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*EwX7_fhFiVikA9kNTz4mhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*AQq7qIRzh2D8v3ljgYlW0Q.png" /></figure><p>So what’s an accuracy in that case, accuracy=96%, Accuracy cause the trouble here. Don’t use it incase of imbalance classes.</p><p><strong>Precision</strong></p><p>Precision is accuracy of predicted positive outcomes.</p><p>It completely ignore the Negative(True Negative, False Negative) portion in confusion matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*43Lzf-_opBUbiGwOJSMF0A.png" /></figure><p>Formula for calculating precision is,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*VEHQw4mV33xZNy1awpqGyA.png" /><figcaption>Precision formula</figcaption></figure><p>Precision value close to 0 is the indication of Poor performing model and close to 1 indicates better performing model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*vfcYWw_zkoIw7WYGDr-AFw.png" /></figure><p>Python implementation of precision</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c09365f807f3f6bb0ce3f69c4340639/href">https://medium.com/media/3c09365f807f3f6bb0ce3f69c4340639/href</a></iframe><p>Value of precision near to 0 is consider model as poor model where as precision value near 1 shows model is better.</p><p><strong>Recall</strong></p><p>That’s what she said <strong>😅 </strong>Lets try to understand what <strong>Recall </strong>actually is correctly identified true positive. It’s also referred as <strong>Sensitivity.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*nbybqqJg7IxNkdhyrfAgIQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*Z-Uj_UWMUvAsXkWrupC-vw.png" /><figcaption>Mathematical Formula</figcaption></figure><p>Using Scikit-Learn you can find recall:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75e502adca01695bc96472acc7fcacf2/href">https://medium.com/media/75e502adca01695bc96472acc7fcacf2/href</a></iframe><p>High Recall represent well performing model and Low Recall represent poor performing model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*svaFmtddmEeFFBoxl3XBdw.png" /></figure><p><strong>F1-score</strong></p><p>It’s simply the <a href="https://en.wikipedia.org/wiki/Harmonic_mean">Harmonic mean</a> of Precision and Recall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*cadPoPoalgyzCEKo2c73Zg.png" /><figcaption>F1-SCORE</figcaption></figure><p>When we have high precision and recall we will have higher F1-Score and F1-Score will be low when either or both of them are low.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*dVbkeOM0KyLad9zRixkbBw.png" /></figure><p><strong>Conclusion</strong></p><p>These’re the few of the metrics which helps in evaluating the ML classification model beside that some other metrics are available as well which aren’t mentioned here.</p><p>We have discussed what really confusion matrix is and how we can utilize confusion matrix to get some other metrics like Accuracy score, Precision, Recall and F1-Score.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43ee441d2947" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/metrics-for-classification-confusion-matrix-43ee441d2947">Metrics for Classification- Confusion Matrix</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Glass Classification using Neural Networks]]></title>
            <link>https://medium.com/analytics-vidhya/glass-classification-using-neural-networks-165a97242de6?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/165a97242de6</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Mon, 14 Jun 2021 09:59:31 GMT</pubDate>
            <atom:updated>2021-06-30T09:12:16.368Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Classify different types of Glasses</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*ehxtQv2M5nzGFzQmyyzsqA.jpeg" /><figcaption>Source: <a href="https://images.unsplash.com/photo-1481026469463-66327c86e544?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;ixlib=rb-1.2.1&amp;auto=format&amp;fit=crop&amp;w=524&amp;q=80">Unsplash</a></figcaption></figure><p><strong>Problem statement<br></strong> This problem is related to classifying the glass based upon certain features. This particular problem can be solved by using the Machine learning algorithm like SVC, Random Forest or any other classification algorithm but I used Neural Network. However choosing the simple algorithm will be better because we don’t have the much data.</p><p><strong>Data Source<br></strong> The data is available publicly over the <strong>Kaggle </strong>from <a href="https://www.kaggle.com/uciml/glass">here</a> you can easily download.</p><p><strong>About data<br></strong>The purpose of the dataset is predict the class of the Glass based upon the given features there’re around 9 features (Id number, RI, Na, Mg, Al, Si, K, Ca, Ba) In which all the columns except the Id columns plays an important role in determining the type of the Glass which also our target variable there are 7 types of glasses are in the description provided about the dataset but in a dataset of glasses we don’t have data about type 4 glass each type of glass has it’s own name but in a data the target variable in numbered from 1 to 7. So, based upon the available features we have to predict the target variable (type of glass).</p><pre><strong>import</strong> <strong>pandas</strong> <strong>as</strong> <strong>pd</strong><br><strong>import</strong> <strong>seaborn</strong> <strong>as</strong> <strong>sns</strong><br><strong>import</strong> <strong>numpy</strong> <strong>as</strong> <strong>np</strong><br><strong>import</strong> <strong>matplotlib.pyplot</strong> <strong>as</strong> <strong>plt</strong><br><strong>from</strong> <strong>imblearn.over_sampling</strong> <strong>import</strong> SMOTE<br><strong>from</strong> <strong>sklearn.model_selection</strong> <strong>import</strong> train_test_split<br><strong>from</strong> <strong>sklearn.preprocessing</strong> <strong>import</strong> MinMaxScaler, StandardScaler<br><strong>from</strong> <strong>sklearn.metrics</strong> <strong>import</strong> classification_report<br><strong>from</strong> <strong>sklearn.model_selection</strong> <strong>import</strong> train_test_split<br><strong>from</strong> <strong>sklearn.metrics</strong> <strong>import</strong> confusion_matrix<br><strong>import</strong> <strong>tensorflow</strong> <strong>as</strong> <strong>tf<br></strong>from <strong>tensorflow</strong> <strong>as</strong> keras<strong><br>from</strong> <strong>tensorflow.keras.optimizers</strong> <strong>import</strong> Adam<br><strong>from</strong> <strong>tensorflow.keras.utils</strong> <strong>import</strong> to_categorical, normalize<br><strong>from</strong> <strong>keras.callbacks</strong> <strong>import</strong> Callback, EarlyStopping<br><strong>import</strong> <strong>warnings</strong><br>warnings.filterwarnings(&#39;ignore&#39;)</pre><p>The dataset available to me didn’t contained any header if the data you have downloaded have header then ignore “<em>header=None”</em></p><pre>df=pd.read_csv(&#39;/content/glass_data.csv&#39;,header=<strong>None</strong>)<br>df.columns=[&#39;Id&#39;,&#39;refractive_index&#39;,&#39;Sodium&#39;,&#39;Magnesium&#39;,\<br>&#39;Aluminium&#39;,&#39;Silicon&#39;,&#39;Potassium&#39;,&#39;Calcium&#39;,&#39;Barium&#39;,&#39;Iron&#39;,&#39;Glass_type&#39;]<br>df.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*BGqDnGZvO7hOngvyIBrVjA.png" /></figure><p>The <em>Id</em> column is of no use so dropping that would be a good option. One thing to notice here is that when we dropped the <em>Id </em>column we find out that the data contains some duplicate values as well.</p><pre>df.drop(&#39;Id&#39;,axis=1,inplace=<strong>True</strong>)</pre><p><strong>Data Summary</strong></p><p>Data summary is one of the useful operation for dataframes which gives us the <em>count, Mean, Standard Deviation</em> along with 5 number summary about the features of the data.<br>The 5 number summary contain:</p><ol><li>Min</li><li>Q1</li><li>Median</li><li>Q3</li><li>Max</li></ol><p>so <em>describe </em>function return the 5 number summary along with other statistical methods like standard deviation, Count and Mean</p><pre>df.describe()</pre><p><strong>Null Check</strong></p><p>There’s is no null value in a dataset.</p><pre>df.isna().sum()</pre><p><strong>Duplicate Check</strong></p><p>Dropping the <em>Id </em>column from dataframe we left with a duplicate value so dropping that would be better option to avoid data redundancy.</p><pre>df[df.duplicated()]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*U4BlhEjVfXfgcSOHu2VyLQ.png" /></figure><p><strong>Dropping Duplicate</strong></p><p><strong>How to deal with duplicate records</strong><br>There’re multiple ways to deal with the duplicate records but we have adopted the approach by keeping the last rows and drooping the rows which occurred first in the dataset.</p><pre>df.drop_duplicates(keep=&#39;last&#39;,inplace=<strong>True</strong></pre><p><strong>Concise Summary</strong></p><p><strong>info</strong> function of the dataframe provides the concise summary of the features that how many non-null values are there, Data type of each feature and memory usage.</p><pre>df.info()</pre><p><strong>Pairplot</strong></p><p><strong>Pairplot</strong> shows the relations pairwise among features. Each of the features is plot along grid of axis, So each feature is plotted along the rows as well as along the column</p><pre>corr_mat=df.corr()<br>plt.figure(figsize=(16,10))<br>sns.heatmap(corr_mat,annot=<strong>True</strong>,fmt=&#39;.2f&#39;,alpha = 0.7,   cmap= &#39;coolwarm&#39;)<br>plt.show())</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*CpVT_sLsz8v8O_cLZbO2PQ.png" /><figcaption>Correlation</figcaption></figure><p><strong>Classes Distribution</strong></p><p>The distribution of the Glass type dataset which shows the distribution of each type of glass in a dataset that how many times the particular glass is occurred in a dataset. The distribution shows us that the data is imbalanced</p><pre>plt.figure(figsize=(10,10))<br>sns.countplot(x=&#39;Glass_type&#39;, data=df, order=df[&#39;Glass_type&#39;].value_counts().index);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*5CsGkcPTg28h7qeLnnWlrQ.png" /></figure><p><strong>Separating Features and target variable</strong></p><p>we have separated the features and target variables all the independent variables are stored in X variable where the dependent variable is stored in y variables.<br>The independent variables are normalized by using the normalize function from Keras.Util API of Keras. Normalization can also be performed by using the Scikit-Learn API of Standard-Scaler or Min-Max-Scaler or Robust-Scaler there’re a lot of methods to deal with this.</p><p><strong>why normalization?</strong><br>Usually the normalization is performed to bring down all the features on the same scale.<br>By brining down all the features to same scale benefit is that model treat each feature as same.</p><pre>X=df.drop(&#39;Glass_type&#39;,axis=1)<br>X=normalize(X)<br>y=df[&#39;Glass_type&#39;]</pre><p><strong>Class Balancing</strong></p><p>As above from Distribution of class we can see that the classes are imbalance so if we develop the model of unbalance dataset the model will bias towards the class containing most of the samples so dealing with imbalance classes will help in developing fair model</p><pre><strong>from</strong> <strong>imblearn.over_sampling</strong> <strong>import</strong> RandomOverSampler<br><br>ros = RandomOverSampler(random_state=42)<br>x_ros, y_ros = ros.fit_resample(X, y)</pre><p><strong>Splitting Data</strong><br>Now the data is balance so we split that balanced dataset into train test and validation data. By using the Scikit-Learn API train test split twice we split the data, 75% of data as training data and furtherly we split the 25% test data into the test and validation data.<br>By printing the shape of the data we can see that 75% of data lies in training set and remaining 25% of data is further splitted half into testing and validation data</p><pre>X_train, X_test, y_train, y_test = train_test_split(x_ros,y_ros,test_size=0.25,random_state=42)<br>X_test, X_val, y_test, y_val = train_test_split(X_test,y_test,stratify=y_test,test_size = 0.5,random_state=42)</pre><pre>y_train=to_categorical(y_train)<br>y_test=to_categorical(y_test)<br>y_val=to_categorical(y_val)</pre><pre>print(&#39;X_train :&#39;,X_train.shape)<br>print(&#39;y_train :&#39;,y_train.shape)<br>print(&#39;X_test :&#39;,X_test.shape)<br>print(&#39;y_test :&#39;,y_test.shape)<br>print(&#39;X_val :&#39;,X_val.shape)<br>print(&#39;y_val :&#39;,y_val.shape)</pre><pre># Output:<br># X_train : (342, 9)<br># y_train : (342, 8)<br># X_test : (57, 9)<br># y_test : (57, 8)<br># X_val : (57, 9)<br># y_val : (57, 8)</pre><p><strong>Model Building</strong></p><p>Choosing a model which neither over-fit nor under-fit is all about applying hit and trail methods and choose the one which provides the better results.</p><p>One can find a good model by using the libraries of Keras to tune the parameters and find out the best number of layers. But I have adopt a simple approach because our problem is not much complex.</p><pre>model = tf.keras.models.Sequential([<br>tf.keras.layers.Dense(40,input_shape=(9,),activation=&#39;relu&#39;),<br><br>tf.keras.layers.Dense(20,activation=&#39;relu&#39;),<br><br>tf.keras.layers.Dense(8, activation=&#39;softmax&#39;)<br>])<br><br>model.compile(optimizer = &#39;adam&#39;, loss = &#39;categorical_crossentropy&#39;, metrics = [&#39;accuracy&#39;])</pre><pre>model.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*KbZthWHbngHAl9Ay2nsVJQ.png" /></figure><p><strong>Stop Loss</strong></p><p>Before training the model on data we defined the early stopping approach, training the model again and again can be very time consuming when the epoch size is greater. So, adding the early stop was a better option to measure the validation loss, whenever the model validation loss stops improving over the 20 number of epochs which is set using the patience parameter the model will stop training. The model is fitted over the training data and validated at the same time on the validation set.</p><pre>early_stop = EarlyStopping(<br>                monitor=&#39;val_loss&#39;, <em>#Quantity to be monitored.</em><br>                mode=&#39;auto&#39;, <em>#direction is automatically inferred from the name of the monitored quantity</em><br>                verbose=1, <em>#verbosity mode.</em><br>                patience=20 <em>#Number of epochs with no improvement after which training will be stopped</em><br>              )</pre><p><strong>Model Training</strong></p><p>Now the model architecture is finalized and we have set the early stop as well. Now its time to train the model over the training data and validate it using validation data. The model would train for 1000 epochs if the validation loss is keep decreasing if the validation loss stop decreasing then model will stop the iterations after check further till 20 epochs</p><pre>history = model.fit(X_train, y_train,<br>                    epochs=1000,<br>                    validation_data=(X_val, y_val),<br>                    callbacks=[early_stop],<br>                    verbose=2,<br>                   )</pre><p><strong>Accuracy Plot</strong></p><p>The model is successfully trained and validated over the data now we can plot the accuracy of model over the train set and accuracy on validation dataset. The below graph shows the visual representation of both the accuracies along with legends at the lower right bottom</p><pre>plt.figure(figsize=(18,8))<br>plt.plot(history.history[&#39;accuracy&#39;])<br>plt.plot(history.history[&#39;val_accuracy&#39;])<br>plt.title(&#39;Model Accuracy&#39;)<br>plt.ylabel(&#39;Accuracy&#39;)<br>plt.xlabel(&#39;Epoch&#39;)<br>plt.legend([&#39;Training-Accuracy&#39;, &#39;validation-Accuracy&#39;], loc=&#39;lower right&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*cye92NmgtiAAzr-LSbfRJg.png" /></figure><p><strong>Loss Plot</strong></p><p>The model loss representation can be seen in below graph along with legends</p><pre>plt.figure(figsize=(18,8))<br>plt.plot(history.history[&#39;loss&#39;])<br>plt.plot(history.history[&#39;val_loss&#39;])<br>plt.title(&#39;Model Loss&#39;)<br>plt.ylabel(&#39;Loss&#39;)<br>plt.xlabel(&#39;Epoch&#39;)<br>plt.legend([&#39;Training-Loss&#39;, &#39;validation-Loss&#39;], loc=&#39;upper right&#39;)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*liNvBJtLSLfFNNfaRm20rQ.png" /></figure><p><strong>Model Evaluation</strong></p><p>Now we’re done with all the things related to model training now it’s time to test our model on the test data which haven’t seen by the model to check how model performs over the unseen dataset. We can see that the model has achieved an accuracy of 63% of over the test data as well. The accuracy score isn’t the good option for measuring the performance of model which is trained over imbalance dataset however we have balanced the dataset so we can consider this metric reliable one.</p><pre>model.evaluate(X_test, y_test)</pre><p><strong>Classification Report</strong></p><p>Classification report gives an idea about the class the model has predict orrect and incorrect. The values in diagonals represent the classes that are predicted correctly whereas the values other than diagonals are incorrect predictions</p><pre>y_pred = model.predict(X_test) <em># model predicions of test data</em> y_pred_max = np.argmax(y_pred,axis=1) <em># choosing the max probability predicted by model</em> y_test_max = np.argmax(y_test,axis=1) <em># selecting max from y_test for comparison</em> confusion_matrix(y_test_max, y_pred_max)</pre><pre>#Output<br>array([[1, 2, 8, 0, 0, 0],<br>      [0, 6, 6, 0, 0, 0],<br>      [0, 1, 5, 0, 0, 0],<br>      [0, 0, 0, 7, 0, 0],<br>      [0, 0, 0, 0, 8, 2], <br>      [0, 0, 1, 1, 0, 9]])</pre><p><strong>Conclusion</strong></p><p>With Neural Network we achieved accuracy of about 65% percent which is achieved by applying trail-and-errors methods to find the best architecture of the Neural Network which neither overfit nor underfit. The accuracy can be improved by adding more data as Neural Networks are considered as best for large quantity of data. for smaller amount of dataset the traditional machine learning algorithms work better. The more data we have the more it helps the model in learning best parameters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=165a97242de6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/glass-classification-using-neural-networks-165a97242de6">Glass Classification using Neural Networks</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 4:Python Newbie?]]></title>
            <link>https://adnankhanx.medium.com/day-4-python-newbie-b0ad9e3f0145?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0ad9e3f0145</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Thu, 28 Nov 2019 17:33:28 GMT</pubDate>
            <atom:updated>2022-07-16T08:22:20.475Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Newbie?</h3><p>Day 4</p><p>Lets get started with some hot coding in cool weather.Today we’re going to discuss builtin data structure known as <strong>List</strong>.Suppose you’re buying some fruits for your family from market and want to store fruit names and prices every time in a different variables with fruit names and store the price of that fruit in it so that would be kind of inconvenient right?.To overcome this problem Lists were introduce to store all the values in a single list.You can build such a list with square brackets like this</p><pre>prices=[&quot;Apple&quot;,90,&quot;Mango&quot;,70,&quot;Banana&quot;,45]</pre><p>In simple words you can say that assigning multiple values to a single variable.It’s some how related to Arrays but the difference between array and list is that Array can store multiple values of similar type where list can store values of any type.Moreover,we can add list inside list as well which is know as sublist.</p><pre>prices=[[&quot;Apple&quot;,90],<br>        [&quot;Mango&quot;,70],<br>        [&quot;Banana&quot;,45]]</pre><p>In above example you can see how we have created three sublists in a list.Now you’re familiar with how to create a list in python right. So now the question raised is how to access that values after creating the list.Let’s take a look with example first.</p><pre>prices=[&quot;Apple&quot;,90,&quot;Mango&quot;,70,&quot;Banana&quot;,45]<br>prices[0] #output=&quot;Apple&quot;<br>prices[3] #output=70<br>price[-1] #output=45<br>price[-3] #output=70</pre><p>In the example you can notice that how can we access elements of list by mentioning their index number inside square brackets with name of the list we have given.Like C++,Python indexing also starts from zero.However,in python you can access element through negative index as well,you can notice that price[3] and price[-3] has the same value 70.What if you want to access multiple values of the list? Yes you can access multiple values at a time through slicing as well.While specifying a slice you enter two index numbers one as starting index while other as an ending index separated by adding colon between them<strong>[start : end].</strong></p><pre>prices[1:3] #[90,&quot;Mango&quot;]<br>prices[2:5] #[&quot;Mango&quot;,70,&quot;Banana&quot;]<br>prices[:3]  #[&quot;Apple&quot;,90,&quot;Mango&quot;,70,&quot;Banana&quot;,45]<br>prices[4:]  #[&quot;Banana&quot;,45]</pre><p>That’s how you can do slicing. where in 3rd line you can notice that there is no starting point it means start from index 0 and go till index 3 similarly in 4th line ending point is missing so it means go till last element of the list. Where in list of list you can access element like this:</p><pre>prices=[[&quot;Apple&quot;,90],<br>        [&quot;Mango&quot;,70],<br>        [&quot;Banana&quot;,45]]<br>prices[1][0] #output=&quot;Mango&quot;<br>prices[2][1] #output=45</pre><h4>List Manipulation:</h4><p>we can update the list at our will like adding or removing elements from list and we can replace lists values as well, for updating a value we simply use assignment operator where for removing a value from list we use del(variable_name) function.</p><pre>final_prices =prices+[[&quot;strawberry&quot;,110]]<br>del(final_prices[3])<br>final_prices[1][1] = 120</pre><p>In first line of code we add another sublist to list prices and stored it in final_prices,for deletion of that sublist we have added we use <strong>del </strong>function and to update the value we select an element then assigned it a new value.There is one point to note down we we copy a list and assign it to another variable let’s suppose you have list A and you assign it to variable B so making change in B will also effect list A because we assign a reference of list A memory to variable B.However if you want to avoid this then you do something like this B=list(A),now if make changes in B it wouldn’t effect list A.</p><p>That’s enough for today otherwise it would be overloaded and your brain wouldn’t consume that all at once. By the way, that was kind of joke don’t forget to solve examples on lists because the more you code the more your concepts would become clear.Share your feedback or the problem you faced i’m here to make it clear for you and for me as well. Good Luck with that! See you tomorrow with another builtin data structure of Python.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0ad9e3f0145" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Newbies ?]]></title>
            <link>https://adnankhanx.medium.com/python-newbies-300b6f88be5f?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/300b6f88be5f</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 19:04:26 GMT</pubDate>
            <atom:updated>2019-11-28T17:36:55.874Z</atom:updated>
            <content:encoded><![CDATA[<h3>Day 3: Python Newbie?</h3><p>Have you prepared a cup of coffee?Go get a cup of coffee before reading this because today we are going to discuss very interesting topic the type of operators which are mostly used in python.Let dive in types of operators first.</p><blockquote>Operators are used to perform operations on variables and values.</blockquote><p>Python divides the operators in the following groups:</p><ul><li>Arithmetic operators</li><li>Assignment operators</li><li>Comparison operators</li><li>Logical operators</li><li>Identity operators</li><li>Membership operators</li></ul><h4>Arithmetic Operators:</h4><p>Arithmetic operators are used with numeric values to perform operations like addition, subtraction, multiplication, division, %modulus.</p><pre>var1 = 20<br>var2 = 5<br>res_add=var1 + var2 #Addition among variables<br>res_sub=var1 - var2 #Subtraction among variables<br>res_mul=var * var2 #multiplication among variables<br>res_div=var / var2 #division among variables<br>res_mod=var % var2 #modulus among variables<br>res_mul=var // var2 #floor division among variables</pre><p>Firstly we have declared two variables var1 and var2 then we perform arithmetic operations over it like addition,subtractions etc.But the point here is what’s the difference between division( / ) and floor division( // )?.The main difference between them is division( / ) will give you answer in form of float where floor division will give you answer in type integer and follow the concept of floor function. Floor function is used to return the closest integer value which is less than or equal to the specified value.</p><h4>Assignment operators:</h4><p>Python assignment operators are used for assigning the value of the right operand to the left operand. Assignment operators in python are (=, +=,%= , *=, /=,//= etc).</p><pre>var1 = 20<br>var1 += 5<br>var1 -= 2</pre><p>That’s how we use assignment operators to assign the value to left operand(var1).Lets take an example to make it more clear we already have declared var1 with value of 20.Now we perform this operation over it var1+=5 so it would simply add 5 in the existing value of var1.So, if you printout the value of var1 it would show 25 similarly,these all operation will effect the existing value of var1.</p><h4>Note:</h4><p>when you apply one operation on var1 then the existing value will change like when we applied var+=5 operation on var1 now the value of var1 is 25.so when you apply var1-=2 it will print 23 instead of 3.</p><h4>Comparison operators:</h4><p>Comparison operator are used to compare two values.These operators are some how similar to assignment operator in sign.Comparison operators are &gt;,&lt;,≥,≤,==,!=.These types of operators will give you output in boolean form like True or False.</p><pre>var1 = 5<br>var2 = (2+3)<br>Equal_to = (var1 == var2) #True<br>greater_then =(var1 &gt; var2) #False<br>greater_then_equal_to = (var1 &gt;= var2)#True</pre><h4>Logical operators:</h4><p>Logical operators in python are used for checking the conditional statement whether it is True or False.Logical operators in python are AND,OR and NOT.</p><p>AND operator → It return True only if all the conditions are true</p><p>OR operator →It returns True when any of the condition is true</p><p>NOT operator →Return true when the operand is False</p><pre>var1 = 15<br>var2 = 25<br>result1= (var1 &gt; 10 and var2 &lt; 30) #True<br>result2= (var1 &gt;5 or var2 &lt; 20)#True<br>result3= not(Var &gt; 5 and var2 &lt; 30 ) #False</pre><p>result3 here is returning False because the value of result3 is giving us True so NOT will convert it into False and vice versa.</p><h4>Identity operators:</h4><p>To compare the memory location of two objects, Identity Operators are used. The two identify operators used in Python are (is, is not).</p><ul><li>Operator is: It returns true if two variables point the same object and false otherwise</li><li>Operator is not: It returns false if two variables point the same object and true otherwise</li></ul><pre>var1=[1,2,3]<br>var2=[1,2,3]<br>var3=var1<br>print(var3 is var1) #True<br>print(var3 is var2) #False</pre><p>Second print statement is going to print False because identity operators same objects with same memory locations.However in this example we’re using List which we will discuss later.</p><h4>Membership operators:</h4><p>These operators test for membership in a sequence such as lists, strings or tuples. There are two membership operators that are used in Python.Membership operators are “in, not in”.</p><pre>list1 = [&quot;one&quot;,&quot;two&quot;,&quot;three&quot;]<br>print(&quot;one&quot; in list1)#True<br>print(&quot;Five&quot; in list1) #False</pre><p>So that’s it for today get practice over that and try to more examples on your own.In very first tutorial i recommended a book where a lot of examples are given solve as many as you can because if you’re not going to solve examples then these articles didn’t going to effect your skills.I’m providing the link of first articles where you can find book and some recommended course where you can learn basics of python as well.</p><p><a href="https://medium.com/@adnankhan_65379/python-newbies-lets-get-started-c9f9be72e1dd">Python Newbies ? Let’s get started…</a></p><p>Don’t forget to share your feedback 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=300b6f88be5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Newbie?]]></title>
            <link>https://adnankhanx.medium.com/python-newbie-83fbfb9feea6?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/83fbfb9feea6</guid>
            <category><![CDATA[variable-declaration]]></category>
            <category><![CDATA[type-in-python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python-beginner]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Tue, 26 Nov 2019 16:10:16 GMT</pubDate>
            <atom:updated>2019-11-28T17:35:28.811Z</atom:updated>
            <content:encoded><![CDATA[<h3>Day 2: Python Newbie?</h3><h4>Variable :</h4><blockquote>A python variable is a reserved memory location to store values.</blockquote><p>OR</p><blockquote>A container for storing data values.</blockquote><h4>How to declare a variable?</h4><pre>var = &quot;a&quot;</pre><p>That’s how we can simply declare variable of type String. Similarly you can declare variable of other types as well like integer or float.</p><pre>var1= 12.56</pre><blockquote>The process of linking two or more strings together is called <strong>concatenation</strong>.</blockquote><p>You can concatenate variables as well by simply putting + sign among them. However you can’t concatenate variables of different type like string and int.if you want to concatenate them then you have to change the type of variable.Lets see how</p><pre>a = &quot;He&#39;s monthly salary is&quot;<br>b = 80000<br>result = a+ &quot; &quot; +str(b)</pre><p>If you’re not convert the type then it would give a “Traceback error”.However you can add values of float and integer types because both store the numeric values.</p><h4>Rules for declaring variable:</h4><ul><li>A variable name must start with a letter or the underscore character</li><li>A variable name cannot start with a number</li><li>A variable name can only contain alpha-numeric characters and underscores (A-z, 0–9, and _ )</li><li>Variable names are case-sensitive (age, Age and AGE are three different variables)</li><li>A variable name should not contain reserve words.</li></ul><h4>Local &amp; Global Variable:</h4><p>let’s simply understand through code</p><pre>var_A=10<br>def someFunction():<br>    var_B=&quot;Hello&quot;<br>    print(var_B)</pre><p>The variable var_A which is outside the function is “Global variable” and it has global scope. Which is accessible inside as well as outside the function.</p><p>The variable var_B which is inside function is “Local variable” and it has only local scope.It’s accessible only inside the function not from outside.</p><h4>Note:</h4><p>As python is a case sensitive language.So variables are also case sensitive it means that variable result is different from Result.</p><h4>Type():</h4><p>If you declare a variable and you forget later the what was the type of variable A? so you can simply check by using the built-in type function.like this,</p><pre>type(A)</pre><p>So that was all about variable. More about python we will discuss tomorrow we will go step by step and clear each and every concept.This article was very limited one but i know that going from less to more produces more interest for beginners.Don’t forget to share your valuable feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83fbfb9feea6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Newbies ? Let’s get started…]]></title>
            <link>https://medium.com/analytics-vidhya/python-newbies-lets-get-started-c9f9be72e1dd?source=rss-122f963ab5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9f9be72e1dd</guid>
            <category><![CDATA[journey-into-pyhton]]></category>
            <category><![CDATA[newbie-guide]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Adnan Khan]]></dc:creator>
            <pubDate>Mon, 25 Nov 2019 19:14:42 GMT</pubDate>
            <atom:updated>2019-12-02T08:42:30.635Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Newbies ? Let’s get started…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BZg6YBvrpkRDPpdj" /><figcaption>Photo by <a href="https://unsplash.com/@gallarotti?utm_source=medium&amp;utm_medium=referral">Francesco Gallarotti</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Day 1</h3><p>Are you programmer? NO. Doesn’t matter we will start from the very beginning to clear your basic concepts about Python and it’s Syntax.</p><p>I was in 2nd year of my university when i decided now i have to get my hand dirty with python but i didn’t find some proper mentor who help me where to start to become a python expert.So i started on my own but i take a long time to clear my concepts because i was feeling shy at that time that if someone help me it’s good otherwise let it go.Then with time to time i realize that you could learn and clear your concepts about each and every thing when you have access to “Google Ustad” .Ustad is literally a Urdu word use for Teacher. But if you struggle for something then it definitely become worthy. For what i have i don’t want to let anyone struggle that much when you have the proper Road-map to follow.</p><p>So now it’s your turn to get your hand dirty with python by clearing the some basic concepts of python.I Would share my knowledge about everything that i have learn in python from the very basic towards advancement.Once you know proper syntax of the language then further all depend upon your mind to make logic and program according to that. Building logic is kind of an art every program can be written in different ways. I believe that if some problem is given to the class of ten students and each one have different thinking from each other then that problem can have ten possible solutions as well.</p><h3>Input-Output syntax:</h3><p>So newbies to every language take start from very basics like input output syntax. So, we would also take start from there.</p><pre>variable1=input(&quot;Enter your Name :&quot;)<br>Output:<br>Enter your Name :Adnan khan</pre><p>As you could see in above Figure we declare as variable with the name of variable1 and passes simple the input to it. You can take input in python by simple calling the input function. Here you should remember one thing that every single input is taken as string by default. We would briefly discuss string Datatype later on.Now if you want to take some other type of input let’s see how you would take that</p><pre>variable_int=int(input(&quot;Enter the number of your wish :&quot;))<br>print(variable_int)<br>type(variable_int)</pre><pre>Output:<br>Enter the number of your wish :15<br>15<br>int</pre><p>In the above code you could see we have taken the input from the user in the form of integer.Similarly you can take all other types of input from the user.We can check the datatype of the variable simply by using the the function type( ).The purpose of type( ) function is to return the type of the object.So that was all about input function.</p><p>Now lets discuss how to get output from the program. Python syntax is easy to understandable by the human being. For output statement we simply use the Print( ) statement.</p><pre>print(&quot;Hello python!&quot;)</pre><pre>Output:<br>Hello Python!</pre><p>You can notice the print statement it print the statement inside parenthesis. You could whatever you want by simply write inside parenthesis as well as in quotation marks. See Figure 2 as well where we used print statement to print the variable_int we have declared.So that was all about input and output syntax.</p><h3>Data Types :</h3><p>You don’t know what is data types? So it isn’t a great problem we would discuss each and every data type in detail and you would be able to clear your concepts about that.</p><h4>Int :</h4><p>It often called as integers or int, it contain real numbers without decimals like 1,9,110 etc .Integer can be of any length.It’s the simplest way to define Integer data type.</p><h4>Float :</h4><p>The float is similar to integer but the main difference among them is that float contain decimals like 1.5,2.3,65.7 etc.Float is accurate only to 15 decimal points.</p><h4>Decimal :</h4><p>Decimal is similar to float data type but float has accuracy only limited to 15 decimal points.So, sometimes it causes an error how it create an error let me show through code</p><pre>(1.1+2.2)==3.3</pre><pre>Output:<br>False</pre><p>According to human mind calculation these both numbers are equal but python rejects it. As computers only understand binary(0 or 1) and floating-points store in memory in binary form and these numbers didn’t get properly stored that’s why it rejects.</p><p>We generally use Decimal in the following cases.</p><ul><li>When we are making applications that need exact decimal representation.</li><li>When we want to control the level of precision required.</li></ul><h4>Complex :</h4><p>Complex data type is very rarely use in python. If you have read the basic mathematics in school life you get across with term something like this 3+5j. It contain two values one is real where other is imaginary.The value with term “j” is imaginary value.</p><pre>var=3+5j<br>type(var)</pre><pre>Output:<br>complex</pre><p>So that was all about Input-Output and datatypes in python.It was the first day to take a start I will try on daily bases to discuss little bit of my knowledge what i have gained so far. I’m not pro but i believe in that with sharing your knowledge with someone it would definitely beneficial for me as well. I will share some free resources where you could learn about python free of cost.</p><ul><li><a href="https://www.datacamp.com/courses/intro-to-python-for-data-science">Introduction to Python</a></li><li><a href="https://cognitiveclass.ai/blog/event/introduction-python-data-science">Introduction to Python for Data Science (2016-11-10)</a></li></ul><p>If you have the stamina of reading books then you should follow the book where you would learn a lot by solving some basic examples.</p><p>Python-By-Examples by Nichola Lacey</p><p>You can download it from google free of cost.Now go for it and get your hands dirty. Solve as many as examples you can.</p><h3>Tips :</h3><p>· Clear your concept about problem.</p><p>· Find possible solution for it.</p><p>· Don’t irritate over errors. From these small errors you would learn a lot.</p><p>· Try to dry run your code and check the output.</p><p>· Teach others to strong your own base.</p><p>Give your valuable feedback.it would be great for me to gain some knowledge from you guys.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9f9be72e1dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/python-newbies-lets-get-started-c9f9be72e1dd">Python Newbies ? Let’s get started…</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>