<?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 Neeraj Kumar Vaid on Medium]]></title>
        <description><![CDATA[Stories by Neeraj Kumar Vaid on Medium]]></description>
        <link>https://medium.com/@neeraj-kumar-vaid?source=rss-9cdbc8edbceb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*B_tr5_Fd6bBtwjAHO2qjwQ.jpeg</url>
            <title>Stories by Neeraj Kumar Vaid on Medium</title>
            <link>https://medium.com/@neeraj-kumar-vaid?source=rss-9cdbc8edbceb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:53:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@neeraj-kumar-vaid/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[Why and How to Become a Data Scientist in 2023?]]></title>
            <link>https://neeraj-kumar-vaid.medium.com/why-and-how-to-become-a-data-scientist-in-2023-499828ce591?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/499828ce591</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-scientist]]></category>
            <category><![CDATA[data-science-training]]></category>
            <category><![CDATA[data-science-courses]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 04:53:19 GMT</pubDate>
            <atom:updated>2023-02-03T16:34:45.336Z</atom:updated>
            <content:encoded><![CDATA[<p>Free courses to become data scientist in 2023.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*CZlZPzf_tXjpVxZ057EDsA.png" /><figcaption>Image Source: <a href="https://media.licdn.com/dms/image/C4D12AQGD_su1k14bYA/article-cover_image-shrink_423_752/0/1583217310942?e=1680739200&amp;v=beta&amp;t=CeDXkL_lvVVWAnjLJzeL0auxy4Sm7uIof-vV0Nc_R3Q">click here</a></figcaption></figure><p>Data science is a rapidly growing field that is becoming increasingly important in today’s data-driven digital world. The role of a data scientist is to extract insights and knowledge from complex data sets and use that information to inform business decisions. As a data scientist, you will have the opportunity to work with cutting-edge technologies, solve complex problems, and make a significant impact on the success of your organization.</p><p>One of the major reasons why data science is a great career choice is a high demand for data scientists. According to the <a href="https://www.bls.gov/ooh/math/data-scientists.htm">US Bureau of Labor Statistics</a>, the field is projected to grow by 16% by 2026, much faster than the average for all occupations. This means that there will be plenty of job opportunities for data scientists in the coming years. Additionally, data scientist positions often come with competitive salaries and opportunities for advancement.</p><p>Another reason why data science is a great career choice is the diversity of industries that it touches. Data scientists can work in various sectors such as finance, healthcare, retail, technology, and many more. This means that there is a wide range of opportunities for data scientists to apply their skills and make a real difference. A career as a data scientist can be highly rewarding, both in terms of professional growth and financial stability. With high demand, diverse industries, and the opportunity to work with cutting-edge technologies, data science is a great career choice for anyone with an interest in technology, problem-solving, and data analysis. Now let us understand how can you become a data scientist.</p><p>Becoming a data scientist is a challenging but rewarding journey that requires a combination of technical and analytical skills, as well as domain expertise. Here’s a 6-month study plan to help you achieve your goal:</p><ol><li><strong>Programming in Python:</strong> A strong foundation in Python programming is essential for data scientists. You can start by taking the course “<a href="https://www.coursera.org/learn/python-for-applied-data-science-ai">Python for Data Science, AI, and Development</a>, ” or “<a href="https://www.coursera.org/specializations/python?#about">Python for Everybody</a>” on Coursera to learn the basics of the language.</li><li><strong>Data Exploration and Visualization:</strong> Data exploration and visualization skills are crucial to understanding the patterns and insights from data. You can take the course “<a href="https://www.coursera.org/learn/python-for-data-visualization">Data Visualization with Python</a>” on Coursera to learn how to use Python libraries like Pandas and Matplotlib to explore and visualize data.</li><li><strong>Statistics and Probability:</strong> A good understanding of statistics and probability is essential for data scientists to make informed decisions based on data. You can start by taking the course “<a href="https://www.coursera.org/learn/datasciencemathskills">Data Science Math Skills</a>” on Coursera or “<a href="https://www.datacamp.com/tracks/statistics-fundamentals-with-python">Statistics Fundamentals with Python</a>” on DataCamp to learn the fundamentals of statistics and probability.</li><li><strong>Machine Learning: </strong>Machine learning is the process of building models to make predictions based on data. You can start by taking the “<a href="https://www.coursera.org/specializations/machine-learning-introduction">Machine Learning Specialization</a>” and “<a href="https://www.coursera.org/specializations/deep-learning">Deep Learning Specialization</a>” on Coursera to learn the concepts and techniques of machine learning and how to apply them using Python libraries like scikit-learn, tensorflow, etc.</li><li><strong>Big Data Technologies:</strong> Data scientists need to be familiar with big data technologies to process and analyze large amounts of data. You can start by taking the course “<a href="https://www.edx.org/course/big-data-hadoop-and-spark-basics?index=product_value_experiment_a&amp;queryID=b86ef599eaf1d851f6941611ca5ffbfd&amp;position=4&amp;eaid=0&amp;v=2&amp;linked_from=autocomplete&amp;c=autocomplete">Big Data, Hadoop, and Spark Basics</a>” on edX to learn the basics of big data technologies like Hadoop and Spark.</li><li><strong>Practice, Practice, Practice: </strong>Participate in data science competitions on <a href="https://www.kaggle.com/">Kaggle</a> (<a href="https://www.kaggle.com/">https://www.kaggle.com/</a>) or find datasets on <a href="https://www.data.gov/">Data.gov</a> (<a href="https://www.data.gov/">https://www.data.gov/</a>) or <a href="https://archive.ics.uci.edu/ml/index.php">UCI Machine Learning Repository</a> to apply what you’ve learned and build your portfolio.</li></ol><p>In addition to these technical skills, data scientists also need excellent communication skills, the ability to work in a team, and a curious and analytical mind. It’s a challenging but exciting journey, and with dedication and hard work, you can become a successful data scientist.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=499828ce591" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Convolution Neural Networks]]></title>
            <link>https://neeraj-kumar-vaid.medium.com/convolution-neural-networks-9516833e118d?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9516833e118d</guid>
            <category><![CDATA[cnn-model]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[deep-neural-networks]]></category>
            <category><![CDATA[convolution-neural-net]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Thu, 29 Dec 2022 06:51:13 GMT</pubDate>
            <atom:updated>2022-12-29T06:51:13.935Z</atom:updated>
            <content:encoded><![CDATA[<p>A Simple Introduction</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*KBGBlV8g_4vfV8oGrShD6w.png" /><figcaption>Convolutional Neural Network takes an input image and passes it through a series of convolution and pooling layers to extract features (shown on the top) that are used in the final layers to classify the input image into one of several classes (Image Credit — .</figcaption></figure><p>Convolutional Neural Networks (CNNs) are a type of artificial neural network specifically designed for image recognition tasks. They are inspired by the way the visual cortex processes information, with the goal of building models that can identify patterns and features in images.</p><p>At the heart of a CNN is the convolutional layer, which is responsible for extracting features from the input image. This is done through a process called convolution, which involves applying a set of filters to the input image. These filters are small matrices that are used to detect specific patterns in the image, such as edges or corners.</p><p>The convolution process can be mathematically described as follows: given an input image represented by a matrix X and a filter represented by a matrix W, the output of the convolution is a matrix Y, where each element y_{i,j} y is calculated as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*F1Wyh7dYI_9Rv9CEexADfw.png" /></figure><p>In this equation, M and N are the dimensions of the filter, and the sum is taken over all elements in the filter. This operation is repeated for each element in the output matrix, with the filter sliding across the input image and performing the dot product at each position.</p><p>One of the key benefits of convolution is that it allows the network to learn local patterns in the input image, rather than trying to learn the entire image at once. This is useful because many features in an image are only relevant in a small part of the image, and convolution allows the network to focus on these local patterns.</p><p>In addition to the convolutional layer, a CNN typically includes other layers such as pooling layers and fully connected layers. Pooling layers are used to reduce the spatial dimensions of the feature maps produced by the convolutional layers, which helps to reduce the number of parameters in the model and prevent overfitting. Fully connected layers are used to make predictions based on the features extracted by the convolutional layers.</p><p>CNNs have been very successful in a variety of image recognition tasks, and are now the go-to choice for many applications in computer vision. They have been used to achieve state-of-the-art results on tasks such as object detection, image classification, and face recognition, among others.</p><p>In summary, convolutional neural networks are a powerful tool for image recognition tasks and are able to learn local patterns in images through the use of convolutional layers. Combined with other types of layers, they are able to extract features from images and make predictions based on these features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9516833e118d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Deep Learning Libraries on Apple MacBook M1 Pro]]></title>
            <link>https://neeraj-kumar-vaid.medium.com/install-deep-learning-libraries-on-apple-macbook-m1-pro-37444644299b?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/37444644299b</guid>
            <category><![CDATA[m1-pro]]></category>
            <category><![CDATA[apple-m1]]></category>
            <category><![CDATA[m1]]></category>
            <category><![CDATA[apple-m1-chip]]></category>
            <category><![CDATA[m1-macbook-pro]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Wed, 17 Nov 2021 02:26:37 GMT</pubDate>
            <atom:updated>2021-11-17T02:36:44.128Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How to install Tensorflow and Jupyter-Notebook on latest MacBook M1 Pro?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-ERyIds7KISN84cIJBovg.jpeg" /></figure><p>I was excited to setup my new MacBook M1 Pro to do machine/deep learning with Tensorflow (Keras), Scikit-learn, and Pandas. Below I share the steps that worked for me to install the required libraries on my Macbook, which has the latest M1 Pro chip with 10 CPU cores and 16 GPU cores.</p><p>You should open the terminal on you latest MacBook and complete the following steps to set up Tensorflow and other machine learning libraries on your computer.</p><h3>Step 1: Install Xcode Command Line Tools</h3><p>These are the tools required for programming and software development on MacOS. Type the following command</p><pre>xcode-select --install</pre><h3><strong>Step 2: Install Miniforge</strong></h3><p>Ananconda is not supported on the new M1 chip; so you need to install miniforge, which provides you Conda to install other machine learning packages such as pandas, scikit-learn, etc.</p><p>Download “Miniforge3-MacOSX-arm64.sh” from <a href="https://github.com/conda-forge/miniforge/releases/tag/4.10.0-0">https://github.com/conda-forge/miniforge/releases/</a>. Use the following command to install miniforge on your computer.</p><pre>bash Miniforge3-MacOSX-arm64.sh</pre><p>Note that you might need to provide the full path to the downloaded file to execute above command from your terminal. To verify, close your terminal, reopen the terminal, and run the following command.</p><pre>conda</pre><p>You should see the following output after running the “conda” command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzqj8gkiFyUIDdBchc0hDg.png" /><figcaption>Output of “conda” command in Terminal</figcaption></figure><h3><strong>Step 3: Create and Activate conda Environment</strong></h3><p>Run the following command to create a Python virtual environment (why? - <a href="https://realpython.com/python-virtual-environments-a-primer/">read this</a>) where you will install Tensorflow.</p><pre>conda create -name tensorflow</pre><p>You can replace the virtual environment name “tensorflow” with whatever name you prefer in above command. You should now activate the virtual environment by running the following command.</p><pre>conda activate tensorflow</pre><h3><strong>Step 4: Install Tensorflow</strong></h3><p>Let us first install the dependencies for tensorflow by running the following command.</p><pre>conda install -c apple tensorflow-deps</pre><p>Now run the following command to install tensorflow on your Mac.</p><pre>pip install tensorflow-macos</pre><p>You should also install the metal plug-in for tensorflow by running the following command.</p><pre>pip install tensorflow-metal</pre><blockquote><strong>NOTE 1: </strong>Make sure you have “pip” installed on your computer before you run the above two commands in your terminal. If you do not have “pip” installed on your computer then you can install it using the following command:</blockquote><pre>conda install pip</pre><h3><strong>Step 5: Install Jupyter Notebooks, Pandas, and Scikit-Learn</strong></h3><p>Finally, you can install Jupyter Notebook and other required packages to code your favorite machine learning algorithms on your Mac by using the following commands.</p><pre>conda install notebook -y<br>conda install pandas -y<br>conda install scikit-learn -y</pre><h3><strong>Step 6: Verify the Installation</strong></h3><p>Run the following command to open a jupyter notebook. Make sure you are in the “tensorflow” virtual environment.</p><pre>jupyter notebook</pre><p>Run the following commands in your notebook.</p><pre>import sys<br>import tensorflow as tf<br>import tensorflow.keras</pre><pre>print(f&quot;Tensor Flow Version: {tf.__version__}&quot;)<br>print(f&quot;Keras Version: {tensorflow.keras.__version__}&quot;)<br>print()<br>gpu = len(tf.config.list_physical_devices(&#39;GPU&#39;))&gt;0<br>print(&quot;GPU is&quot;, &quot;AVAILABLE&quot; if gpu else &quot;NOT AVAILABLE&quot;)</pre><p>You should see the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wRdHR-k03kIqR8rypZZ4oQ.png" /><figcaption>Installation Verification</figcaption></figure><p>If you see “GPU is AVAILABLE” then tensorflow was able to detect the M1 GPU. Now you can write your favorite machine/deep learning programs to solve problems of the world on your new MacBook.</p><blockquote><strong>NOTE 2:</strong> “import tensorflow.keras” might return an error because of the version mismatch. You should be able to fix it by running the following command in your tensorflow virtual environment.</blockquote><pre>pip install keras==2.6</pre><blockquote>I have Tensor Flow Version 2.6.0 and Keras Version 2.6.0 installed on my computer.</blockquote><blockquote><strong>NOTE 3: </strong>Tensorflow should use M1 GPU cores by default. However, if it does not use the GPU, insert the following lines in your code to force it to use M1 GPU for computation.</blockquote><pre>from tensorflow.python.compiler.mlcompute import mlcomputemlcompute.set_mlc_device(device_name=&quot;gpu&quot;)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37444644299b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Openslide on a Windows 10 computer with Python 3.7]]></title>
            <link>https://neeraj-kumar-vaid.medium.com/installing-openslide-on-a-windows-10-computer-with-python-3-7-8c57b5cc3e40?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c57b5cc3e40</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[pathology]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Mon, 08 Mar 2021 00:20:03 GMT</pubDate>
            <atom:updated>2021-03-08T00:20:03.797Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will learn how to install Openslide-Python on a computer with Microsoft Windows 10 operating system and Anaconda Python 3.7.</p><p>Openslide-Python is a popular Python module for reading whole slide images. Whole slide images are gigapixel multi-resolution images of tissue sections and are also known as digital (or virtual) slides in the computational pathology community. Due to their enormous size, whole slide images can not be read directly into computer’s memory using standard Python libraries. Openslide provides the flexibility of loading small patches of these digital slides at the required resolution level. OpenSlide can read virtual slides in several formats including:</p><ul><li><a href="http://openslide.org/formats/aperio/">Aperio</a> (.svs, .tif)</li><li><a href="http://openslide.org/formats/hamamatsu/">Hamamatsu</a> (.ndpi, .vms, .vmu)</li><li><a href="http://openslide.org/formats/leica/">Leica</a> (.scn)</li><li><a href="http://openslide.org/formats/mirax/">MIRAX</a> (.mrxs)</li><li><a href="http://openslide.org/formats/philips/">Philips</a> (.tiff)</li><li><a href="http://openslide.org/formats/sakura/">Sakura</a> (.svslide)</li><li><a href="http://openslide.org/formats/trestle/">Trestle</a> (.tif)</li><li><a href="http://openslide.org/formats/ventana/">Ventana</a> (.bif, .tif)</li><li><a href="http://openslide.org/formats/generic-tiff/">Generic tiled TIFF</a> (.tif)</li></ul><p>Steps to install Openslide-Python on a Windows 10 platform with Anaconda Python 3.7 are as follows:</p><ol><li>Download Microsoft Visual Studio IDE (Community 2019 edition) from <a href="https://visualstudio.microsoft.com/">https://visualstudio.microsoft.com/</a></li><li>Click on the vs_community.exe file in the Downloads folder and follow the on-screen instructions. Make sure you check Desktop Development with C++ under Windows and Python Development under Web &amp; Cloud tabs. Also check MSVC 140 under the Optional tab in Summary.</li><li>Restart your computer after installing the visual studio.</li><li>Download Openslide-Python package, by clicking at the clone or download option (green button), from the following github page: <a href="https://github.com/openslide/openslide-python">https://github.com/openslide/openslide-python</a></li><li>Unzip the downloaded Openslide-Python package.</li><li>Open Anaconda Prompt and change the directory to the unzipped Openslide-Python folder.</li><li>Run the command: python set-up.py install</li><li>Download Openslide Windows binaries from the following webpage: <a href="https://openslide.org/download/">https://openslide.org/download/</a></li><li>Unzip the windows binaries folder and keep it at the location of your choice.</li><li>Go to the following folder on your computer and open lowlevel.py in a text editor: C:\Users\Gan\AppData\Local\Continuum\anaconda3\Lib\site-packages\openslide</li><li>Add the following commands at the beginning of lowlevel.py file:</li></ol><p>import os</p><p>os.environ[‘PATH’] = “path-to-openslide-bin” + “;” + os.environ[‘PATH’]</p><p>Replace path-to-openslide-bin with the path of the bin folder within windows binaries file saved at step 9 (keep the quotes). After these additions, save and close lowlevel.py file.</p><p>Now type <em>python</em> in your Anaconda Prompt and type <em>import openslide</em> to start using your newly installed module.</p><p>Sometimes <em>import openslide </em>will throw <em>SyntaxError: (unicode error). </em>To resolve this just put one more backslash before each backslash in path-to-openslide-bin so that C\Users\openslide-binaries\bin looks like C\\Users\\openslide-binaries\\bin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c57b5cc3e40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Canada — Let’s Explore]]></title>
            <link>https://neeraj-kumar-vaid.medium.com/canada-lets-explore-c128e5bedf6e?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c128e5bedf6e</guid>
            <category><![CDATA[travel]]></category>
            <category><![CDATA[facts]]></category>
            <category><![CDATA[immigration]]></category>
            <category><![CDATA[geography]]></category>
            <category><![CDATA[places]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 03:24:40 GMT</pubDate>
            <atom:updated>2021-01-25T10:19:04.854Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-nk4ENKdhJrJT7xD824Tg.jpeg" /><figcaption><strong>Beauvert Lake, Jasper National Park, Alberta, Canada</strong></figcaption></figure><h3>Canada — Let’s Explore</h3><p>Namaste Canada Musings — Chapter 1</p><p><strong>Introduction</strong></p><p>My wife and I recently moved to Canada from the USA amidst the government imposed lockdown and border closure restrictions due to COVID-19. To avoid the complications associated with air travel, we decided to drive from our nest in Ohio to our new home in Alberta, Canada. We were familiar with the landscape in the USA but were touching the Canadian land for the first time — naturally, we were ambivalent. Today, we have spent six months in Canada after crossing through that Pembina (USA) — Emerson (Canada) border and in this post, I am sharing a few interesting facts I learned about this beautiful country. Following are my notes from my quest to know Canada from various perspectives including its geography, national symbols, important days, etc. So without further ado, let’s begin with Canada’s geography.</p><p><strong>Geography</strong></p><p>Canada is the second largest country in the world after Russia and the largest country in the North American continent, with a total area of 9.98 million square kilometers. It has the world’s largest proportion of freshwater lakes and by land area alone (excluding the area covered by water) it ranks fourth in the world. Canada has 2 million lakes out of which 563 are greater than 100 square kilometers. Canada has 60% of the world’s lakes and 30% of freshwater lakes. The longest land border in the world is between the USA and Canada, which is 8,891 kilometers long. Canada has the world’s longest maritime boundary that spans 243,042 kilometers, with the Arctic Ocean in the North, Atlantic in the east, and Pacific in the west. The world’s north most remote human settlement, the Canadian Forces Station Alert in Ellesmere Island, is also in Canada and it is just 817 kilometers away from the North Pole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A-mpWFDlq_cU4Vyg.png" /><figcaption>Image Source: Google Images</figcaption></figure><p>Canada has 10 provinces and 3 territories, with Ottawa as the capital. The major difference between provinces and territories is that the Canadian constitution grants provincial and federal powers to the provinces but the territories are directly governed by the Canadian parliament. Canadian winters are harsh where average the temperature could go as low as -15 degrees Celsius, while summers could see an average temperature between 20°C to 30°C. Toronto, Montreal, and Vancouver are the three largest cities in Canada.</p><p><strong>National Symbols</strong></p><p>Now, let’s talk about some symbols of national importance in Canada and I think it is good to begin with the Canadian flag.</p><p><strong>Flag-</strong> Canadian flag features its national colors — red and white — with a white square at the centre that is bounded by two red fields in 1:2:1 ratio. It also features an 11- pointed maple leaf at the center, within the white square. The red color symbolizes the sacrifices made during both world wars and white represents the peace, tranquility, and neutrality of Canada. The maple leaf at the center is one of the prominent national symbols of Canada for over 300 years — because maple served as an important food source for several years.</p><p><strong>Tree-</strong> The maple tree is the national tree of Canada and it was adopted as a national symbol in 1996. Canada grows 10 species of the maple tree and at least one of the ten species grows naturally in every province.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qo-IUFSP8oXLvjzhOjtBjQ.png" /><figcaption>A few National Symbols of Canada: Red White Flag with 11-pointed Maple Leaf, Canadian Horse, Beaver, Ice Hockey, and Lacrosse</figcaption></figure><p><strong>Animal- </strong>The beaver and the Canadian horse are the national animals of Canada. The fur trade was a significant factor in the selection of the beaver as the national animal of Canada. Beaver pelts were used to make everything from wool felt hats to robes to winter coats to keep people warm in the harsh Canadian winters. The Canadian horse is a symbol of resilience, intelligence, endurance, and great strength.</p><p><strong>Sports-</strong> Canada has two national sports- ice hockey for winters and lacrosse for summers- and I love watching ice hockey. Canada is considered the birthplace of ice hockey, and Canadians are playing lacrosse for over 500 years.</p><p><strong>Demography</strong></p><p>The total population of Canada was 35,151,728 according to the 2016 census with a population density of 3.7 inhabitants per square kilometers, which is one the lowest in the world. Immigration is the main driver of population growth instead of natural growth in Canada. In 2019, a total of 341, 180 immigrants were admitted to Canada- including us — who came mainly from India, China, and the Philippines.</p><p>About 80% of the total population in Canada lives within 150 kilometers of the USA-Canada border. Ontario and Quebec, the two biggest provinces in Canada, account for almost 60% of the total population. The most densely populated part of the country is the Quebec City-Windsor Corridor (50% of the population) followed by the additional 30% living in British Columbia’s lower mainland (Vancouver) and the Calgary-Edmonton corridor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tD0EwJBypbcrUxqPyLF9eQ.png" /><figcaption>(a) Province-wise distribution of the Canadian population and (b) Canada population by mother tongue. The data for these charts were taken from <a href="https://www12.statcan.gc.ca/census-recensement/2016/dp-pd/index-eng.cfm">the 2016 census</a>, which recorded 35 million as the total population of Canada.</figcaption></figure><p>The Canadian population is mostly composed of whites (75%) with Asians contributing 14% of the population, of which about 4% are Indians, while natives and black/Latinos contribute 5% each. A multitude of languages is spoken in Canada with English and French being the mother tongue of 56% and 21 % of Canadians, while 1.4% of Canadians have Punjabi as their mother tongue. So, Canada is a multi-cultural and multi-ethnic society where people from different backgrounds live together in harmony and peace.</p><p><strong>Important Days</strong></p><p>Although there are several days of regional and national importance in Canada, the following is the list of those ones that I have seen people celebrating during my 6 month long stay in Canada. With time, I am sure I will be introduced to other significant days in Canadian history and culture. However, let’s begin with the ones I am currently most familiar with.</p><p><strong>Canada Day — </strong>It celebrates the anniversary of the Canadian confederation, which occurred on July 1, 1867, when the three separate British colonies of Canada, Nova Scotia, and New Brunswick were united into a single dominion called <strong>Canada</strong>. Canadians celebrate this day throughout the country as well as in various locations around the world.</p><p><strong>Victoria Day — </strong>It is celebrated on the last Monday before May 25 to honor Queen Victoria’s birthday (May 24). It is informally considered as the beginning of the summer season in Canada.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErulraddYCK-5mZ-zG1DzA.png" /><figcaption>Image Source: Google Images</figcaption></figure><p><strong>Thanksgiving Day — </strong>It is celebrated on the second Monday of October to honor the harvest and other blessings of the past year.</p><p><strong>Boxing Day — </strong>It is celebrated on 26th December, the day after Christmas. Though it originated as a holiday to give gifts to the poor (in a box), today Boxing Day is primarily known as a shopping holiday. It originated in the United Kingdom and is celebrated in a number of countries that previously formed part of the British Empire.</p><p><strong>Remembrance Day — </strong>It is celebrated on November 11 when Canadians pause in a moment of silence to honour and remember the men and women who have served and continue to serve Canada during times of war, conflict, and peace. The Poppy, a flower, is the symbol of the remembrance day — because poppies are the flowers that grew on the battlefields after World War One ended.</p><p>I have kept popular holidays, including Christmas and Labour day, out of this list because their significance is common knowledge in today’s world.</p><p><strong>Closing Remarks</strong></p><p>Finally, I am glad that you have made it to the end of this post! I know I have covered only a few things about this great and vast country called Canada, but we will explore more together when I will take you to the Canadian cities and towns. In my next post, we will travel to one of the beautiful places in the world and one of my favourite places in Canada. Till then, stay tuned! I am leaving you with a couple of more Canadian facts.</p><p><strong>The Loonie — </strong>Canadian one dollar. The most prevalent versions of the coin show a common loon, a bird found throughout Canada, on one side and Queen Elizabeth on the other.</p><p><strong>The Toonie — </strong>Canadian two dollars — Add two loonies and you will get a twonie or toonie.</p><p><strong>The Derby Line — </strong>Derby Line is known for the Haskell Free Library and Opera House, a line house deliberately constructed on the international US-Canada and opened in 1904. The intent behind constructing this line house was that people on both sides of the border would have use of the facility, which is now a designated historic site. Patrons of the library from either side of the border may use the facility without going through border security.</p><p>Canada shares its land border with only one country in the world, the United States of America. The Hudson Bay, the largest bay in Canada, is the second largest in the world after the Bay of Bengal. There are no roads to connect Nunavut, a province that occupies the fifth of Canada, to the rest of Canada — people usually travel there by air.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c128e5bedf6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hypothesis Testing I: Introduction]]></title>
            <link>https://medium.com/data-science/hypothesis-testing-i-introduction-9d4f769fef3?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d4f769fef3</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[hypothesis-testing]]></category>
            <category><![CDATA[hypothesis-test]]></category>
            <category><![CDATA[hypothesis]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 18:53:27 GMT</pubDate>
            <atom:updated>2019-06-27T23:27:28.082Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hypothesis Testing — An Introduction</h3><p>Hypothesis are our assumptions about the data which may or may not be true. In this post we’ll discuss about the statistical process of evaluating the truthiness of a hypothesis — this process is known as hypothesis testing.</p><p>Most of the statistical analysis has its genesis in comparing two types of distributions: population distribution and sample distribution. Let’s understand these terms through an example — Suppose we want to statistically test our hypothesis that<em> on average, the performance of students in a standard aptitude test has improved in the last decade</em>. We’re given a dataset containing the marks (maximum marks = 250) of 100 randomly selected students who appeared in the exam in 2009 and 2019. Given this information, we should identify the following details-</p><p>Q1. What are the population and sample distributions for this problem?</p><p>Q2. How should we statistically evaluate the correctness (or incorrectness) of the aforementioned hypothesis?</p><p>The answer to the first question lies in the amount of data we can collect to do our analysis. Ideally, we should have marks of all students (across the country) who appeared in the exam a decade ago and in the current year to make a fair comparison. But due to physical constraints we can’t get the data (marks) from all students across the country who appeared in the aptitude exam in 2009 and 2019. Hence, we use a few data points (marks) from each year to do our statistical analysis. The population distribution thus refers to the distribution of marks of all students (2009 and 20019 combined) and a sample distribution is a subset of the population distribution that contains marks of a fewer (let’s say, 100) randomly selected students. Usually, we don’t have access to the population distribution and we work only with sample distributions.</p><p>We can draw multiple samples from a population distribution, we drew two sample distributions for our example- first containing the marks of 100 students from 2009 data, and second containing the marks of 100 students from 2019 data. Let’s formally denote the unknown population distribution as P: μ, σ, n, and the known sample distributions as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2_RLIplieYtUEX56Rv44A.png" /><figcaption><strong>Equation 1:</strong> Two sample distributions for our example</figcaption></figure><p>The numbers in subscripts are last two digits of the respective years of our sample distributions. For each distribution, μ, σ and n represent their mean, standard deviation and sample size (number of samples), respectively, and values of these parameters can be computed from the given data (except for the population distribution). The second question can be answered using a three step hypothesis testing procedure as follows:</p><p><strong>Step 1: Set up the hypothesis</strong></p><p>Formally, our hypothesis <em>— on average, performance of students in a standard aptitude test has improved in the last decade, </em>can be written as <em>— is the statement, </em>μ₁₉ &gt; μ₀₉ <em>(comparing averages)</em>, <em>statistically significantly correct</em>? Our hypothesis about the data is known as <strong><em>research hypothesis</em></strong><em>. </em>We know that numerically μ₁₉ &gt; μ₀₉, but we also know that there are students in 2019 who scored below μ₀₉ because σ₁₉ &gt; σ₀₉, it’s thus important to ask — what is the statistical significance of the research hypothesis? To solve such problems we always start with a <strong><em>null hypothesi</em></strong><em>s, </em>and we assume<em> </em>that the null hypothesis is true until proven otherwise. For our example, the null hypothesis is that there is no statistically significant increase in the average marks scored by students in 2009 and 2019, — that is, μ₁₉ = μ₀₉. From the given data, we can compute the probability of correctness of the null hypothesis and if that probability turns out to be very low then we should reject the null hypothesis in favor of the research hypothesis, otherwise we should reject the research hypothesis. We’ll soon learn how to compute the desired probability but as of now we should set up our hypothesis about the given data as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BtJOlME1zp6EOEaym3l4RA.png" /><figcaption><strong>Equation 2:</strong> Setting up the hypothesis</figcaption></figure><p><strong>Step 2: Select appropriate test statistic</strong></p><p>To do this we can revoke the central limit theorem (CLT), which states that the distribution of the means of sample distributions is normal with mean μ and standard deviation σ/⎷n, i.e. Z(μ,σ/⎷n). You can read more about the central limit theorem from my earlier <a href="https://towardsdatascience.com/understanding-the-central-limit-theorem-standard-error-and-confidence-intervals-7e20c674a51a">post</a>. Although, we do not have access to P: μ, σ, n, but we know from CLT that μ₀₉ and μ₁₉ belong to a normal distribution with unknown parameters. Here comes the trickiest part of hypothesis testing, which is to transform (or map) the values of μ₀₉ and μ₁₉ from an unspecified normal distribution,Z(μ,σ/⎷n), to the standard normal distribution, i.e. Z(0,1). Essentially, we want to center the mean to zero and scale the standard deviation to 1 for the points, μ₀₉ and μ₁₉, in Z(μ,σ/⎷n). This can be done as follows for our hypothesis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4vYzvlit5VVxsisVd3NN5Q.png" /><figcaption><strong>Equation 3:</strong> Mapping our hypothesis to a standard normal distribution, Z(0,1)</figcaption></figure><p>Even after mapping the values (μ₀₉ and μ₁₉) to a Z(0,1), still the unknowns, μ, σ and n, appear in our hypothesis. We can easily remove μ by rearranging the terms in our hypothesis as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3cq857UvLI5ajbdNyEkPgA.png" /><figcaption><strong>Equation 4: </strong>Rearranging the terms in our hypothesis to get rid of the unknown μ</figcaption></figure><p>Solving the left hand side of our hypothesis in <strong>Equation 4</strong> gives us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Th-XajrxRrMhSqeVmWdr3g.png" /><figcaption><strong>Equation 5:</strong> Hypothesis without the unknown μ</figcaption></figure><p>To get rid of σ, we should replace it with the highest sample standard deviation. In our example, σ₁₉ &gt; σ₀₉, so we’ll replace σ with σ₁₉ and use the corresponding n₁₉ in the denominator of our hypothesis. Hence, our final hypothesis in terms of the known sample distribution parameters can be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfd-ugdB6DpLpFqh8mqjOA.png" /><figcaption><strong>Equation 6:</strong> Our hypothesis in terms of the known sample distribution parameters</figcaption></figure><p>Now, we can plug in the values of respective parameters from Equation 1 to Equation 6 to get the numerical values for our hypothesis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3NWXfZ-mBCe_zNohIGa6rA.png" /><figcaption><strong>Equation 7:</strong> Numerical values of our hypothesis testing set up</figcaption></figure><p><strong><em>Caution:</em></strong><em> Everyone knows that numerically 2.4 is greater than 0 in Equation 7, but please note that hypothesis testing is not a numerical comparison problem, instead it’s a statistical problem. This means that we are asking whether 2.4 is </em><strong><em>statistically significantly</em></strong><em> greater than 0 (not just, is 2.4 greater than 0?)? Here, z=2.4 is our test statistic.</em></p><p>By statistically significant we precisely mean that if we select multiple independent random samples, of 100 students each, who appeared in our aptitude test in 2019, then what is the probability that <strong>most</strong> of those random samples will have z &gt; 2.4 (implicitly meaning, μ₁₉ &gt; μ₀₉). Our random sample S₁₉ contains only one set of 100 students and the comparison of its mean (μ₁₉) with μ₀₉ gives only one test statistic (z = 2.4). But we are interested in testing a general hypothesis that if we obtain marks of another group of 100 students (randomly selected) from 2019 data then what is the likelihood that the average of the new group is also greater than μ₀₉. That’s why we test for z &gt; 2.4 and not for z = 2.4. Notice that I highlighted “most” because we should quantify what “most” means in our statistical hypothesis testing problem and we’ll do that in the next step. But first let’s calculate the probability of z &gt; 2.4, that is p(z &gt; 2.4), from the <a href="https://www.math.arizona.edu/~rsims/ma464/standardnormaltable.pdf">table</a> of the standard normal distribution, Z(0,1). At z = -2.4 (bell curve is symmetric so values at -2.4 and 2.4 are equal) we’ve <strong>p(z &gt; 2.4) = 0.0082</strong>.</p><p>You can also use <a href="http://onlinestatbook.com/2/calculators/normal_dist.html">this</a> calculator to compute p(z&gt;2.4).</p><p><strong>Step 3: Select a level of significance (α)</strong></p><p>This is the parameter we use to decide the statistical significance of our hypothesis test. To do so, let’s first look at the probability distribution of Z(0,1) as shown in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PCMZh7xGtjnSXwxyvuEzkg.png" /><figcaption><strong>Figure 1: </strong>A plot of standard normal distribution, Z(0,1)</figcaption></figure><p>From Figure 1, it is evident that 68% of the data lies within 1 standard deviation, 95% of the data lies within 2 standard deviations and 99% of the data lies within 3 standard deviations around the mean (=0) in a standard normal distribution. In hypothesis testing, we select that point as our level of significance for which at least (1-α)% of the random samples support our research hypothesis. Let’s understand this — remember I highlighted “most” in the last paragraph of step 2? That “most” is quantified in terms of the level of significance (α) in the sense that if we randomly select multiple groups, of 100 students each, who appeared in the exam in 2019 then we accept our research hypothesis (μ₁₉ &gt; μ₀₉, equivalently z&gt;2.4) only if (1-α)% of those groups have their means greater than μ₀₉.</p><p>Usually, α = 0.05 is selected to test the statistical significance of a hypothesis test. This means that we want (1-α) = 1–0.05 = 95% of random samples to support our research hypothesis. Since, we usually have one z-statistic for our hypothesis testing problem so we just want p(z &gt; z-statistic) &lt; α to accept the research hypothesis, otherwise we reject it in the favor of the null hypothesis. For our example, if we select α = 0.05 then we should accept the research hypothesis only if p(z&gt;2.4) = 0.0082 &lt; 0.05, which is indeed correct. By accepting the research hypothesis we mean — <em>with 0.05 level of significance (α = 0.05), we conclude that </em>μ₁₉ <em>is statistically significantly greater than </em>μ₀₉.</p><p>To summarize, a three step procedure is adopted for statistical hypothesis testing:</p><ol><li><strong>Set up the hypothesis:</strong> The user formulates a research hypothesis (for example, μ₁₉ &gt; μ₀₉) and selects a null hypothesis (μ₁₉ = μ₀₉) for comparison.</li><li><strong>Select appropriate test statistic:</strong> A test statistic is a single number that summarizes the sample information. For instance, we used Z statistic in our discussion and hence, our example hypothesis test is popularly known as Z-test. However, depending on the nature of the problem, a different test statistic should be appropriately selected. For example, a t-statistic (computed from Student’s t-distribution) should be used for the problems with small sample size (n &lt; 30) and the corresponding hypothesis test is known as t-test.</li><li><strong>Select a level of significance (α): </strong>To establish the statistical significance of a hypothesis test, the user selects a suitable level of significance. Since, level of significance is a probability measure, its value ranges between 0 and 1. The typical values of α used in scientific literature are 0.01, 0.05 and 0.10, with α=0.05 the most commonly used value.</li></ol><p>Finally, depending on the nature of the research hypothesis, a hypothesis test can be of three types:</p><ol><li><strong>Upper-tailed test: </strong>A hypothesis test where the research hypothesis states that the value of the parameter has increased in comparison to the null hypothesis (for example, μ₁₉ &gt; μ₀₉).</li><li><strong>Lower-tailed test: </strong>A hypothesis test where the research hypothesis states that the value of the parameter has decreased in comparison to the null hypothesis (for example, μ₁₉ &lt; μ₀₉).</li><li><strong>Two-tailed test: </strong>A hypothesis test where the research hypothesis states that the value of the parameter has changed in comparison to the null hypothesis (for example, μ₁₉ ≠ μ₀₉). Noticeably, a two-tailed test is a test of inequality instead of increase or decrease in the value of the parameter of interest.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d4f769fef3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/hypothesis-testing-i-introduction-9d4f769fef3">Hypothesis Testing I: Introduction</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[Understanding the Central Limit Theorem, Standard Error and Confidence Intervals]]></title>
            <link>https://medium.com/data-science/understanding-the-central-limit-theorem-standard-error-and-confidence-intervals-7e20c674a51a?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e20c674a51a</guid>
            <category><![CDATA[confidence-interval]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[central-limit-theorem]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Tue, 14 May 2019 13:29:39 GMT</pubDate>
            <atom:updated>2019-05-15T04:55:23.126Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Central Limit Theorem, Standard Error and Confidence Intervals</h3><h4>A worked example to understand aforementioned concepts</h4><p>In this post we’ll build intuitive understanding of descriptive statistics including mean and standard deviation, and inferential statistics including standard error of the mean, and confidence intervals. We’ll also develop an understanding of the central limit theorem in this process. The R code used for generating examples in this post is available <a href="https://github.com/neerajkumarvaid/Blogpost-Codes/blob/master/Code%20for%20CLT_SE_CI.R">here</a>.</p><p>Let’s begin our journey by assuming that we have N = 10,000 students in a country who studied Physics in their l0th grade. We noted the marks they obtained, out of 100, after their final exam and the histogram (with intervals of 10) of these marks is shown in Figure 1. This histogram represents our population distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*qxUL9uhc-4fS40pmOcmQqg.png" /><figcaption><strong>Figure 1</strong> Histogram of the marks obtained by all 10th grade students in Physics across the country (population distribution).</figcaption></figure><p>Now, we can calculate population mean (μ), and standard deviation (σ) using following formulas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcIhlsEvi6IXdwb5W3LXkg.png" /></figure><p>where xᵢ represents the marks scored by iᵗʰ student, and N is the total number of students across the country. For the population distribution shown in Figure 1, μ = 71.52 and σ = 16.15. These both are descriptive statistics because they describe some features of the data in hand. Mean represents centrality of the data (center is median) and standard deviation represents how much each point differs from the mean in the average sense. A small σ means that the values in a data set are close to the mean of the data, on average, and a large σ means that the values in a data set are farther away from the mean, on average. We can see that our population distribution has a longer tail on the left compared to the right and such distributions are known as left skewed.</p><p>It should be noted that our population distribution requires data from all students across the country. This requirement is practically very difficult to fulfill and we usually do not have access to the population distribution (and associated descriptive statistics: μ and σ). In such situations we resort to random sampling to <em>infer </em>descriptive statistics of the underlying population distribution from the descriptive statistics of the sample distribution — let’s understand this!</p><p>Random sampling means that instead of collecting data from all students, i.e. entire population, we randomly select a few representative students across the country to do our analysis. Let’s assume that in our first random sampling attempt s1, we selected n₁= 50 representative students across the country and noted down their marks. Let’s denote the descriptive statistics for s₁ as μ₁ and σ₁, and let’s also denote our first random sampling event as, s₁: n₁,μ₁,σ₁. Following this notation and the random sampling procedure we can randomly select multiple groups of representative students from our population distribution. Remember, the population distribution includes all students across the country and a sample distribution contains only 50 randomly selected students — each sample distribution is a subset of the population distribution.</p><p>How the descriptive statistics of our sample distributions relate to the descriptive statistics of our population distribution? The answer is given by the <strong>central limit theorem</strong>, which in simple words states that –</p><p>For <a href="https://en.wikipedia.org/wiki/Statistical_independence">independent random variables</a>, the distribution of the means of the sample distributions tends toward a normal distribution (informally a “<em>bell curve</em>”), irrespective of the shape of the population distribution.</p><p>Now, let’s apply this theorem to our example and see what can we understand through this exercise. Random variables in our case are the marks obtained by each student and these are indeed independent random variables because the marks scored by one student are independent of the marks scored by another. Going further, let’s say we obtain r = 20 random samples, each with n = 50 students, from our population distribution and these sample distributions can be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*nNEunk1WEOups0gVrWUkdg.png" /></figure><p>here, n₁ = n₂ = … nᵣ = 50, and r = 20. Mean of the 20 sample means can be computed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*dNC40rWthD1_VC20tSusRQ.png" /></figure><p>Let’s now plot the means of our 20 sample distributions and see what their distribution looks like. From figure 2, it is evident that the distribution indeed looks like a bell curve irrespective of the shape of our population distribution (which is actually Beta distribution, see code for details).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*4HkTFEsFNoz2shd1cT-R7w.png" /><figcaption><strong>Figure 2 </strong>Distribution of the means of 20 random samples (μ₁, μ₂,…,μ₂₀). Mean of the sample means (μ₂₀means = 72.26) yellow dashed vertical line, and actual population mean (μ = 71.52), green vertical line, are also plotted for comparison.</figcaption></figure><p>The normality of the distribution of the sample means is much stronger if we obtain (r=) 80 random samples (each of size n = 50), instead of (r=) 20, as shown in Figure 3. The mean of the 80 sample means can be computed as follows-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*hWCSOz9N1wVMoJ_my8Ciyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*A4rXydtZfDxEutQhNvfpSg.png" /><figcaption><strong>Figure 3 </strong>Distribution of the means of 80 random samples (μ₁, μ₂,…,μ₈₀). Mean of the sample means (μ₈₀means = 71.66) yellow dashed vertical line, and actual population mean (μ = 71.52), green vertical line, are also plotted for comparison.</figcaption></figure><p>It is also evident from Figure 2 and Figure 3 that the mean of the sample means moves closer to the population mean as we draw more random samples. Notice, that with only r*n = 80*50 = 4000 student scores we can get a sufficiently accurate estimate (μ₈₀means = 71.66) of the population mean (μ = 71.52) of N = 10,000 student scores. This means that if we have sufficient number of random samples then we actually do not need the entire population distribution for our analysis.</p><p><strong>Q. Should we use multiple random samples, each with a smaller number of observations, or a single random sample with larger number of observations for an actual data analysis problem?</strong></p><p>We just saw that using 80 random samples, each with 50 observations (student scores), we can closely approximate the mean of the underlying population distribution. However, in practice, we usually work with one random sample containing sufficiently large number (n) of data points (student scores) such that n ≪ N, here, n represents the number of students in our random sample and N represents the entire population of students across the country.</p><p>Now onwards, we’ll work with a single random sample containing n students, and let’s denote the standard deviation and mean of this random sample as s and μₑ (e as in estimate), respectively. Figure 4 shows that the principles of the central limit theorem still hold — for n = 4000, the distribution of our random sample is bell shaped and its mean μₑ = 71.58, is a good estimate of the population mean (μ = 71.52).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*Ge6GYEIDx9pha-VgXx4b2g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*s5hclR33wKfPSmBESIEK5w.png" /><figcaption><strong>Figure 4 </strong>Distribution of a random sample containing n = 4000 observations. Sample mean (μₑ = 71.58), yellow dashed vertical line, and actual population mean (μ = 71.52), green vertical line, are also shown for comparison.</figcaption></figure><p>It is important to note that both, μₑ and s, are themselves random variables because their values depend on the strategy used for random sampling.</p><p><strong>Inferential Statistics</strong></p><p>Aforementioned observations have great implications for data analysis because we usually do not have access to the entire population and thus descriptive statistics of the population distribution are usually unknown. In such situations, the central limit theorem provides us with a way to do data analysis with randomly selected data points and <em>preciseness of such analysis </em>can be quantified using <em>inferential statistics</em> including standard error of the mean and confidence intervals, which are discussed next. These statistics are inferential because we use randomly sampled distributions to infer characteristics of the underlying population distribution.</p><p><strong>Standard error of the mean (SEM)</strong>: From central limit theorem, we know that our sample distribution is normal with mean =μₑ. But μₑ itself is a random variable as it depends upon the choice of our random samples. In other words, any change in our sample distribution changes our μₑ. Standard error of the mean simply quantifies this change by computing the standard deviation of our estimate, μₑ, of the underlying population mean (μ). Formally, it can be computed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8rpsN2KQqfLpNlxBKB03ZQ.png" /></figure><p>Taking the square root on both sides of above equation we get the desired standard error of the mean:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*bLmg8fYPNTmd8r6glKTDAg.png" /></figure><p>Notice, that we can use a single random sample with sufficient sample size (n) to compute standard error estimate of the population mean. If we have sufficiently large n we can obtain almost zero standard error. This means that if we have a large random sample of data points then the mean of our sample distribution accurately approximates the mean of the underlying unknown population distribution. Thus, a higher n is often desired in various machine learning and statistical problems for better generalizability.</p><p><strong>Confidence Intervals:</strong> A confidence interval is an interval around the estimated mean (μₑ) that is likely to include the unknown population mean (μ). Let’s understand this — we want to estimate the mean, μ, of the underlying population distribution and we have access to a random sample containing n observations with standard deviation s and mean μₑ. Confidence intervals are constructed at a <em>confidence level</em>, such as 95%, selected by the user. The confidence level describes the uncertainty associated with a <em>sampling method</em>. Suppose we used the same sampling method to select multiple random samples and computed confidence intervals using μₑ of each random sample. We’ll naturally have multiple confidence intervals (one around every μₑ). Some of these interval estimates would include the population mean, μ, and some would not. A 95% confidence level means that we would expect 95% of the interval estimates would include the population mean. Usually, we work with only one random sample containing large number of data points and in such case we have only one confidence interval estimate that can be computed as follows for 95% confidence level:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*VAzRWv0XY6owtioxG2qtxg.png" /></figure><p>Note that the term after plus-minus sign on right hand side of above equation quantifies the uncertainty in the estimate of population mean (μ) in terms of sample mean (μₑ). 1.96 is multiplied to the standard error of the mean because for a standard normal distribution, N(0,1), 95% of the data lies within 1.96 standard deviations around the mean as shown in Figure 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XtBhY43apW_xIyf23eOWow.png" /><figcaption><strong>Figure 5 </strong>Standard normal distribution with mean 0 and standard deviation 1, N(0,1) [Image from <a href="https://en.wikipedia.org/wiki/Standard_error#/media/File:Standard_deviation_diagram.svg">Wikipedia</a>]</figcaption></figure><p>Sometimes, 1.96 is rounded up to 2 for calculation purposes. Lastly, higher standard error leads to wider confidence interval, which indicates that the mean, μₑ, of our random sample is not a good approximation of the mean, μ, of the underlying population distribution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e20c674a51a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/understanding-the-central-limit-theorem-standard-error-and-confidence-intervals-7e20c674a51a">Understanding the Central Limit Theorem, Standard Error and Confidence Intervals</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[Statistical Performance Measures]]></title>
            <link>https://neeraj-kumar-vaid.medium.com/statistical-performance-measures-12bad66694b7?source=rss-9cdbc8edbceb------2</link>
            <guid isPermaLink="false">https://medium.com/p/12bad66694b7</guid>
            <category><![CDATA[accuracy]]></category>
            <category><![CDATA[accuracy-and-precision]]></category>
            <category><![CDATA[f1-score]]></category>
            <category><![CDATA[ds-in-the-real-world]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Neeraj Kumar Vaid]]></dc:creator>
            <pubDate>Sat, 04 May 2019 23:57:28 GMT</pubDate>
            <atom:updated>2019-05-05T00:08:11.031Z</atom:updated>
            <content:encoded><![CDATA[<p>How to select the best model from the available options?</p><p>Statistical performance measures are often used for model selection in machine learning and statistical inference. From multiple models trained with different sets of hyper-parameters and parameters, the one that gives best performance in terms of a selected performance criterion is finally adopted. Let’s understand commonly used performance metrics for model selection through an example so that we can choose one of these for our model selection.</p><p>Let’s assume that we have a pregnancy test that gives us binary results, positive (or 1), if tested individual is pregnant and negative (or 0) if tested individual is not pregnant (~pregnant). Now, we can define the following outputs for this binary test-</p><p><strong>True positive</strong>: Test results are + when an individual is pregnant</p><p><strong>True negative</strong>: Test results are - when an individual is not pregnant</p><p><strong>False positive (Type I error)</strong>: Test results are + when an individual is not pregnant</p><p><strong>False negative (Type II error)</strong>: Test results are - when an individual is pregnant</p><p>These four scenarios are illustrated in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*T5mfQqhcn-nB-n7LOiPv6A.png" /><figcaption><strong>Figure 1</strong> Four possible combinations of reality and our binary pregnancy test results</figcaption></figure><p>Let’s say we evaluate N randomly selected individuals for pregnancy using our test and note down the number of True positives, False positives, True negatives and False negatives. Using these numbers we can create a 2 x 2 matrix, known as confusion matrix, as shown below-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZpE8x4gQvdxXAXZNyxl_Q.png" /><figcaption><strong>Figure 2</strong> Confusion matrix for comparing reality (or ground-truth) with the binary pregnancy test results</figcaption></figure><p>Using information in Figure 2, we can define the following performance metrics to assess the quality of our pregnancy test-</p><p><strong>Sensitivity (recall or true positive rate, TPR)</strong>: Divide the number of true positives (test results) with total number (out of N) of pregnant women (ground truth) to compute sensitivity as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sg-It8UlHsokv_eHTDWgYQ.png" /></figure><p>Sensitivity or recall gives us the conditional probability of getting a + test result given that the individual is pregnant, p(test = + | individual = pregnant). Sensitivity (or recall) is a good measure for model selection if the cost of false negatives is very high. For our pregnancy test, the cost of a false negative decision (test negative for an actually pregnant individual) is indeed very high compared to that of a false positive decision (test positive for an individual not pregnant) because of the healthcare issues involved.</p><p><strong>Specificity (true negative rate, TNR)</strong>: Divide the number of true negatives (test results) with total number (out of N) of women who are not pregnant (ground truth) to compute sensitivity as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N6qkY6RMmCGZ93Lvcg7vDA.png" /></figure><p>Specificity gives us the conditional probability of getting a - test result given that the individual is not pregnant, p(test = - | individual = ~pregnant). <br>Specificity assesses the test’s ability to correctly identify patients who are not pregnant.</p><p><strong>Precision (positive predictive value, PPV)</strong>: Divide the number of true positives (test results) with the total number of predicted positives (test results) to compute precision as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uxvdva45ymxywuW9qfEA-Q.png" /></figure><p>Precision is a good measure for model selection if the cost of false positives is very high. Notice the difference between sensitivity and precision, sensitivity is computed with respect to the ground truth while precision uses only test results in its computation.</p><p><strong>False discovery rate (FDR)</strong>: It simply tells us how many false positives are given by our pregnancy test out of the total number of predicted positives (test results) and can be computed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HHI6LQYqXsrk8w0eCERPoQ.png" /></figure><p><strong>Negative predictive value (NPV)</strong>: Divide the number of true negatives (test results) with the total number of predicted negatives (test results) as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xh2fO2GRcSR2QvF-vIiDxA.png" /></figure><p>Notice the difference between specificity and NPV, specificity is computed with respect to the ground truth while NPV uses only test results.</p><p>The aforementioned measures mostly emphasize on one type of model errors or correctness as indicated by terms in their numerators and denominators. For example, sensitivity (or recall) only assess true positives with respect to all actual positives, while precision only assess true positives with respect to all predicted positives. The following measures combine the two types of model errors in certain ways to give more comprehensive measures of model performance.</p><p><strong>Accuracy</strong>: For our binary pregnancy test, accuracy simply tells us how many pregnancy test results are correct. This means that out of all individuals tested, how many test predictions match to their actual pregnancy status and can be computed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*96fJV0U3xc_nCjwArDud7g.png" /></figure><p>Noticeably, accuracy treats all types of model errors equally, that is, committing a false positive mistake is as fatal as committing a false negative mistake.</p><p><strong>F1 score (or Dice coefficient)</strong>: Since, precision and recall gives importance to two different types of errors, it is then useful to combine them to penalize both errors simultaneously. F1 score does this by computing the harmonic mean of precision and recall as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zynQQ4NjClu26uAtaVP0SQ.png" /></figure><p><strong>Jaccard Index (JI)</strong>: It’s similar to F1 score and can be computed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vxchDBFedZizhXYRFiHtUg.png" /></figure><p>Since, F1 score uses both precision and recall in its computation, it is a better measure than accuracy for (1) imbalanced classes (or uneven class distributions), and (2) when the costs of making two types of errors are different. Using both recall and precision in its computation, F1 score balances out the differences in class distributions and errors costs.</p><p>However, there are two limitations to F1 score: (1) it gives equal importance to precision and recall, (2) it doesn’t take true negatives into account. For these special cases, Matthews correlation coefficient or Cohen’s kappa coefficient can be used. Now, let’s answer two important questions regarding these statistical measures.</p><p><strong>Q1.</strong> How to adapt these binary measures of performance for a multi-class problem?</p><p><strong>Ans.</strong> There are two ways to do this: (1) We can use 1 vs. all approach where we compute confusion matrix for test results of one class versus all other classes in our model and then average these over all classes, (2) we can compute K x K confusion matrices (for K classes) and then extract 2 x 2 confusion matrices for two specific classes for computing binary performance measures which can then be averaged over all possible pairs of classes to obtain average binary performance measures.</p><p><strong>Q2. </strong>What makes these measures of performance statistical?</p><p><strong>Ans.</strong> This is because we use random sampling to select N individuals for evaluating our pregnancy test. All individuals in the world represent a population and our N individuals represent a sample of that population. Any measure we compute using N individuals (such as accuracy, F-score, average age, average weight, etc.) is a sample measure and it may or may not be good approximation of the population measure. Deviation of sample measures from population measures is an important factor in assessing the generalizability of a model trained on N samples. And this deviation is often quantified in terms of other statistical measures including standard error, confidence intervals, etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12bad66694b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>