<?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"><channel><title><![CDATA[World Labyrinth]]></title><description><![CDATA[Engineer]]></description><link>https://jeremyzhang.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 06:07:43 GMT</lastBuildDate><atom:link href="https://jeremyzhang.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Note | Regression Analysis and Final Project]]></title><description><![CDATA[This is a note of the Course Statistics for Data Science with Python in week 5 and week 6.
We will use regression analysis to describe the relationship between one set of variables(the dependent variables), and another set of variables(the independen...]]></description><link>https://jeremyzhang.hashnode.dev/note-or-regression-analysis-and-final-project</link><guid isPermaLink="true">https://jeremyzhang.hashnode.dev/note-or-regression-analysis-and-final-project</guid><category><![CDATA[Data Science]]></category><category><![CDATA[statistics]]></category><dc:creator><![CDATA[Jeremy]]></dc:creator><pubDate>Thu, 28 Apr 2022 04:00:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/N5-8otT_J_Y/upload/v1651120546304/5ktqn-HoA.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a note of the Course <a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">Statistics for Data Science with Python</a> in week 5 and week 6.</p>
<p>We will use regression analysis to describe the relationship between one set of variables(the dependent variables), and another set of variables(the independent or explanatory variables)^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">1</a> and accomplish the final project with the Boston house dataset.</p>
<blockquote>
<p>When there is only one explanatory variable, it is called simple regression.</p>
</blockquote>
<p>We will use regression analysis instead of the t-test, ANOVA, and correlation.  <a target="_blank" href="https://anifacc.github.io/machinelearning/learningfromdata/2017/09/14/lfd-ch03-linear-model/">Details about linear model</a>.</p>
<h2 id="heading-import-libraries">Import libraries</h2>
<pre><code><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">import</span> statsmodels.api <span class="hljs-keyword">as</span> sm
</code></pre><h2 id="heading-fetch-data">Fetch data</h2>
<pre><code><span class="hljs-attr">ratings_url</span> = <span class="hljs-string">'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-ST0151EN-SkillsNetwork/labs/teachingratings.csv'</span>
<span class="hljs-attr">ratings_df</span> = pd.read_csv(ratings_url)
</code></pre><h2 id="heading-regression-with-t-test">Regression with T-test</h2>
<p>Question: </p>
<blockquote>
<p>Using the teachers rating data set, does gender affect teaching evaluation rates?</p>
</blockquote>
<p>State the hypothesis: </p>
<ul>
<li>H0: Gender has no effect on teaching evaluation scores</li>
<li>H1:  Gender has an effect on teaching evaluation scores</li>
</ul>
<p>The alpha level is 0.05.</p>
<pre><code><span class="hljs-comment">## X is the input variables (or independent variables)</span>
X = ratings_df['female']
<span class="hljs-comment">## y is the target/dependent variable</span>
y = ratings_df['eval']
<span class="hljs-comment">## add an intercept (beta_0) to our model</span>
X = sm.add_constant(X) 

model = sm.OLS(y, X).fit()
predictions = model.predict(X)

<span class="hljs-comment"># Print out the statistics</span>
model.summary()
</code></pre><p>Results: <code>R-squared: 0.022</code>, <code>F-statistic:     10.56</code>, <code>Prob (F-statistic):     0.00124</code></p>
<p>Conclusion: Like the t-test, the p-value is less than the alpha (α) level, so we reject the null hypothesis. </p>
<p>There is significant evidence to prove that there is a difference in mean evaluation scores based on gender. </p>
<p>"The coefficient -0.1680 means that females get 0.168 scores less than men."</p>
<p><code>OLS</code> is the <a target="_blank" href="https://anifacc.github.io/machinelearning/learningfromdata/2017/09/14/lfd-ch03-linear-model/">ordinary least squares(OLS)</a>.</p>
<h2 id="heading-regression-with-anova">Regression with ANOVA</h2>
<p>Question: Using the teachers' rating data set, does beauty score for instructors differ by age?</p>
<p>We group the data into 3 age groups, and state the hypothesis.</p>
<ul>
<li>H0: u1=u2=u3, the three population means are equal</li>
<li>H1: At least one of the means differ</li>
</ul>
<pre><code><span class="hljs-comment"># Seperate</span>
ratings_df.loc[(ratings_df[<span class="hljs-string">'age'</span>] &lt;= <span class="hljs-number">40</span>), <span class="hljs-string">'age_group'</span>] = <span class="hljs-string">'40 years and younger'</span>
ratings_df.loc[(ratings_df[<span class="hljs-string">'age'</span>] &gt; <span class="hljs-number">40</span>)&amp;(ratings_df[<span class="hljs-string">'age'</span>] &lt; <span class="hljs-number">57</span>), <span class="hljs-string">'age_group'</span>] = <span class="hljs-string">'between 40 and 57 years'</span>
ratings_df.loc[(ratings_df[<span class="hljs-string">'age'</span>] &gt;= <span class="hljs-number">57</span>), <span class="hljs-string">'age_group'</span>] = <span class="hljs-string">'57 years and older'</span>

<span class="hljs-comment"># Regression</span>
<span class="hljs-keyword">from</span> statsmodels.formula.api <span class="hljs-keyword">import</span> ols
lm = ols(<span class="hljs-string">'beauty ~ age_group'</span>, data = ratings_df).fit()
table= sm.stats.anova_lm(lm)
print(table)
</code></pre><p>The p-value = 4.322549e-08, we will reject the null hypothesis. There is significant evidence that at least one of the means differs. </p>
<h2 id="heading-correlation">Correlation</h2>
<p>Question: Using the teachers' rating data set, what is the correlation between the number of students who participated in the evaluation survey and evaluation scores?</p>
<pre><code>X <span class="hljs-operator">=</span> ratings_df[<span class="hljs-string">'students'</span>]
y <span class="hljs-operator">=</span> ratings_df[<span class="hljs-string">'eval'</span>]

X <span class="hljs-operator">=</span> sm.add_constant(X)
model <span class="hljs-operator">=</span> sm.OLS(y, X).fit()
predictions <span class="hljs-operator">=</span> model.predict(X)

