Skip to content

modified: notebook/problems.ipynb #21

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
153 changes: 148 additions & 5 deletions notebook/problems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,109 @@
"execution_count": 1,
"id": "34720ab6",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Normal vector: [-0.14 2.06 0.28 1.33 -0.15 -0.07 0.76 0.83 -0.11 -2.37 -0.17 0.69\n",
" 0.02 0.46 0.27 -1.44 0.88 -0.58 -0.5 0.59 -0.73 0.26 -0.86 -0.19\n",
" -0.37 -0.46 -0.82 -0.05 0.12 0.93 -0.57 0.05 2.21 0.39 0.48 0.43\n",
" -1.7 -0.24 -2.14 0.86 1.7 -0.53 1.76 -1.12 -1.19 0.55 -0.82 -0.5\n",
" 1.09 -0.97 -0.28 -0.12 0.38 0.73 -0.1 -1.2 1.01 2.88 0.82 0.56\n",
" -0.38 -0.25 -1.39 0.62 -0.14 1.29 -1.04 1.36 -0.31 -0.61 -0.48 -0.61\n",
" -2.09 0.64 0.77 1.28 0.71 0.66 -1.68 0.18 -1.13 -0.28 1.4 0.03\n",
" -2.61 -1. -0.57 -0.23 0.94 0.84 0.81 0.23 -0.3 -0.36 0.43 0.93\n",
" 1.55 0.09 0.29 1.49]\n",
"\n",
" Chi square vector: [0.68 4.59 6.88 8. 0.75 3.57 2.09 2.69 3.27 0.74 4.13 3.75 5.86 0.75\n",
" 5.25 5.22 4.24 2.33 2.63 1.13 1.72 0.32 1.82 0.49 1.57 0.54 3.13 0.7\n",
" 6.19 2.07 0.85 0.43 4.24 4.89 2.1 1.44 1.5 0.85 5.31 1.87 1.95 1.\n",
" 2.2 1.63 1.43 1.81 3.34 5.18 0.74 0.67 0.81 2.43 1.89 0.82 4.39 3.41\n",
" 1.3 2.76 1.61 1.81 1.53 4.34 1.95 0.49 7.05 3.21 6.3 2.58 3.76 0.23\n",
" 2.36 5.88 4.16 0.42 6.48 1.27 4.36 1.55 2.1 3.53 1.82 0.14 1.64 1.95\n",
" 1.37 3.26 2.03 0.5 0.19 2.76 1.44 6.12 1.1 5.01 3.53 1.1 4.53 7.01\n",
" 1.69 4.27] \n",
"Normal mean: 0.05970000000000001\n",
"\n",
"Chi mean: 2.6677\n",
"\n",
"Normal median: 0.025\n",
" Chi Square median: 2.05\n",
"\n",
"Normal mode: -0.14 \n",
" Chi Square mode: 1.95\n",
"\n",
"Normal range: 2.7399999999999998 \n",
"Chi range: 7.86\n",
"\n",
" Normal variance is: 0.9918029393939394 and normal standard desviation 0.9958930361208173\n",
"\n",
"Chi Square vaciance is: 3.629947181818182 and chi standard desviation 1.9052420270973927\n",
"\n",
"Normal skewness: -0.11747207959176492 Chi Skewness 0.8022466752368267\n",
"\n",
" Normal kurtosis: 0.3342063860928839 Chi Kurtosis -0.2580203698679746\n"
]
}
],
"source": [
"# TODO"
"import numpy as np\n",
"\n",
"np.random.seed(99)\n",
"\n",
"normal = np.random.normal(size=100)\n",
"chi_square = np.random.chisquare(3, 100)\n",
"normal_rounded = np.round(normal, decimals=2)\n",
"chi_square_rounded = np.round(chi_square, decimals=2)\n",
"\n",
"print(f\"\\nNormal vector: {normal_rounded}\\n\\n Chi square vector: {chi_square_rounded} \")\n",
"\n",
"#_______________MEASURES_____________________________________________________________\n",
"\n",
"import statistics as stats\n",
"\n",
"#MEAN\n",
"print(f\"Normal mean: {stats.mean(normal_rounded)}\")\n",
"print(f\"\\nChi mean: {stats.mean(chi_square_rounded)}\")\n",
"\n",
"#MEDIAN\n",
"print(f\"\\nNormal median: {stats.median(normal_rounded)}\\n Chi Square median: {stats.median(chi_square_rounded)}\")\n",
"\n",
"#MODE\n",
"print(f\"\\nNormal mode: {stats.mode(normal_rounded)} \\n Chi Square mode: {stats.mode(chi_square_rounded)}\")\n",
"\n",
"#_________________MEASURES OF DISPERSION_________________________________\n",
"\n",
"#RANGE\n",
"normal_range = max(normal_rounded)-min(chi_square_rounded)\n",
"chi_range = max(chi_square_rounded)-min(chi_square_rounded)\n",
"print(f\"\\nNormal range: {normal_range} \\nChi range: {chi_range}\")\n",
"\n",
"#STANDARD DESVIATION AND VARIANCE______________\n",
"normal_var = stats.variance(normal_rounded)\n",
"chi_var = stats.variance(chi_square_rounded)\n",
"normal_sd = stats.stdev(normal_rounded)\n",
"chi_sd = stats.stdev(chi_square_rounded)\n",
"print(f\"\\n Normal variance is: {normal_var} and normal standard desviation {normal_sd}\")\n",
"print(f\"\\nChi Square vaciance is: {chi_var} and chi standard desviation {chi_sd}\")\n",
"\n",
"#SHAPE MEASURES____________\n",
"\n",
"#SKEWNESS\n",
"from scipy.stats import skew,kurtosis \n",
"\n",
"normal_skew = skew(normal_rounded)\n",
"chi_skew = skew(chi_square_rounded)\n",
"print(f\"\\nNormal skewness: {normal_skew} Chi Skewness {chi_skew}\")\n",
"\n",
"#KURTOSIS \n",
"normal_kurt = kurtosis(normal_rounded)\n",
"chi_kurt = kurtosis(chi_square_rounded)\n",
"print(f\"\\n Normal kurtosis: {normal_kurt} Chi Kurtosis {chi_kurt}\")\n",
"\n",
"\n"
]
},
{
Expand All @@ -48,12 +148,55 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "d590308e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data: [4, 2, 5, 8, 6]\n",
"the standard deviation for these data is: 2.23606797749979\n"
]
}
],
"source": [
"# TODO"
"import math\n",
"import sys\n",
"\n",
"data = [4, 2, 5, 8, 6]\n",
"\n",
"def standard_deviation(data):\n",
" n = len(data)\n",
"\n",
" if (n <= 1):\n",
" return 0.0\n",
"\n",
" mean, sd = average(data), 0.0\n",
"\n",
" for d in data:\n",
" sd += (float(d) - mean) ** 2\n",
" sd = math.sqrt(sd / float(n - 1))\n",
"\n",
" return sd\n",
"\n",
"def average(data):\n",
" n, mean = len(data), 0.0\n",
"\n",
" if (n <= 1):\n",
" return data[0]\n",
"\n",
" for d in data:\n",
" mean = mean + float(d)\n",
"\n",
" mean = mean / float(n)\n",
" return mean\n",
"\n",
"\n",
"data = [4, 2, 5, 8, 6]\n",
"print(f\"Data: {data}\")\n",
"print(f\"the standard deviation for these data is: {standard_deviation(data)}\")"
]
}
],
Expand Down