From d6cbfa382b7c51d0c7e5c20903430981431dbc17 Mon Sep 17 00:00:00 2001 From: Fidel Vera Chourio <108196848+fevc08@users.noreply.github.com> Date: Sun, 20 Aug 2023 02:38:12 +0000 Subject: [PATCH] my profile --- notebook/problems.ipynb | 161 +++++++++++++++++++++++++++++++--------- 1 file changed, 124 insertions(+), 37 deletions(-) diff --git a/notebook/problems.ipynb b/notebook/problems.ipynb index 2889f183..15235d2d 100644 --- a/notebook/problems.ipynb +++ b/notebook/problems.ipynb @@ -30,41 +30,73 @@ }, { "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())" ] }, { @@ -72,9 +104,18 @@ "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())" ] }, { @@ -82,12 +123,22 @@ "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)" ] }, { @@ -95,9 +146,19 @@ "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)" ] }, { @@ -105,12 +166,25 @@ "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\")" ] }, { @@ -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" ] } ], @@ -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", @@ -163,11 +244,16 @@ "\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", @@ -175,8 +261,9 @@ "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))" ] }, { @@ -209,7 +296,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.11.4" } }, "nbformat": 4,