model.summary()
</code></pre><p><code>R-squared: 0.001</code>, R is <code>math.sqrt(0.001)</code> which is about 0.03. The correlation coefficient is 0.03.  So there is a very weak correlation between the number of students who participated in the evaluation survey and evaluation scores</p>
<p>Here is the <a target="_blank" href="https://github.com/JeremiahZhang/gopython/blob/master/statistics-for-data-science-with-python/week05-regression_analysis.ipynb">source code</a>.</p>
<h2 id="heading-final-project">Final project</h2>
<blockquote>
<p>Project Scenario: You are a Data Scientist with a housing agency in Boston MA, you have been given access to a previous dataset on housing prices derived from the U.S. Census Service to present insights to higher management. Based on your experience in Statistics, what information can you provide them to help with making an informed decision? Upper management will like to get some insight into the following.</p>
<ul>
<li>Is there a significant difference in the median value of houses bounded by the Charles river or not?</li>
<li>Is there a difference in median values of houses of each proportion of owner-occupied units built before 1940?</li>
<li>Can we conclude that there is no relationship between Nitric oxide concentrations and the proportion of non-retail business acres per town?</li>
<li>What is the impact of an additional weighted distance to the five Boston employment centers on the median value of owner-occupied homes?</li>
</ul>
</blockquote>
<p>Here are the <a target="_blank" href="https://github.com/JeremiahZhang/gopython/blob/master/statistics-for-data-science-with-python/week06-last-project.ipynb">solutions</a>.</p>
<p>Next, I will go through <a target="_blank" href="https://github.com/microsoft/Data-Science-For-Beginners">Data Science For Beginners</a>of MS and the book named <a target="_blank" href="https://probability4datascience.com/">Introduction to Probability for Data Science</a></p>
<h2 id="heading-change-log">Change Log</h2>
<p>2022-04-28 Jeremy initialized.</p>
]]></content:encoded></item><item><title><![CDATA[Note | Hypothesis Testing]]></title><description><![CDATA[This is a note of the Course Statistics for Data Science with Python in week 4.
This week, we will learn how "to conduct a hypothesis test on a population mean, how to formulate a decision rule for testing a hypothesis, how to conduct a hypothesis te...]]></description><link>https://jeremyzhang.hashnode.dev/note-or-hypothesis-testing</link><guid isPermaLink="true">https://jeremyzhang.hashnode.dev/note-or-hypothesis-testing</guid><category><![CDATA[statistics]]></category><dc:creator><![CDATA[Jeremy]]></dc:creator><pubDate>Sat, 23 Apr 2022 13:34:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/hpjSkU2UYSU/upload/v1650720904743/8yhUOUWl_.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a note of the Course <a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">Statistics for Data Science with Python</a> in week 4.</p>
<p>This week, we will learn how "to conduct a hypothesis test on a population mean, how to formulate a decision rule for testing a hypothesis, how to conduct a hypothesis test on a difference in two or more population means, and how to distinguish between correlation tests for two continuous variables and two categorical variables. ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">1</a>"</p>
<blockquote>
<p>When you are evaluating a hypothesis, you need to account for both the variability in your sample and how large your sample is ^<a target="_blank" href="https://www.nedarc.org/statisticalhelp/advancedstatisticaltopics/hypothesisTesting.html">2</a>. </p>
</blockquote>
<p>Hypothesis testing is used to compare two or more groups or examine associations between variables^<a target="_blank" href="https://www.nedarc.org/statisticalhelp/advancedstatisticaltopics/hypothesisTesting.html">2</a>. For example, we want to know whether gender affects teaching evaluation rates in the <a target="_blank" href="https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-ST0151EN-SkillsNetwork/labs/teachingratings.csv">teachers' ratings data set</a>. To evaluate this, we could compare the evaluation scores of the male teachers and that of female teachers.</p>
<p>There are five steps in Hypothesis Testing^<a target="_blank" href="https://www.nedarc.org/statisticalhelp/advancedstatisticaltopics/hypothesisTesting.html">2</a>. </p>
<ul>
<li>Specify the Null Hypothesis</li>
<li>Specify the Alternative Hypothesis</li>
<li>Set the significance level(alpha usually 0.05)</li>
<li>Calculate the test statistics and corresponding P-value</li>
<li>Drawing a conclusion</li>
</ul>
<hr />
<p>We can use z-test or t-test to conduct the hypothesis test.</p>
<p>"A z-test is a statistical test used to determine whether two population means are different when the variances are known and the sample size is large." ^<a target="_blank" href="https://www.investopedia.com/terms/z/z-test.asp">3</a></p>
<p>A t-test, like the z-test, is used to determine if there is a significant difference between the means of two groups with a small sample size. "For a large sample size, statisticians use a z-test. Other testing options include the chi-square test and the f-test."^<a target="_blank" href="https://www.investopedia.com/terms/t/t-test.asp">4</a></p>
<p>There are some assumptions^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">1</a> that must be met when we use the t-test for independent samples.</p>
<ul>
<li>One independent, categorical variable with two levels or group</li>
<li>One dependent continuous variable</li>
<li>Independence of the observations. Each subject should belong to only one group. There is no relationship between the observations in each group.</li>
<li>The dependent variable must follow a normal distribution, bell-shaped distribution curve.</li>
<li>Assumption of homogeneity of variance</li>
</ul>
<hr />
<p>There are 3 types of t-tests, correlated/paired t-test, <strong>equal variance</strong>/pooled t-test, and <strong>unequal variance</strong> t-test,
categorized as dependent and independent t-tests.^<a target="_blank" href="https://www.investopedia.com/terms/t/t-test.asp">4</a> </p>
<p>How to choose, we can see the screenshot from Investopedia.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650717439848/L-RdRAP-N.png" alt="t-test.png" />
Image by Julie Bang Â© Investopedia 2019</p>
<p>Then how to deal with rejections and tails? See the note about alpha and p-value in <a target="_blank" href="https://jeremyzhang.hashnode.dev/note-or-probability-distributions">week 2</a></p>
<hr />
<p>There is an example to use a t-test. "Using the teachers' rating data set, genders affect teaching evaluation rates?"</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">numpy</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">np</span>
<span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">pandas</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">pd</span>
<span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">scipy</span>.<span class="hljs-title">stats</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">stats</span>
<span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">matplotlib</span>.<span class="hljs-title">pyplot</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">plt</span>
<span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">seaborn</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">sns</span>

<span class="hljs-title">ratings_url</span> <span class="hljs-operator">=</span> <span class="hljs-string">'https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-ST0151EN-SkillsNetwork/labs/teachingratings.csv'</span>
<span class="hljs-title">ratings_df</span> <span class="hljs-operator">=</span> <span class="hljs-title">pd</span>.<span class="hljs-title">read_csv</span>(<span class="hljs-title">ratings_url</span>)
</code></pre><p>Let's state the hypothesis: </p>
<ul>
<li><p>H0: µ1 = µ2 ("there is no difference in evaluation scores between males and females")     </p>
</li>
<li><p>H1: µ1 ≠ µ2 ("there is a difference in evaluation scores between males and females")    </p>
</li>
</ul>
<pre><code><span class="hljs-comment"># Whether normal distribution</span>
ax = sns.distplot(ratings_df[<span class="hljs-string">'eval'</span>],
                  bins=<span class="hljs-number">20</span>,
                  kde=<span class="hljs-literal">True</span>,
                  color=<span class="hljs-string">'green'</span>,
                  hist_kws={<span class="hljs-string">'linewidth'</span>: <span class="hljs-number">15</span>, <span class="hljs-string">'alpha'</span>: <span class="hljs-number">1</span>})
ax.set(xlabel=<span class="hljs-string">'Normal Distribution'</span>, ylabel=<span class="hljs-string">'Frequency'</span>)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650718365301/9TPKjo5uF.png" alt="normal_distribution.png" /></p>
<pre><code><span class="hljs-section"># Assume it is normal</span>
<span class="hljs-section"># Equal variance？</span>
mask<span class="hljs-emphasis">_female = ratings_</span>df['gender'] == 'female'
mask<span class="hljs-emphasis">_male = ratings_</span>df['gender'] == 'male'
stats.levene(ratings<span class="hljs-emphasis">_df[<span class="hljs-string">mask_female</span>][<span class="hljs-symbol">'eval'</span>],
                   ratings_</span>df[<span class="hljs-string">mask_male</span>][<span class="hljs-symbol">'eval'</span>], center='mean')
</code></pre><p><code>LeveneResult(statistic=0.1903292243529225, pvalue=0.6628469836244741)</code></p>
<blockquote>
<p>We have a t-test called Levene's test to determine the equality of variances. The null hypothesis of the Levene's test is that population variances are equal if the p-value of the test is less 0.05, reject the null hypothesis of equal variances and assume that the variances are unequal.</p>
</blockquote>
<p>The p-value is greater than 0.05, we assume equality of variance.</p>
<pre><code><span class="hljs-section"># T-test</span>
stats.ttest<span class="hljs-emphasis">_ind(ratings_</span>df[<span class="hljs-string">mask_female</span>][<span class="hljs-symbol">'eval'</span>],
<span class="hljs-code">                ratings_df[mask_male]['eval'], equal_var=True)</span>
</code></pre><p><code>Ttest_indResult(statistic=-3.249937943510772, pvalue=0.0012387609449522217)</code></p>
<p>The p-value is less than 0.05/2, we reject the null hypothesis H0. So the difference in evaluation scores between males and females is statistically significant.</p>
<hr />
<p>When we conduct a test with three or more means, one must use an <strong>an</strong>alysis <strong>o</strong>f <strong>va</strong>riance(<strong>ANOVA</strong>). </p>
<blockquote>
<p>"Analysis of variance (ANOVA) is a collection of statistical models and their associated estimation procedures (such as the "variation" among and between groups) used to analyze the differences among means".^<a target="_blank" href="https://en.wikipedia.org/wiki/Analysis_of_variance">5</a></p>
</blockquote>
<p>Example:</p>
<pre><code><span class="hljs-comment"># ANOVA: Using the teachers' rating data set, </span>
<span class="hljs-comment">#      does beauty score for instructors differ by age?</span>
<span class="hljs-comment">#  we group the data into categories as the one-way</span>
<span class="hljs-comment">#  ANOVA can't work with continuous variable</span>
<span class="hljs-attribute">mask_younger</span> = ratings_df[<span class="hljs-string">'age'</span>] &lt;= <span class="hljs-number">40</span>
mask_between = (ratings_df[<span class="hljs-string">'age'</span>] &gt; <span class="hljs-number">40</span>) &amp; (ratings_df[<span class="hljs-string">'age'</span>] &lt; <span class="hljs-number">57</span>)
mask_older = ratings_df[<span class="hljs-string">'age'</span>] &gt;= <span class="hljs-number">57</span>

ratings_df.loc[mask_younger, <span class="hljs-string">'age_group'</span>] = <span class="hljs-string">'40 years and younger'</span>
ratings_df.loc[mask_between, <span class="hljs-string">'age_group'</span>] = <span class="hljs-string">'between 40 and 57 years'</span>
ratings_df.loc[mask_older, <span class="hljs-string">'age_group'</span>] = <span class="hljs-string">'57 years and older'</span>
</code></pre><p>State the hypothesis:</p>
<ul>
<li>H0: µ1 = µ2 = µ3 (the three population means are equal)</li>
<li>H1: At least one of the means differ</li>
</ul>
<p>Test for equality of variance:</p>
<pre><code>mask1 = ratings<span class="hljs-emphasis">_df['age_</span>group'] == '40 years and younger'
mask2 = ratings<span class="hljs-emphasis">_df['age_</span>group'] == 'between 40 and 57 years'
mask3 = ratings<span class="hljs-emphasis">_df['age_</span>group'] == '57 years and older'
stats.levene(ratings<span class="hljs-emphasis">_df[<span class="hljs-string">mask1</span>][<span class="hljs-symbol">'beauty'</span>],
             ratings_</span>df[<span class="hljs-string">mask2</span>][<span class="hljs-symbol">'beauty'</span>],
<span class="hljs-code">             ratings_df[mask3]['beauty'],
             center='mean')</span>
</code></pre><p><code>LeveneResult(statistic=8.60005668392585, pvalue=0.0002153661809934714)</code></p>
<p>Since the p-value is less than 0.05, we reject the null hypothesis which means the variances are not equal.</p>
<p>ANOVA test:</p>
<pre><code>younger = ratings<span class="hljs-emphasis">_df[<span class="hljs-string">mask1</span>][<span class="hljs-symbol">'beauty'</span>]
between = ratings_</span>df[<span class="hljs-string">mask2</span>][<span class="hljs-symbol">'beauty'</span>]
older = ratings<span class="hljs-emphasis">_df[<span class="hljs-string">mask3</span>][<span class="hljs-symbol">'beauty'</span>]

# run a one-way ANOVA
f_</span>statistic, p<span class="hljs-emphasis">_value = stats.f_</span>oneway(younger, between, older)
print("F<span class="hljs-emphasis">_Statistic: {0}, P-value: {1}".format(f_</span>statistic, p<span class="hljs-emphasis">_value))</span>
</code></pre><p><code>F_Statistic: 17.597558611010122, P-value: 4.3225489816137975e-08</code></p>
<p>Since the p-value is less than 0.05/2, we will reject the null hypothesis as there is significant evidence that at least one of the means differs.</p>
<hr />
<p>We can use Chi-square to test whether there is an association between tenure and gender(categorical data sets).</p>
<p>State the hypothesis:</p>
<ul>
<li>H0: The proportion of teachers who are tenured is independent of gender</li>
<li>H1: The proportion of teachers who are tenured is associated with gender</li>
</ul>
<pre><code># <span class="hljs-keyword">Cross</span>-tab <span class="hljs-keyword">table</span>
cont_table = pd.crosstab(ratings_df[<span class="hljs-string">'tenure'</span>], ratings_df[<span class="hljs-string">'gender'</span>])
stats.chi2_contingency(cont_table, correction = <span class="hljs-keyword">True</span>)
</code></pre><p>Output:</p>
<p><code>(2.20678166999886,
 0.1374050603563787,
 1,
 array([[ 42.95896328,  59.04103672],
        [152.04103672, 208.95896328]]))</code></p>
<p>2.2 is the 𝜒2 value, and 0.137 is the p-value.</p>
<p> <strong>Conclusion:</strong> Since the p-value is greater than 0.05/2, we fail to reject the null hypothesis. As there is no sufficient evidence that teachers are tenured because of gender.</p>
<hr />
<p>Next are the correlation tests.</p>
<blockquote>
<p>Q: Correlation, Using the teachers' rating dataset, Is teaching evaluation score correlated with beauty score?</p>
</blockquote>
<p>State the hypothesis:</p>
<ul>
<li>H0: Teaching evaluation score is not correlated with beauty score</li>
<li>H1: Teaching evaluation score is correlated with beauty score</li>
</ul>
<pre><code><span class="hljs-selector-tag">stats</span><span class="hljs-selector-class">.pearsonr</span>(<span class="hljs-selector-tag">ratings_df</span><span class="hljs-selector-attr">[<span class="hljs-string">'beauty'</span>]</span>, <span class="hljs-selector-tag">ratings_df</span><span class="hljs-selector-attr">[<span class="hljs-string">'eval'</span>]</span>)
</code></pre><p>Output: <code>(0.18903909084045212, 4.247115419812614e-05)</code></p>
<p> <strong>Conclusion:</strong> Since the p-value &lt; 0.05/2, we reject the null hypothesis and conclude that there is a relationship between beauty and teaching evaluation score.</p>
<p>Here is the <a target="_blank" href="https://github.com/JeremiahZhang/gopython/blob/master/statistics-for-data-science-with-python/week04-hypothesis-testing.ipynb">source code</a>.</p>
<h2 id="heading-change-log">Change Log</h2>
<p>2022-04-23 Jeremy initialized.</p>
]]></content:encoded></item><item><title><![CDATA[Note | Probability Distributions]]></title><description><![CDATA[This is a note of the Course Statistics for Data Science with Python in week 3.
Content: the basic concepts and application of probability and probability distributions.
Objectives: Calculate probabilities given a normal density, State the null and a...]]></description><link>https://jeremyzhang.hashnode.dev/note-or-probability-distributions</link><guid isPermaLink="true">https://jeremyzhang.hashnode.dev/note-or-probability-distributions</guid><category><![CDATA[statistics]]></category><category><![CDATA[Data Science]]></category><dc:creator><![CDATA[Jeremy]]></dc:creator><pubDate>Wed, 20 Apr 2022 13:37:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/npxXWgQ33ZQ/upload/v1650461808132/hcgqdcrLJ.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a note of the Course <a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">Statistics for Data Science with Python</a> in week 3.</p>
<p>Content: the basic concepts and application of probability and probability distributions.</p>
<p>Objectives: Calculate probabilities given a normal density, State the null and alternative hypothesis when performing tests, and understand the different bell-shaped distributions.</p>
<h2 id="heading-random-numbers-and-probability-distributions">Random Numbers and Probability Distributions</h2>
<blockquote>
<p>The random variable is a quantity whose possible values depend in some clearly defined way on a set of some random events ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/lecture/y7DJD/random-numbers-and-probability-distributions">1</a>. </p>
<p>The probability is a measure between zero and one for the likelihood that something or some event might occur ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/lecture/y7DJD/random-numbers-and-probability-distributions">1</a>.</p>
</blockquote>
<p>The course introduces a game ^<a target="_blank" href="http://www.edcollins.com/backgammon/diceprob.htm">2</a> that uses dice to understand random variables and probability.</p>
<p>Let's play the dice game ^<a target="_blank" href="https://www.jeffastor.com/blog/using-python-to-calculate-dice-statistics">3</a>. Let's roll two dice 10000 times. If we look at the distribution of the sum of two dice, we can see it's a normal distribution.</p>
<pre><code><span class="hljs-comment"># Two dice game</span>
<span class="hljs-attribute">import</span> matplotlib.pyplot as plt
<span class="hljs-attribute">import</span> seaborn as sns
<span class="hljs-attribute">import</span> numpy as np

