Skip to content

main #4

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 124 additions & 37 deletions notebook/problems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,87 +30,161 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"id": "34720ab6",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The array elements distribute normally are:\n",
" [-2.42878499 -1.34216896 -0.1872267 -1.91076622 1.61142874 -0.39538096\n",
" -0.13866769 1.31755992 1.43755063 0.3461454 -0.3022814 0.8692907\n",
" -0.23959013 1.14812635 -0.65393263 0.87660662 -0.30258082 -0.31233049\n",
" 1.52497392 0.91100354]\n"
]
}
],
"source": [
"#import libraries\n",
"\n",
"import random\n",
"import numpy as np\n",
"\n",
"# Set seed in order to get similar results\n",
"\n",
"random.seed(20)\n",
"\n",
"# create the data\n",
"data = np.random.normal(0,1,20)\n",
"\n",
"\n",
"#print results"
"#print results\n",
"print(\"The array elements distribute normally are:\\n\",data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "49c55822",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The mean of the data is: 0.0914487413075153\n"
]
}
],
"source": [
"#Use numpy to get the mean of your data"
"#Use numpy to get the mean of your data\n",
"print(\"The mean of the data is: \",data.mean())"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "03529459",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The variation of the data is: 1.2338555658446149\n"
]
}
],
"source": [
"#get the variance of your data"
"#get the variance of your data\n",
"print(\"The variation of the data is: \",data.var())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e53f30c5",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The standard deviation of the data is: 1.1107905139334846\n"
]
}
],
"source": [
"# Standard deviation\n"
"# Standard deviation\n",
"print(\"The standard deviation of the data is: \",data.std())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9bce852f",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The data mode is: -2.428784987925977\n"
]
}
],
"source": [
"#import libraries and print the mode\n",
"import statistics\n",
"\n",
"\n",
"# Mode for continuous array\n"
"# Mode for continuous array\n",
"data_mode = statistics.mode(data)\n",
"print(\"The data mode is: \",data_mode)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "c682cb6e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The data median is: -0.16294719647810535\n"
]
}
],
"source": [
"# Median\n"
"# Median\n",
"data_median = statistics.median(data)\n",
"print(\"The data median is: \",data_median)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "39c3fabd",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The Quantiles of the data are:\n",
" [-0.374618339376134, -0.16294719647810535, 1.0888456458137472]\n",
"The median data is: -0.16294719647810535\n",
"The median value match with the quantile match because, this value, represent the value tha we can find in the middle of the dataset\n"
]
}
],
"source": [
"# Print the Quantiles\n",
"print(\"The Quantiles of the data are:\\n\",statistics.quantiles(data))\n",
"\n",
"\n",
"# This match with np.median, why?\n"
"# This match with np.median, why?\n",
"print(\"The median data is: \",np.median(data))\n",
"print(\"The median value match with the quantile match because, this value, represent the value tha we can find in the middle of the dataset\")"
]
},
{
Expand All @@ -128,16 +202,17 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 11,
"id": "d590308e",
"metadata": {},
"outputs": [
{
"ename": "IndentationError",
"evalue": "expected an indented block (4006267275.py, line 20)",
"output_type": "error",
"traceback": [
"\u001b[1;36m Input \u001b[1;32mIn [8]\u001b[1;36m\u001b[0m\n\u001b[1;33m def avg_calc(ls):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
"name": "stdout",
"output_type": "stream",
"text": [
"The data values are:\n",
" [4, 2, 5, 8, 6]\n",
"The Standard deviation is: 2.0\n"
]
}
],
Expand All @@ -149,11 +224,17 @@
"\n",
"def sd_calc(data):\n",
" #code here\n",
" n = len(data)\n",
" if n<= 1:\n",
" return 0.0\n",
" \n",
" \n",
" \n",
"\n",
" mean = avg_calc(data)\n",
" sd = 0\n",
" for x in data:\n",
" sd += (float(x) - mean)**2\n",
" # calculate stan. dev.\n",
" sd = math.sqrt(sd / float(n))\n",
" return sd\n",
" \n",
"\n",
"\n",
Expand All @@ -163,20 +244,26 @@
"\n",
"def avg_calc(ls):\n",
" #code here\n",
" n = len(ls)\n",
" if n <= 1:\n",
" return ls[0]\n",
" \n",
" \n",
" \n",
"\n",
" mean = 0\n",
" for x in ls:\n",
" mean += float(x) \n",
" # calculate average\n",
" mean = mean / float(n)\n",
" return mean\n",
" \n",
" \n",
" \n",
"\n",
"data = [4, 2, 5, 8, 6]\n",
"\n",
"#print the data\n",
"\n",
"#print the standard deviation of the data"
"print(\"The data values are:\\n\",data)\n",
"#print the standard deviation of the data\n",
"print(\"The Standard deviation is: \",sd_calc(data))"
]
},
{
Expand Down Expand Up @@ -209,7 +296,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down