<?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 Amazing-Grace Umoren on Medium]]></title>
        <description><![CDATA[Stories by Amazing-Grace Umoren on Medium]]></description>
        <link>https://medium.com/@umorenamazinggrace?source=rss-fccadf0b2173------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zrM5Nyl0LQMqv8Ks0vIZCw.jpeg</url>
            <title>Stories by Amazing-Grace Umoren on Medium</title>
            <link>https://medium.com/@umorenamazinggrace?source=rss-fccadf0b2173------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:17:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@umorenamazinggrace/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[SQL Joins: Understanding the Theory.]]></title>
            <link>https://medium.com/@umorenamazinggrace/sql-joins-understanding-the-theory-388ae2ac3f4?source=rss-fccadf0b2173------2</link>
            <guid isPermaLink="false">https://medium.com/p/388ae2ac3f4</guid>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Amazing-Grace Umoren]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 07:27:28 GMT</pubDate>
            <atom:updated>2023-06-15T07:27:28.201Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding the concept of joins in SQL seemed impossible for a while until I fully grasped the theory behind it, and then I was able to write SQL joins! For many people mastering SQL joins seems like an impossible mission. Through this article, I’ll be breaking down the various types of joins as simply as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZmOgGH_0e51gvTeSc688w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@varpap?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Vardan Papikyan</a> on <a href="https://unsplash.com/photos/DnXqvmS0eXM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>What Exactly are Joins and Why Do I Need Them?</h4><p>Imagine yourself as a librarian, you are responsible for managing the library inventory, you are responsible for keeping track of every book borrowed or returned. You have two tables: one which contains details on all books available in the library(Books Table), and another containing the borrowing history in the library(BorrowingHistory Table). To effectively keep track of book loans and records, you need Joins!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*eUl6r4uSYP-BDJ8W29oFAQ.png" /></figure><p>By joining both tables based on a common column (BookID), you can tell when a book was borrowed and by whom. This allows you, as a librarian, to effectively manage and keep track of information in the library.</p><p>Joins allow us to work with multiple tables, combining rows based on a common column in both tables. This allows for efficient data retrieval. By leveraging joins, we can merge data from different tables into a single result set, eliminating the need for multiple queries and manual data manipulation. Joins enable us to establish meaningful relationships between tables, facilitating data exploration, aggregation, and calculations.</p><h4>The Key to Joins</h4><p>In understanding “joins”, we need to, first of all, understand “keys”. Keys are identifiers in a table. For example, in the Book table above, “Book ID” is a key. Keys are used to identify rows of a table and allow you to establish relationships between tables (<em>which is what “joins” is about!</em>). When working with joins, there are two major keys used — the primary key and the foreign key.</p><p>A primary key is a unique identifier in a table i.e. it uniquely identifies each row in a table. A primary key can not be null or a duplicate. When performing joins, primary keys are used to form connections with a different kind of key in the other table. There can be only one primary key in a table.</p><p>A foreign key in one table refers to the primary key in another table. It links two different tables. More than one foreign key can be present in a table, and duplicates are allowed.</p><p>For the tables above, BookID (in the Book table) and BorrowID (in the BorrowingHistory table) are the primary keys. BookID(in the BorrowingHistory table) is the foreign key — it refers to the primary key in the Book table.</p><h4>Types of Joins</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LBTF0fLczIBiXCD0_KWb1Q.png" /><figcaption>Image by <a href="https://medium.com/@andreasmartinson?source=post_page-----ede15f9583fc--------------------------------">Andreas Martinson</a></figcaption></figure><ol><li>Inner Join</li><li>Right Join</li><li>Left Join</li><li>Full Join</li></ol><h4><strong>Inner Join</strong></h4><p>An inner join is the simplest and easiest-to-use join of all the SQL joins. It returns records from both tables where there is a match based on certain join conditions i.e. the primary key is equal to the foreign key.</p><pre>SELECT *<br>FROM Books<br>INNER JOIN BorrowHistory ON Books.BookID = BorrowHistory.BookID;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xDpyvOcTJV45YlhA_ph2jA.png" /></figure><h4>Right Join</h4><p>A right join returns all values of the right table and values from the left table that satisfies the join condition. If there are no matches, it returns a null value.</p><pre>SELECT *<br>FROM Books<br>RIGHT JOIN BorrowHistory ON Books.BookID = BorrowHistory.BookID;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MH7-btgJmKKQunX7iINYtQ.png" /></figure><h4>Left Join</h4><p>A left Join is similar to a right join, the difference between these two joins is that it returns all values on the left table and corresponding matches on the right table. If there are no matches, it also returns a null value.</p><pre>SELECT *<br>FROM Books<br>LEFT JOIN BorrowHistory ON Books.BookID = BorrowHistory.BookID;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgDmcYFUkE_LyrfyjEJr7A.png" /></figure><h4>Full Join</h4><p>A full join, also known as a full outer join, takes all rows from both the left and right table and returns all corresponding values. If there are no matches, it returns a null value.</p><pre>SELECT *<br>FROM Books<br>FULL OUTER JOIN BorrowHistory ON Books.BookID = BorrowHistory.BookID;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzxfZgWYnsdYqFDrTKcfYQ.png" /></figure><h4>Choosing the Right Join Operation</h4><ol><li>Inner joins can be used when you need to extract data that exists in both tables, filtering out non-matching records.</li><li>Left joins are useful when you want to retrieve data from one table while considering the relationships with the other table.</li><li>Right joins can be useful when the right table is the primary focus or when the desired results are more easily expressed using a right join.</li><li>Full outer joins can be used when you need to include all data from both tables to get a complete picture, regardless of matches or non-matches.</li></ol><p>Overall, selecting the kind of SQL join to use is dependent on the desired result and an understanding of the relationship between the tables.</p><h4>Conclusion</h4><p>In summary, understanding SQL joins allows you to combine data from various tables, extract information and perform advanced data analysis tasks. Leveraging the power of SQL joins is an essential skill to have while working with relational databases. So, let’s embrace the power of joins and embark on a journey of efficient data manipulation and analysis!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=388ae2ac3f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Types in SQL]]></title>
            <link>https://medium.com/@umorenamazinggrace/data-types-in-sql-86c41dbba854?source=rss-fccadf0b2173------2</link>
            <guid isPermaLink="false">https://medium.com/p/86c41dbba854</guid>
            <category><![CDATA[data-analyst]]></category>
            <category><![CDATA[data-type]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Amazing-Grace Umoren]]></dc:creator>
            <pubDate>Sat, 02 Apr 2022 14:38:17 GMT</pubDate>
            <atom:updated>2022-04-02T14:40:15.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*msZuYyvuXQYS0Vf5" /><figcaption>Photo by <a href="https://unsplash.com/@casparrubin?utm_source=medium&amp;utm_medium=referral">Caspar Camille Rubin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>SQL(Structured Query Language) is a programming language used in communicating with a relational database by allowing its users store, retrieve and manipulate data in the database.</p><p>SQL is a user friendly and easy to use programming language and like learning any other programming language, it is important to understand what data types are, what they do and how to use them.</p><h4><strong>What Is a Data Type?</strong></h4><p>In simple words, a data type of a particular variable tells the computer how to use that variable i.e a variable “A” of one data type would not be handled by the interpreter or compiler, the same way variable “B” of a different data type would be handled.</p><p>Every variable stored within the computer must be assigned a data type, a data type allows the computer know what mathematical, logical or relational operation to perform on a variable without leading to an error.</p><p>The common types of data types in most programming languages includes: Integers, Float, Boolean, String and Character.</p><h4><strong>SQL Data Types</strong></h4><p>While storing data in a database, it is best practice for every column to be assigned to a data type, it is a great help when handling a large database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHGanu2NglBqUj7W2OlNFA.png" /><figcaption>SQL DATA TYPES</figcaption></figure><blockquote>Data types may vary across various relational databases i.e what works in MySQL might not work on Oracle</blockquote><p>In SQL data types are generally divided into 5 categories:</p><ol><li>Numeric Data Types</li><li>Character String Data Types</li><li>Date and Time Data Types</li><li>Binary Data Types</li><li>Unicode Character String Data Types</li></ol><h4>Numeric Data Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*Tx1pWt9UMhZOtRFoeQbliQ.jpeg" /></figure><p>Numeric data types as the name implies deals with numbers, and as such are data that only in the form of numbers and not in a descriptive form.</p><p>Types of Numeric Data Types in SQL are:</p><ul><li>Int — int, bigint, smallint, tinyint</li><li>Bit</li><li>Numeric</li><li>Decimal</li><li>Float</li><li>Real</li><li>Money — money, smallmoney</li></ul><p><strong>INTEGERS : </strong>Integers (int) are usually the typical choice when selecting a numeric data type. They are allocated 4 bytes of memory storage and allow whole numbers between the range of -2,147,483,648 and 2,147,483,647.</p><p><strong>BIGINT : </strong>bigint numeric data type is the larger version of int, they occupy a larger amount of memory (8 bytes) and allow a wider range of values. (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,808).</p><p><strong>SMALLINT : </strong>smallint occupies half a normal integer data type memory size(2 bytes) and allow a range of whole numbers between -32,768 and 32,767.</p><p><strong>TINYINT : </strong>tinyint are integer data types but occupy a smaller memory size (2 bytes). They allow for whole numbers between the range of 0 to 255.</p><p><strong>BIT : </strong>allows integer values of 0 or 1.</p><blockquote>While choosing data types, take the memory size of the data type into consideration. Choosing “int” for a column that would that has only values between 0 to 255 would come at a performance cost. It would be preferable to use “tinyint” in such scenarios.</blockquote><p><strong>NUMERIC :</strong> numeric data type takes two arguments- <em>precision</em> and <em>scale</em><strong><em>.</em></strong> <strong>Precision </strong>is the maximum total number of digits a number can have (default = 18) while <strong>Scale</strong> is the number of digits after a decimal point (default = 0). The memory space allocated to a numeric data type varies according to its precision. numeric(p,s) allow precision within the range of 1 to 38 and a range of values between -10³⁸ +1 to 10³⁸ –1.</p><p><strong>DECIMAL :</strong> decimal data type is similar to the numeric data type and are sometimes used interchangeably, they both take <em>precision </em>and <em>scale</em> as arguments and allow the same range of values.</p><blockquote>numeric data type strictly obeys the exact specified input of precision and scale while decimal is more flexible and may allow more than the specified precision.</blockquote><p><strong>FLOAT : </strong>float(n) is an approximate numeric data type and allows a range of values between −1.79E+308 and 1.79E+308. Its memory allocation size depends on the value of n.</p><p><strong>REAL : </strong>real is also an approximate numeric data type with a range of values between −3.40E+38 and 3.40E + 38. Real occupies 4 bytes of memory.</p><p><strong>MONEY : </strong>money data types represent monetary or currency data. They are allocated 8 bytes of memory space and allow data between -922,337,203,685,477.5808 to 922,337,203,685,477.5807.</p><p><strong>SMALLMONEY:</strong> smallmoney is the lite data type version of money with 4 bytes allocated to it, it allows data between -214,748.3648 to 214,748.3647.</p><h4>Character String Data Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*dju2iK7dZvOcQtvOHBkTQw.png" /></figure><p>Character string data types are data types that stores data that contains alphabets, digit, punctuation and any other valid character. Examples are names, email addresses, descriptions…</p><p>Character string data types in SQL are:</p><ul><li>Char</li><li>Varchar</li><li>Text</li></ul><p><strong>CHAR :</strong> char(n) is a fixed length data type, with a maximum size of 8,000 characters. If n is to be 12 and only ‘abc’ is the given value for the column defined by char(12), the remaining length is filled up with blank characters, thus the fixed width. The memory allocated to char(n) is equivalent to n bytes.</p><p><strong>VARCHAR : </strong>varchar(n) is a variable length data type with a size within the range 0 to 8000 bytes, it takes n + 2 bytes of memory.</p><p><strong>TEXT :</strong> text is a variable length data type that takes up to 2,147,483,647 characters except Unicode characters.</p><h4>Date and Time Data Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*oikKb678E3T-5mUNUmnzSA.png" /></figure><p>Date and time data type are data types used for storing date and time data in various formats.</p><p>Date and Time Data Types in SQL are:</p><ul><li>Date</li><li>Time</li><li>Datetime</li><li>Smalldatetime</li></ul><p><strong>DATE : </strong>date data type stores date in the format YYYY-MM-DD and takes up fixed memory of 3 bytes. The supported range of data is between 0001–01–01 through 9999–12–31.</p><p><strong>TIME :</strong> time data type stores time in hh:mm:ss format. The supported range of values is from 00:00:00.0000000 to 23:59:59.9999999 with a memory size allocation of 5 bytes.</p><p><strong>DATETIME :</strong> datetime is a date and time combination in the format YYYY-MM-DD hh:mm:ss which takes up 8 bytes of memory space. The supported range is from 1753–01–01 00:00:00&#39; to 9999–12–31 23:59:59.</p><p><strong>SMALLDATETIME :</strong> smalldatetime is a mini datetime datatype, in the same format as datetime. The supported range is 1900–01–01 through 2079–06–06. smalldatetime occupies 4 bytes of memory.</p><h4>Binary Data Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*2e8MQBiL2zdJPt19sYaWXA.jpeg" /></figure><p>Binary data types are unstructured data types that stores different types of information.</p><p>Binary Data Types are:</p><ul><li>Binary</li><li>Varbinary</li></ul><p><strong>BINARY : </strong>binary(n) takes up a fixed length binary data between 0 and 8000 bytes. The memory occupied by binary(n) is equivalent to the value of n.</p><p><strong>VARBINARY :</strong> varbinary(n) is a variable length data type with the range of data between 0 to 8000 bytes. It occupies 2 + length of data bytes of memory.</p><h4>Unicode Character String Data Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*WbsVA6-U3DDYfUcagQsFTA.jpeg" /></figure><p>Unicode character string data types stores fixed length or variable length data Unicode character data.</p><ul><li>Nchar</li><li>Nvarchar</li></ul><p><strong>NCHAR</strong> : nchar(n) is similar to char(n) except it can hold Unicode characters and allows a maximum of 4000 chars and a minimum of 0 chars. It occupies 2*n bytes of memory.</p><p><strong>NVARCHAR : </strong>nvarchar(n) is also similar to varchar, the difference is that it can hold Unicode characters allows up to 4000 chars. It occupies 2*n + 2 bytes of memory.</p><blockquote>SQL allows more data types than has been discussed in this article.</blockquote><p>I hope you enjoyed reading, don’t forget to share and drop a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86c41dbba854" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Statistics with Python II]]></title>
            <link>https://medium.com/@umorenamazinggrace/statistics-with-python-ii-295b15b5efe6?source=rss-fccadf0b2173------2</link>
            <guid isPermaLink="false">https://medium.com/p/295b15b5efe6</guid>
            <category><![CDATA[normal-distribution]]></category>
            <category><![CDATA[poisson-distribution]]></category>
            <category><![CDATA[binomial-distribution]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Amazing-Grace Umoren]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 18:05:00 GMT</pubDate>
            <atom:updated>2021-09-27T18:05:00.952Z</atom:updated>
            <content:encoded><![CDATA[<p>In my <a href="https://medium.com/@umorenamazinggrace/statistics-with-python-i-729503c48ee4">last article</a>, we looked at measures of central tendency and the measures of dispersion and how they can be implemented with some of the packages and modules that python provides. In this article, we would be looking at another aspect of inferential statistics in this case <strong>probability</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PgOBPtC10UAD5Bpf" /><figcaption>Photo by <a href="https://unsplash.com/@tamiminaser?utm_source=medium&amp;utm_medium=referral">Naser Tamimi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is probability?</h3><p>Probability is a branch of mathematics and a part of statistics that deals with calculating the likelihood of a given event’s occurrence, which is between the range of 0 and 1. 1 being the event certainly happening and 0 being the event not happening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*wtCAawgoWeGEzmkfmllqHg.png" /></figure><h3><strong>Probability Distribution</strong></h3><p>A probability distribution is a mathematical function that gives the probabilities of occurrence of different possible outcomes for an experiment. It describes all the possible values and likelihoods that a random variable can take within a given range.</p><p>A probability distribution is either <strong>discrete or continuous</strong>. A discrete probability distribution counts occurrences that have countable or finite outcomes. Common examples of discrete probability distributions include Binomial, Poisson, Bernoulli. A continuous distribution describes the probabilities of the possible values of a continuous random variable. Common examples of continuous probability distributions include Uniform, Normal.</p><h4>Normal Distribution</h4><p>Normal distribution is a continuous probability distribution also known as the Gaussian distribution which is symmetric about the mean. The graphical representation of a normal distribution is a “bell curve”. In a perfect normal distribution, the mean, median and mode are of the same and appear at the peak of the curve. All normal distributions are symmetrical, that is the curve can be divided at the center to produce two equal halves. In the real world, real data does not always follow a normal distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*3FA0aQJkObjM1aIUOPYz2g.png" /></figure><p>Skewness and kurtosis are measure of coefficient that measures how different a distribution is from a normal distribution. Kurtosis measures the thickness of the tail ends relative to the tails of a normal distribution. Skewness measures the symmetry of a distribution, it is the measure of the degree of asymmetry of a distribution from a normal distribution. A distribution can be said to right(positively) skewed or left(negatively) skewed. The mean of a positively skewed distribution is greater than the median, it is the opposite in the case of a negatively skewed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*4n2tvkqwpREDFaXl56FpLA.jpeg" /></figure><p>The graph of a normal distribution is characterised by two parameters which determine the shape and probability of the distribution: <strong>Mean</strong> which determines the center of the peak, and <strong>standard deviation</strong> which is how wide the peak is or how spread out the data is.</p><p>To plot a normal distribution using python, we can use the following code snippet:</p><pre>#Import required libraries<br>import numpy as np<br>import matplotlib.pyplot as plt</pre><pre>#creating a series of data between 1 to 25<br>x = np.linspace(1,25)</pre><pre>pdf = (np.pi*np.std()) * np.exp(-0.5*((x-np.mean())/np.std())**2)</pre><pre>plt.plot(x, pdf)<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*3NFV4W3c7p1Cj5YBFm8j3w.png" /></figure><h4>Poisson Distribution</h4><p>Poisson distribution is a discrete probability that gives the probability of a given number of events at a fixed interval of time. They are used to understand independent events that occur at a constant rate within a given interval of time. Poisson distribution can only take discrete count variable and are sometimes referred to as <strong>count distribution.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*OlAexwzKGfcURV1BlU68ZQ.jpeg" /></figure><p>We can implement Poisson distribution in python using numpy package or scipy library.</p><p>Using numpy, the numpy.random.poisson takes two argument lam which takes a float or an array of floats which is the expected number of events occurring in a fixed-time interval and must be greater than or equal to 0 and size takes an integer or a tuple of integer.</p><pre>import numpy as np</pre><pre>x = np.random.poisson(lam=4, size=300)</pre><pre>print(x)</pre><p>We can also generate a Poisson random variable using the scipy package, using the stats module and poisson.rvs() method.</p><pre>from scipy.stats import poisson</pre><pre>x = poisson.rvs(mu=3, size=1000)</pre><pre>print(x)</pre><p>We can visualize a poisson distribution using a distplot() method from the seaborn library.</p><pre>from scipy.stats import poisson</pre><pre>import seaborn as sns</pre><pre>x = poisson.rvs(mu=3, size=1000)</pre><pre>ax = sns.distplot(x, kde=False)</pre><pre>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*BGbY7f2nM9OXfpDM2qCZUA.png" /></figure><h4>Binomial Distribution</h4><p>Binomial distribution is a discrete probability distribution, that calculates the probability for <strong><em>x</em></strong> successes in <strong><em>n</em></strong> trials, given a success probability <strong><em>p </em></strong>for each trial. It can also be said to be the probability of an outcome being a success or failure in an experiment that is repeated multiple times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*F29JGpkkmFIzShR-GHC4XA.gif" /></figure><p>The mean of a binomial distribution is calculated by multiplying the number of trials (n) by the probability of successes (p). To calculate binomial distribution, the following criteria must be satisfied:</p><ol><li>A fixed or finite number of trials or number of observation.</li><li>Each trial or observation is independent, that is the outcome of one trial doesn’t affect the outcome of another trial.</li><li>The probability of success is always the same from one trial to another.</li></ol><p>To implement binomial distribution in python, we can use the numpy package which provides a function to do so.</p><pre>#Given 15 data points and 15 trials</pre><pre>import numpy as np</pre><pre>x = np.random.binomial(n=15, p=0.5, size=15)</pre><pre>print(x)</pre><p>Apart from the numpy package, python also has the scipy library, which uses numpy underneath but has been better optimised and has more functions.</p><pre>#Given 15 data points and 15 trials</pre><pre>from scipy.stats import binom</pre><pre>x = binom.rvs(n=15,p=0.5,size=15)</pre><pre>print(x)</pre><p>You can also plot a binomial distribution with seaborn,</p><pre>import seaborn as sns</pre><pre>from scipy.stats import binom</pre><pre>x = binom.rvs(n=50,p=0.5,size=100)</pre><pre>ax = sns.distplot(x, kde=True)</pre><pre>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*HtmWS2Zaq0v2jD3_gGi8Tw.png" /></figure><h4>Summary</h4><p>Through this article we have discussed probability. Probability distribution- both continuous and discrete, we also talked about Normal distribution, Poisson and Binomial distribution and how we can implement them using python.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=295b15b5efe6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Statistics with Python I]]></title>
            <link>https://medium.com/@umorenamazinggrace/statistics-with-python-i-729503c48ee4?source=rss-fccadf0b2173------2</link>
            <guid isPermaLink="false">https://medium.com/p/729503c48ee4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Amazing-Grace Umoren]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 14:09:12 GMT</pubDate>
            <atom:updated>2021-09-07T14:09:12.913Z</atom:updated>
            <content:encoded><![CDATA[<p>Statistics is the science concerned with developing and studying methods for collecting, analyzing, interpreting and presenting data. Python is a popular programming language used in the field of Data Science and Machine Learning. In this article, I would walk through how to carry out basic stats using python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BCC2tYBX-KltJp7G" /><figcaption>Photo by <a href="https://unsplash.com/@kmuza?utm_source=medium&amp;utm_medium=referral">Carlos Muza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Python provides libraries like Numpy, SciPy, Pandas, Matplotlib and other packages that can help collect, analyze, and draw accurate conclusions from data.</p><h3>Measure of Central Tendency</h3><p>Measures of central tendency describes a set of data by identifying the central position within that set of data, to simplify, it basically helps you find the middle, or the average, of a data set. It is also called measures of central location. Measure of central tendency includes <strong>mean, median, mode</strong>.</p><p><strong>Mean(Arithmetic Mean)</strong></p><p>Mean is the average of a group of data, it is usually calculated by the sum of all values divided by the total number of values. Mean is the most commonly used measure of central tendency. They are influenced by outliers(values that significantly differ from the rest of the data), an outlier in a dataset can either increase or decrease the value of a mean. How a mean describes a sample data is based on how spread the data is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*h6pBzZAF43oNq141ldyoaQ.png" /></figure><p>Mean can be calculated with python using the numpy mean() method.</p><pre>#import the numpy package as alias<br>import numpy as np</pre><pre>#example data<br>data = [2, 4, 5, 8]</pre><pre>#using mean() to find the mean of the data<br>mean = np.mean(data)</pre><p>Apart from numpy, the statistics module also offers another method that allows you to calculate the average of an array of numbers.</p><pre>#import statistics module<br>import statistics</pre><pre>data <strong>=</strong> [1, 3, 4, 5, 7, 9, 2]</pre><pre>#using .mean() to find the average of the data<br>x <strong>=</strong> statistics.mean(data)</pre><p><strong>Median</strong></p><p>Median is the exact middle value of a dataset when ordered from highest to lowest. They are not influenced by outliers, therefore unlike mean, they are not influenced by the spread of the dataset, neither do they depend the values of the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*2vaY8z7psXF4zGEodppuSQ.png" /></figure><p>In python, we can calculate the median of a dataset using the numpy package or statistics module.</p><pre>#import numpy as alias<br>import numpy as np</pre><pre>data = [10, 4, 27, 6]<br>median = np.median(data)</pre><p>Calculating median using the statistics module.</p><pre>#import statistics <br>import statistics</pre><pre>data = [10, 4, 27, 6]<br>median = statistics.median(data)</pre><p><strong>Mode</strong></p><p>Mode is the most occurring value in a dataset. In a dataset it is possible to have one or more modes, or none at all. A dataset having two modes is said to be <strong>bimodal, </strong>three modes is said to be <strong>trimodal</strong>. Sometimes a mode can be graphically located. Modes are not affected by outliers and are easy to calculate. They are most useful when examining categorical or qualitative data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/258/1*1mWKfnubwqhX83zhRDiqtQ.png" /></figure><pre>#import numpy package as alias<br>import numpy as np</pre><pre>data = [19, 34, 45, 3, 34, 34, 6]<br>mode = np.mode(data)</pre><p>While using the statistics module:</p><pre>#import statistics module<br>import statistics</pre><pre>data = [19, 34, 45, 3, 34, 34, 6]<br>mode = statistics.mode(data)</pre><h3>Measure of Dispersion</h3><p>Measures of dispersion includes <strong>range, quartiles, interquartile range, variance and standard deviation</strong>. Measure of dispersion can also known as measure of spread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*WVMkNucgLNEZ65EeSGEY0w.png" /></figure><p><strong>Range</strong></p><p>Range is the difference between the highest and lowest value of a dataset. It is very sensitive to outliers and does not use all the observations in a data set. Given a dataset 2, 3, 45, 8, 23, it’s range would be the difference between the highest value, 45, and the lowest value, 2, which is 43.</p><p><strong>Quartile</strong></p><p>A quartile is a term that describes a division of observations into four defined intervals based on the values of the data and how they compare to the entire set of observations. Quartile is a value that divides a dataset into a group of four or quarters. Quartiles are used to carry out further calculations like interquartile range.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*zCQtcPWcgQozypVrXwbC3w.jpeg" /></figure><p>The lower quartile or the first quartile(Q1) is the first 25% of the dataset when arranged in increasing order. The second quartile, Q2 also known as the median is 50% of the dataset in increasing order. The upper quartile, or third quartile (Q3), is the value under which 75% of data points in increasing order.</p><p>Using the numpy package, we can calculate the quartile of a dataset by using the percentile.method</p><pre># numpy.quantile() method</pre><pre><strong>import</strong> numpy as np</pre><pre>data <strong>=</strong> [20, 2, 7, 1, 34]</pre><pre>Q2 = np.percentile(data, 50)</pre><pre>Q1 = np.percentile(data, 25)</pre><pre>Q3 = np.percentile(data, 75)</pre><p><strong>Interquartile Range</strong></p><p>Interquartile range is also known as midspread or H-spread. It is calculated by getting the difference between the upper quartile and lower quartile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*6TxKE773QKxyWhvzrZ3iAA.png" /></figure><p>There are a variety of ways to calculate the interquartile range in python- using the numpy package, scipy library or the statistics module.</p><p>Using Numpy, the interquartile range can simple be calculated by calculating the difference between the 75th percentile and the 25th percentile.</p><pre># Import numpy library</pre><pre>import numpy as np</pre><pre>data <strong>=</strong> [32, 36, 46, 47, 56, 69, 75, 79, 79, 88, 89, 91, 92, 93, 96]</pre><pre># Lower quartile (Q1)</pre><pre>Q1 <strong>=</strong> np.percentile(data, 25)</pre><pre># Upper quartile (Q3)</pre><pre>Q3 <strong>=</strong> np.percentile(data, 75)</pre><pre># Interquartile range (IQR)</pre><pre>IQR <strong>=</strong> Q3 <strong>-</strong> Q1</pre><p>The IQR is used to measure how spread out the data points in a set are from the mean of the data set. The higher the IQR, the more spread out the data points and vice versa. Interquartile ranges are not affected by outliers.</p><p><strong>Variance</strong></p><p>Variance is the statistical measurement of the spread between numbers in a data set. Variance is calculated by taking the differences between each number in the data set and the mean, then squaring the differences, then finally dividing the sum of the squares by the number of values in the data set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jn53kLqEmXeAq8dO3rpbbQ.png" /></figure><p>In python, variance can simply be calculated using the statistics module or the numpy package.</p><p>Using the statistics module variance() function is used when a sample of a population needs to be calculated. Another function known as pvariance()is used to calculate the variance of an entire population.</p><pre>import statistics</pre><pre>import statistics<br>data = [27, 5, 23, 2, 19, 4, 29]</pre><pre>sample_var = statistics.variance(data)</pre><pre>pop_var = statistics.pvariance(data)</pre><p>With the numpy package, the var()function calculates the variance of a dataset.</p><pre>import numpy as np</pre><pre>data = [12, 3, 45, 15]<br>var = np.var(data)</pre><p>When the value of the variance is large, this indicates that numbers in the dataset are far from the mean and far from each other, and a variance of small value indicates the opposite.</p><p><strong>Standard Deviation</strong></p><p>Standard deviation is a also a measure of the amount of variation of numbers in a dataset. Standard deviation is calculated by taking the square root of your variance. The higher the standard deviation, the farther the values of the dataset from the mean and the more spread out the data is.</p><p>With python, the standard deviation can be calculated using the numpy package or the statistics module.</p><p>Using the statistics module, the stdev() function allows us to find the standard deviation of a sample of a population.</p><pre>import statistics</pre><pre>data = [1, 2, 3, 4, 5]</pre><pre>std_dev = statistics.stdev(data)</pre><p>To find the standard deviation of an entire population, the pstdev() is a more appropriate function.</p><pre>import statistics</pre><pre>data = [1, 2, 3, 4, 5]</pre><pre>std_dev = statistics.pstdev(data)</pre><p>Both stdev and pstdev take an optional parameter, <strong><em>xbar </em></strong>which is the mean of the dataset, if not given, it is automatically calculated.</p><p>With numpy, std()function is used to find the standard deviation of a given set of values.</p><pre>import numpy as np</pre><pre>data = [1, 2, 3, 4, 5]</pre><pre>std_dev = np.std(data)</pre><h3>Summary</h3><p>So far, we have looked at the measures of central tendency such as mean, median, mode and the measures of spread and how we can calculate them using the numpy package and the statistics modules in python.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=729503c48ee4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>