<span class="hljs-attribute">np</span>.random.seed(<span class="hljs-number">1738</span>)

<span class="hljs-attribute">d1</span> = np.arange(<span class="hljs-number">1</span>, <span class="hljs-number">7</span>)
<span class="hljs-attribute">d2</span> = np.arange(<span class="hljs-number">1</span>, <span class="hljs-number">7</span>)

<span class="hljs-attribute">dice_1</span> =<span class="hljs-meta"> []</span>
<span class="hljs-attribute">dice_2</span> =<span class="hljs-meta"> []</span>
<span class="hljs-attribute">sums</span> =<span class="hljs-meta"> []</span>

<span class="hljs-attribute">for</span> _ in range(<span class="hljs-number">10000</span>):
    <span class="hljs-attribute">roll_1</span> = np.random.choice(d<span class="hljs-number">1</span>)
    <span class="hljs-attribute">roll_2</span> = np.random.choice(d<span class="hljs-number">2</span>)

    <span class="hljs-attribute">dice_1</span>.append(roll_<span class="hljs-number">1</span>)
    <span class="hljs-attribute">dice_2</span>.append(roll_<span class="hljs-number">2</span>)

    <span class="hljs-attribute">sums</span>.append(roll_<span class="hljs-number">1</span> + roll_<span class="hljs-number">2</span>)

