-
Notifications
You must be signed in to change notification settings - Fork 6
Buynak-Yinyying-Mildige Submission #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mbuynak
wants to merge
3
commits into
lyy005:master
Choose a base branch
from
mbuynak:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Challenge 1" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 2) Plot the data " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 2, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import pandas as pd\n", | ||
| "data=pd.read_table('chickwts.txt',sep=',')" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 6, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "<matplotlib.axes._subplots.AxesSubplot at 0x115b369d0>" | ||
| ] | ||
| }, | ||
| "execution_count": 6, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "data.boxplot(by='feed',column='weight',grid=False,figsize=(15,15))\n", | ||
| "# I am not sure why somehow there is no figure in Jupyter but I did get a barplot in python. " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "source": [ | ||
| "## 3) A hypothesis test\n", | ||
| "\n", | ||
| "### Null hypothesis: the weight of chick fed by soybean has no significant difference with the weight of chick fed by sunflower\n", | ||
| "### Alternative hypothesis: the weight of chick fed by soybean has significant difference with the weight of chick fed by sunflower" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 4) Hypothesis test" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 31, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "le=LabelEncoder()\n", | ||
| "le.fit(data['feed'])\n", | ||
| "data['Index']=le.transform(data['feed'])\n", | ||
| "x=data[(data['feed']=='soybean')|(data['feed']=='sunflower')]['Index']\n", | ||
| "y=data[(data['feed']=='soybean')|(data['feed']=='sunflower')]['weight']" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 28, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "Optimization terminated successfully.\n", | ||
| " Current function value: 145.240592\n", | ||
| " Iterations: 85\n", | ||
| " Function evaluations: 162\n" | ||
| ] | ||
| }, | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "array([ 284.49999051, 64.53691755])" | ||
| ] | ||
| }, | ||
| "execution_count": 28, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "import numpy as np\n", | ||
| "from scipy.optimize import minimize\n", | ||
| "from scipy.stats import norm\n", | ||
| "\n", | ||
| "# null hypothesis\n", | ||
| "def null(p,obs):\n", | ||
| " B0=p[0]\n", | ||
| " sigma=p[1]\n", | ||
| " \n", | ||
| " expected=B0\n", | ||
| " nll=-1*norm(expected,sigma).logpdf(obs).sum()\n", | ||
| " return nll\n", | ||
| "\n", | ||
| "initialGuess1=np.array([1,1])\n", | ||
| "fitNull=minimize(null,initialGuess1,method=\"Nelder-Mead\",options={'disp':True},args=(y))\n", | ||
| "fitNull.x" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 29, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "Optimization terminated successfully.\n", | ||
| " Current function value: 138.469162\n", | ||
| " Iterations: 194\n", | ||
| " Function evaluations: 360\n" | ||
| ] | ||
| }, | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "array([-83.52384926, 82.48810462, 49.73945446])" | ||
| ] | ||
| }, | ||
| "execution_count": 29, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "# alternative hypothesis\n", | ||
| "def alter(p,obs1,obs2):\n", | ||
| " B0=p[0]\n", | ||
| " B1=p[1]\n", | ||
| " sigma=p[2]\n", | ||
| " \n", | ||
| " expected=B0+B1*obs1\n", | ||
| " nll=-1*norm(expected,sigma).logpdf(obs2).sum()\n", | ||
| " return nll\n", | ||
| "\n", | ||
| "initialGuess1=np.array([1,1,1])\n", | ||
| "fitalter=minimize(alter,initialGuess1,method=\"Nelder-Mead\",options={'disp':True},args=(x,y))\n", | ||
| "fitalter.x" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 30, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "0.0002331767286918307" | ||
| ] | ||
| }, | ||
| "execution_count": 30, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "from scipy.stats import chi2\n", | ||
| "D=2*(fitNull.fun-fitalter.fun)\n", | ||
| "1-chi2.cdf(x=D,df=1) " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 5) Hypothesis test result" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## If we consider alfa=0.05, then p value is smaller than 0.05, we can reject the null hyphothesis and conclude that the weight of chick fed by soybean has significant difference with the weight of chick fed by sunflower. " | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 2", | ||
| "language": "python", | ||
| "name": "python2" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 2 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython2", | ||
| "version": "2.7.13" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 2 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# Challenge 2" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 1) Times after noon but before midnight, reported in 24 hours or \"military\" format \n", | ||
| "\n", | ||
| "### Times after noon and before midnight, so the numbes before comma should be larger than 12 and smaller than 24. Meanwhile, the number for minute should be in the range of 0-60." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 12, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "['15:30']" | ||
| ] | ||
| }, | ||
| "execution_count": 12, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "import re as re\n", | ||
| "reg1=re.compile('([1][2-9]\\:([0-5][0-9]|[6][0]))|([2][0-3]\\:([0-5][0-9]|[6][0]))')\n", | ||
| "testset1=['15:30','24:00']\n", | ||
| "filter(reg1.match,testset1)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 2) Genus species names \n", | ||
| "\n", | ||
| "### First letter should be capitalized, then it comes with the \".\", then six letters in the lower case. " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 13, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "['H.sapien']" | ||
| ] | ||
| }, | ||
| "execution_count": 13, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "reg2=re.compile('[A-Z]{1}\\.[a-z]{6}')\n", | ||
| "testset2=['H.sapien','h.sapien']\n", | ||
| "filter(reg2.match,testset2)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 3) Social security numbers\n", | ||
| "\n", | ||
| "### Three numbers, then \"-\", then two numbers, then \"-\", then four numbers " | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": 14, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "['389-05-4771']" | ||
| ] | ||
| }, | ||
| "execution_count": 14, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "reg3=re.compile('[0-9]{3}\\-[0-9]{2}\\-[0-9]{4}')\n", | ||
| "testset3=['389-05-4771','38-051-41']\n", | ||
| "filter(reg3.match,testset3)" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 2", | ||
| "language": "python", | ||
| "name": "python2" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 2 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython2", | ||
| "version": "2.7.13" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 2 | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job