<span class="hljs-attribute">sns</span>.countplot(sums)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650443828071/kYtJFumj3.png" alt="dice_game.png" /></p>
<p>The mean is 7.0258, and the standard deviation is about 2.3923</p>
<pre><code>np.mean(sums)
np.std(sums)
</code></pre><h2 id="heading-hypothesis">Hypothesis</h2>
<p>This part introduced the statistical hypothesis testing and how to state our hypothesis, which I learned at the university. We should set the null hypothesis and the alternative hypothesis.</p>
<h2 id="heading-alpha-and-p-value">Alpha and P-value</h2>
<blockquote>
<p>Alpha and p-value are commonly used terms in statistical analysis.</p>
</blockquote>
<p>Alpha (α) is known as the significance level (显著性水平 in Chinese). "It is the probability of rejecting the null hypothesis when the null hypothesis is true. The value often used is 5% ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/supplement/UwHiy/alpha-a-and-p-value">4</a>". This means that there is a 5% chance that we will accept the alternative hypothesis when the null hypothesis is true. </p>
<p>The rejection regions for different kinds of tests are shown in this image below(screenshot from the course.) ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/supplement/UwHiy/alpha-a-and-p-value">4</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650444880970/KGzGbCY_w.png" alt="rejections" /></p>
<blockquote>
<p>P-value is a calculated value and an output you get as part of conducting your hypothesis test.  The p-value can be interpreted as the probability of getting a result that is as extreme or more extreme when the null hypothesis is true i.e. the likelihood of observing that particular sample value if the null hypothesis were true. ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/supplement/UwHiy/alpha-a-and-p-value">4</a></p>
</blockquote>
<p>For example, in a one-tailed test(right tail), we conduct a test and get a p-value of 0.03 which means that there is a 3% chance of obtaining a value of $$\mu_0$$ or more than $$ \mu_0$$</p>
<p>If the alpha(the significance value) is 5%, we will reject the null hypothesis, because 3% is less than 5%. if the alpha is 2%, we will fail to reject the null hypothesis because 3% is greater than 2%.</p>
<h2 id="heading-normal-distribution">Normal Distribution</h2>
<p>The function of the normal distribution:</p>
<p>$$
f(x,\mu,\sigma) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2{\sigma}^2}}
$$</p>
<p>A random variable: $$x$$<br />The mean of the variables: $$\mu$$<br />Standard deviation: $$\sigma$$  </p>
<p>The function of the standard normal distribution:</p>
<p>$$
\sigma = 1,<br />\mu = 0
$$ 
$$
f(x,0,1) = \frac{1}{\sqrt{2\pi}}e^{-(\frac{x^2}{2})}
$$</p>
<pre><code><span class="hljs-comment"># Plot between -4 and 4 with 0.1 steps</span>
<span class="hljs-attribute">x_axis</span> = np.arange(-<span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">0</span>.<span class="hljs-number">1</span>)
<span class="hljs-comment"># Mean = 0, SD= 1.</span>
<span class="hljs-attribute">plt</span>.plot(x_axis, sta.norm.pdf(x_axis, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>))
<span class="hljs-attribute">plt</span>.show()
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650446222296/-EJr6M8_2.png" alt="bell-curve.png" /></p>
<p>CDF: Cumulative distribution function (累积分布函数)
PDF: Probability density function (概率密度函数)</p>
<p>We can standardize the normal distribution to the standard normal distribution.</p>
<p>The method:</p>
<p>$$
z = \frac{x - \mu}{\sigma}
$$
$$
f(z) = \frac{1}{\sqrt{2\pi}}e^{-\frac{z^2}{2}}
$$</p>
<h2 id="heading-t-distribution">T-distribution</h2>
<blockquote>
<p>The t-distribution describes the standardized distances of sample means to the population mean when the population standard deviation is not known, and the observations come from a normally distributed population. ^<a target="_blank" href="https://www.jmp.com/en_us/statistics-knowledge-portal/t-test/t-distribution.html">5</a></p>
<p>The normal distribution describes the mean for the population, whereas the T-distribution describes the mean of samples drawn from a population. ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/lecture/Wicjx/t-distribution">6</a></p>
</blockquote>
<p>When the sample size increases, the t-distribution becomes more similar to the normal distribution^<a target="_blank" href="https://www.jmp.com/en_us/statistics-knowledge-portal/t-test/t-distribution.html">5</a>.</p>
<h2 id="heading-probability-getting-from-cdf">Probability getting from CDF</h2>
<pre><code>eval_mean <span class="hljs-operator">=</span> round(ratings_df[<span class="hljs-string">'eval'</span>].mean(), <span class="hljs-number">3</span>)
eval_std <span class="hljs-operator">=</span> round(ratings_df[<span class="hljs-string">'eval'</span>].std(), <span class="hljs-number">3</span>)
prob0 <span class="hljs-operator">=</span> scipy.stats.norm.cdf((<span class="hljs-number">4.5</span> <span class="hljs-operator">-</span> eval_mean)<span class="hljs-operator">/</span>eval_std)
print(<span class="hljs-number">1</span> <span class="hljs-operator">-</span> prob0)
</code></pre><p>The variance <code>prob0</code> is the probability of receiving an evaluation score of less than 4.5.</p>
<pre><code>x1 <span class="hljs-operator">=</span> <span class="hljs-number">3.5</span>
x2 <span class="hljs-operator">=</span> <span class="hljs-number">4.2</span>
prob1 <span class="hljs-operator">=</span> scipy.stats.norm.cdf((x1 <span class="hljs-operator">-</span> eval_mean)<span class="hljs-operator">/</span>eval_std)
prob2 <span class="hljs-operator">=</span> scipy.stats.norm.cdf((x2 <span class="hljs-operator">-</span> eval_mean)<span class="hljs-operator">/</span>eval_std)
print(prob2 <span class="hljs-operator">-</span> prob1)
</code></pre><p>The variance <code>prob1</code> is the probability of receiving an evaluation score of less than 3.5 (x1). The variance <code>prob2</code> is the probability of receiving an evaluation score of less than 4.2 (x2). So the difference between <code>prob2</code> and <code>prob1</code> is the probability of receiving an evaluation score greater than 3.5 and less than 4.2.</p>
<h2 id="heading-standart-normal-table">Standart Normal Table</h2>
<blockquote>
<p>You can use the z-table to find a set of “less-than” probabilities for a wide range of z-values. ^<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python/supplement/RvInj/standard-normal-table">7</a></p>
</blockquote>
<p>I used this table. It is so familiar. Haha. And I know how to use it.</p>
<h2 id="heading-experiments-probability-distributions">Experiments: Probability Distributions</h2>
<p>In this part, we can go over some hands-on exercises using Python to do some descriptive statistics. Here is the <a target="_blank" href="https://github.com/JeremiahZhang/gopython/blob/master/statistics-for-data-science-with-python/week03-normal-distribution.ipynb">source code</a>. We can also use Google Colab to execute.</p>
<h2 id="heading-change-log">Change Log</h2>
<p>2022-04-20 Jeremy  Initialized.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Note | Data Visualization]]></title><description><![CDATA[This is a note of the Course Statistics for Data Science with Python in week 2.
The learning objectives1 of week 2 are

Interpret graphical summaries of data
Create data visualization in Python
Effectively choose the right chart type for the audience...]]></description><link>https://jeremyzhang.hashnode.dev/note-or-data-visualization</link><guid isPermaLink="true">https://jeremyzhang.hashnode.dev/note-or-data-visualization</guid><category><![CDATA[Data Science]]></category><dc:creator><![CDATA[Jeremy]]></dc:creator><pubDate>Mon, 18 Apr 2022 13:09:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1650287555665/FE3iNbQAr.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a note of the Course <a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">Statistics for Data Science with Python</a> in week 2.</p>
<p>The learning objectives<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">1</a> of week 2 are</p>
<ul>
<li>Interpret graphical summaries of data</li>
<li>Create data visualization in Python</li>
<li>Effectively choose the right chart type for the audience and data type.</li>
</ul>
<hr />
<h2 id="heading-charts-and-graphs-in-statistics">Charts and graphs in statistics</h2>
<h3 id="heading-visualization-fundamentals">Visualization Fundamentals</h3>
<ul>
<li>Use bar charts or column chats to compare items with a few categories</li>
</ul>
<pre><code>sns.set(style<span class="hljs-operator">=</span><span class="hljs-string">"whitegrid"</span>)
ax <span class="hljs-operator">=</span> sns.barplot(x<span class="hljs-operator">=</span><span class="hljs-string">"division"</span>, y<span class="hljs-operator">=</span><span class="hljs-string">"eval"</span>, data<span class="hljs-operator">=</span>division_eval)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650284552845/Ot2408Lig.png" alt="bar_chart.png" /></p>
<hr />
<ul>
<li>Use line charts or line plots to compare behaviors over time(not many time periods, use columns or other approaches)</li>
</ul>
<pre><code># Seaborn X-axis <span class="hljs-keyword">as</span> <span class="hljs-keyword">index</span>
fig = sns.lineplot(data=df_clean.reset_index(), x=<span class="hljs-string">'date'</span>, y=<span class="hljs-string">'value'</span>, palette=[<span class="hljs-string">'red'</span>])
fig.set_xlabel("Date")
fig.set_ylabel("Page Views")
fig.set_title("Daily freeCodeCamp Forum Page Views 5/2016-12/2019")
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650285815452/txsaKVoQ0.png" alt="line_plot.png" /></p>
<hr />
<ul>
<li>Use a scatter plot to depict relationships between two continuous variables</li>
</ul>
<pre><code>ax <span class="hljs-operator">=</span> sns.scatterplot(x<span class="hljs-operator">=</span><span class="hljs-string">"age"</span>, y<span class="hljs-operator">=</span><span class="hljs-string">"eval"</span>, data<span class="hljs-operator">=</span>ratings_df,
                    hue<span class="hljs-operator">=</span><span class="hljs-string">"gender"</span>)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650285833754/XNMa2RCp0.png" alt="scatter_plot.png" /></p>
<hr />
<ul>
<li>Use a bubble chart to depict two variables on the x and y-axis and the third variable(size of the circle)</li>
</ul>
<p>Example: <a target="_blank" href="https://datavizpyr.com/make-bubble-plot-in-python-with-matplotlib/">2</a></p>
<pre><code># scatter plot <span class="hljs-keyword">with</span> scatter() <span class="hljs-keyword">function</span>
# transparency <span class="hljs-keyword">with</span> "alpha"
# bubble size <span class="hljs-keyword">with</span> "s"
plt.scatter(<span class="hljs-string">'X'</span>, <span class="hljs-string">'Y'</span>, 
             s=<span class="hljs-string">'bubble_size'</span>,
             alpha=<span class="hljs-number">0.5</span>, 
             data=df)
plt.xlabel("X", size=<span class="hljs-number">16</span>)
plt.ylabel("y", size=<span class="hljs-number">16</span>)
plt.title("Bubble Plot with Matplotlib", size=<span class="hljs-number">18</span>
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650285863104/rzVO3wk6Z.png" alt="bubble_use_scatter.png" /></p>
<hr />
<ul>
<li>Use a histogram(chart or line) to depict the distribution of the data set</li>
</ul>
<pre><code>sns.histplot(x<span class="hljs-operator">=</span><span class="hljs-string">"gender"</span>, hue<span class="hljs-operator">=</span><span class="hljs-string">"tenure"</span>, data<span class="hljs-operator">=</span>ratings_df, multiple<span class="hljs-operator">=</span><span class="hljs-string">"dodge"</span>)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650285887901/sV-jvj_Bg.png" alt="hist.png" /></p>
<pre><code>sns.distplot(ratings<span class="hljs-emphasis">_df[<span class="hljs-string">mask_female</span>][<span class="hljs-symbol">'eval'</span>], color='green', kde=False)
sns.distplot(ratings_</span>df[<span class="hljs-string">mask_male</span>][<span class="hljs-symbol">'eval'</span>], color='red', kde=False)
plt.show()
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650285897276/ZDWNjmM0K.png" alt="dist.png" /></p>
<hr />
<ul>
<li>Use a pie chart to show the composition<a target="_blank" href="https://matplotlib.org/stable/gallery/pie_and_polar_charts/pie_features.html">3</a></li>
</ul>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">matplotlib</span>.<span class="hljs-title">pyplot</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">plt</span>

# <span class="hljs-title">Pie</span> <span class="hljs-title">chart</span>, <span class="hljs-title">where</span> <span class="hljs-title">the</span> <span class="hljs-title">slices</span> <span class="hljs-title">will</span> <span class="hljs-title">be</span> <span class="hljs-title">ordered</span> <span class="hljs-title">and</span> <span class="hljs-title">plotted</span> <span class="hljs-title">counter</span><span class="hljs-operator">-</span><span class="hljs-title">clockwise</span>:
<span class="hljs-title">labels</span> <span class="hljs-operator">=</span> <span class="hljs-string">'Frogs'</span>, <span class="hljs-string">'Hogs'</span>, <span class="hljs-string">'Dogs'</span>, <span class="hljs-string">'Logs'</span>
<span class="hljs-title">sizes</span> <span class="hljs-operator">=</span> [15, 30, 45, 10]
<span class="hljs-title">explode</span> <span class="hljs-operator">=</span> (0.1, 0.1, 0, 0)  # <span class="hljs-title">only</span> <span class="hljs-string">"explode"</span> <span class="hljs-title">the</span> 2<span class="hljs-title">nd</span> <span class="hljs-title">slice</span> (<span class="hljs-title">i</span>.<span class="hljs-title">e</span>. <span class="hljs-string">'Hogs'</span>)

<span class="hljs-title">fig1</span>, <span class="hljs-title">ax1</span> <span class="hljs-operator">=</span> <span class="hljs-title">plt</span>.<span class="hljs-title">subplots</span>()
<span class="hljs-title">ax1</span>.<span class="hljs-title">pie</span>(<span class="hljs-title">sizes</span>, <span class="hljs-title">explode</span><span class="hljs-operator">=</span><span class="hljs-title">explode</span>, <span class="hljs-title">labels</span><span class="hljs-operator">=</span><span class="hljs-title">labels</span>, <span class="hljs-title">autopct</span><span class="hljs-operator">=</span><span class="hljs-string">'%1.1f%%'</span>,
        <span class="hljs-title">shadow</span><span class="hljs-operator">=</span><span class="hljs-title">True</span>, <span class="hljs-title">startangle</span><span class="hljs-operator">=</span>90)
<span class="hljs-title">ax1</span>.<span class="hljs-title">axis</span>(<span class="hljs-string">'equal'</span>)  # <span class="hljs-title">Equal</span> <span class="hljs-title">aspect</span> <span class="hljs-title">ratio</span> <span class="hljs-title">ensures</span> <span class="hljs-title">that</span> <span class="hljs-title">pie</span> <span class="hljs-title"><span class="hljs-keyword">is</span></span> <span class="hljs-title">drawn</span> <span class="hljs-title"><span class="hljs-keyword">as</span></span> <span class="hljs-title">a</span> <span class="hljs-title">circle</span>.

<span class="hljs-title">plt</span>.<span class="hljs-title">show</span>()
</code></pre><h2 id="heading-piepnghttpscdnhashnodecomreshashnodeimageuploadv1650285908285tpaquqhaxpng"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650285908285/TpAQuQHax.png" alt="pie.png" /></h2>
<ul>
<li>Use stacked columns to show the composition that changes over time(few periods)</li>
<li>Use stacked area charts (Many periods)</li>
</ul>
<h3 id="heading-statistics-by-groups">Statistics by Groups</h3>
<p>Identify and eliminate "duplicates" data</p>
<pre><code>nonduplicates_ratings_df <span class="hljs-operator">=</span> ratings_df.drop_duplicates(subset<span class="hljs-operator">=</span>[<span class="hljs-string">'prof'</span>])
</code></pre><h3 id="heading-statistics-charts">Statistics Charts</h3>
<p>Box plot: Displaying mean, median quartile, and outliers.</p>
<pre><code>ax <span class="hljs-operator">=</span> sns.boxplot(x<span class="hljs-operator">=</span><span class="hljs-string">"credits"</span>, y<span class="hljs-operator">=</span><span class="hljs-string">"beauty"</span>, data<span class="hljs-operator">=</span>ratings_df)
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1650286822122/bw8vE7gVW.png" alt="boxplot.png" /></p>
<p>From bottom to top: minimum, first quartile, median, third quartile, maximum. The range between the first quartile and the third quartile is interquartile range(IQR).</p>
<p>For distribution and variance, see the distribution and histogram above.</p>
<h2 id="heading-experiments-data-visualization">Experiments: Data Visualization</h2>
<p>In this part, we can go over some hands-on exercises using Python to do some descriptive statistics. Here is the <a target="_blank" href="https://github.com/JeremiahZhang/gopython/blob/master/statistics-for-data-science-with-python/week02-data-visualization.ipynb">source code</a>. You can use Google Colab to execute.</p>
<hr />
<h2 id="heading-change-log">Change Log</h2>
<pre><code>2022<span class="hljs-selector-class">.04</span><span class="hljs-selector-class">.18</span> <span class="hljs-selector-tag">Jeremy</span> <span class="hljs-selector-tag">Initialized</span>.
</code></pre><hr />
]]></content:encoded></item><item><title><![CDATA[Note | Statistics for Data Science with Python Week 1]]></title><description><![CDATA[This is a note of the Course Statistics for Data Science with Python.
The contents of this week:

Course Introduction and Python Basics
Instructors and Course Overview
Python Packages for Data Science
Basics of Jupyter Notebooks and Python Review


U...]]></description><link>https://jeremyzhang.hashnode.dev/note-or-statistics-for-data-science-with-python-week-1</link><guid isPermaLink="true">https://jeremyzhang.hashnode.dev/note-or-statistics-for-data-science-with-python-week-1</guid><category><![CDATA[Data Science]]></category><dc:creator><![CDATA[Jeremy]]></dc:creator><pubDate>Wed, 13 Apr 2022 09:59:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1649843954855/pppjEeJIL.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a note of the Course <a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">Statistics for Data Science with Python</a>.</p>
<p>The contents of this week:</p>
<ul>
<li>Course Introduction and Python Basics<ul>
<li>Instructors and Course Overview</li>
<li>Python Packages for Data Science</li>
<li>Basics of Jupyter Notebooks and Python Review</li>
</ul>
</li>
<li>Understanding the basics of Descriptive Statistics<ul>
<li>Statistics introduction </li>
<li>Types of Data</li>
<li>Measure of Central Tendency</li>
<li>Measure of Dispersion</li>
</ul>
</li>
<li>Experiments: Descriptive Statistics</li>
</ul>
<h2 id="heading-course-introduction-and-python-basics">Course Introduction and Python Basics</h2>
<p>The instructors are Murtaza Haider(Associate professor @ Ryerson University in Toronto) and Aije Egwaikhide(Senior Data Scientist and Statisticians @ IBM).</p>
<blockquote>
<p>This course consists of five modules: Introduction and Descriptive Statistics, Data Visualization, Introduction to Probability Distribution, Hypothesis Testing, and Regression Analysis.</p>
</blockquote>
<p>The main packages relevant to analysis in python are divided into 3 groups:</p>
<ul>
<li>Scientific Computing Libraries<ul>
<li><a target="_blank" href="https://pandas.pydata.org/">Pandas</a>, offers data structure and tools</li>
<li><a target="_blank" href="https://numpy.org/doc/stable/">NumPy</a>, provides a multidimensional array object, various derived objects and so on.</li>
<li><a target="_blank" href="https://scipy.org/">SciPy</a>, provides fundamental algorithms for scientific computing in Python.</li>
</ul>
</li>
<li>Visualization Libraries<ul>
<li><a target="_blank" href="https://matplotlib.org/">Matplotlib</a>, makes graphs and plots </li>
<li><a target="_blank" href="https://seaborn.pydata.org/">Seaborn</a>, high level visualization library based on Matplotlib.</li>
</ul>
</li>
<li>Algorithmic Libraries<ul>
<li><a target="_blank" href="https://scikit-learn.org/stable/">scikit-learn</a></li>
<li><a target="_blank" href="https://www.statsmodels.org/stable/index.html">statsmodels</a></li>
</ul>
</li>
</ul>
<p>I have experience in  Python, Pandas, NumPy, Matplolib, and scikit-learn. So these are not unfamiliar to me. Here is my repository <a target="_blank" href="https://github.com/JeremiahZhang/gopython">gopython</a>.</p>
<h2 id="heading-the-basics-of-descriptive-statistics">The basics of Descriptive Statistics</h2>
<h3 id="heading-types-of-data">Types of Data</h3>
<p>In our daily lives, we are surrounded by data and statistics. The most common data would be a <strong>cross-sectional data</strong>, "which is basically looking at <em>a measurement taken at one point in time</em>"<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">1</a>. </p>
<p>Compared to the cross-sectional data, there are panel or cross-sectional panel data, "which is essentially asking the same group of individuals the same questions repeatedly over time.<a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">1</a>" </p>
<p>Another data type is the time series data, as the name indicates, it is "a series of data points indexed (or listed or graphed) in time order.<a target="_blank" href="https://en.wikipedia.org/wiki/Time_series">2:Wikipedia</a>"</p>
<h3 id="heading-measure-of-central-tendency">Measure of Central Tendency</h3>
<p>We can use mean, median, and mode to measure the central tendency of the data. In Pandas, <code>dataframe.mean()</code> and <code>dataframe.median()</code> can help us to get the mean and median of the data.</p>
<p>"The <em>mean</em> of a set of observations is the arithmetic <em>average</em> of the values.<a target="_blank" href="https://en.wikipedia.org/wiki/Mean">3</a>" It is also called the arithmetic mean. There are other types of means.</p>
<p>"The <em>median</em> is the middle number in a sorted, ascending, or descending, list of numbers and can be more descriptive of that data set than the average.<a target="_blank" href="https://www.investopedia.com/terms/m/median.asp">4</a>"</p>
<p>For example, the mean(or average) of this list of numbers <code>[10, 15, 20, 25, 30]</code> is (10 + 15 + 20 + 25 + 30) / 5 = 20. The median is 20. If the list of numbers is <code>[10, 10, 11, 12, 13, 14]</code>, the median is (11 + 12) / 2 = 11.5.</p>
<h3 id="heading-measure-of-dispersion">Measure of Dispersion</h3>
<p>The common measures of dispersion are <strong>standard deviation</strong> and <strong>variance</strong>.</p>
<p>There are sample variance and population variance. We should notice the difference between sample variance(<a target="_blank" href="https://www.statisticshowto.com/probability-and-statistics/statistics-definitions/sample-mean/">variance of the sampling distribution of the sample mean</a>) and <a target="_blank" href="https://www.statisticshowto.com/population-variance/">
Population Variance</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649842605039/jsQKmkWii.png" alt="variance" /></p>
<p>The standard deviation is the square root of the variance. So the standard deviation of the population is different from the standard deviation of the sample.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649842948836/1JW2j62oi.png" alt="std" /></p>
<h2 id="heading-experiments-descriptive-statistics">Experiments: Descriptive Statistics</h2>
<p>In this part, we can go over some hands-on exercises using Python to do some descriptive statistics. Here is the <a target="_blank" href="https://github.com/JeremiahZhang/gopython/blob/master/statistics-for-data-science-with-python/week01-descriptive-statistics.ipynb">source code</a>. You can use Google Colab to execute.</p>
]]></content:encoded></item><item><title><![CDATA[Hello, World！]]></title><description><![CDATA[Hello, everyone. I am Jeremy(Lei Zhang), a world citizen. I am new here and learning to write English articles. World Labyrinth is my Chinese Blog. Welcome to browse.
Someone said: "If you want to make the maximum amount of money possible, if you wan...]]></description><link>https://jeremyzhang.hashnode.dev/hello-world</link><guid isPermaLink="true">https://jeremyzhang.hashnode.dev/hello-world</guid><dc:creator><![CDATA[Jeremy]]></dc:creator><pubDate>Mon, 11 Apr 2022 03:34:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1649648090198/h79tzwQKa.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hello, everyone. I am Jeremy(Lei Zhang), a world citizen. I am new here and learning to write English articles. <a target="_blank" href="https://anifacc.github.io/">World Labyrinth</a> is my Chinese Blog. Welcome to browse.</p>
<p>Someone said: "If you want to make the maximum amount of money possible, if you want to get rich over your life in a deterministically predictable way, stay on the bleeding edge of trends and study technology, design, and art—become really good at something." I agree with him totally. </p>
<p>My interests are very diverse. Now I am learning Data Science, Machine Learning, and Artificial Intelligence. My background is in Mechanical Engineering(BS) and Vehicle Engineering(MS). </p>
<p>I have successfully completed the freeCodeCamp.org Data Analysis with Python. Here is the <a target="_blank" href="https://www.freecodecamp.org/certification/JeremyZhang/data-analysis-with-python-v7">certification</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1649830312177/14yuU41pS.png" alt="data_analysis_with_python_certification" /></p>
<p>Next, I will learn the IBM <a target="_blank" href="https://www.coursera.org/learn/statistics-for-data-science-python">Statistics for Data Science with Python</a> Course in Coursera. 😁🤩</p>
<p>May peace be with you.</p>
<hr />
<pre><code><span class="hljs-selector-tag">Jeremy</span>
2022<span class="hljs-selector-class">.04</span><span class="hljs-selector-class">.11</span> <span class="hljs-selector-tag">init</span>
2022<span class="hljs-selector-class">.04</span><span class="hljs-selector-class">.13</span> <span class="hljs-selector-tag">Certification</span> &amp; <span class="hljs-selector-tag">Coursera</span> <span class="hljs-selector-tag">course</span>
</code></pre>]]></content:encoded></item></channel></rss>