Dataset Viewer (First 5GB)
Auto-converted to Parquet
Search is not available for this dataset
text
stringlengths
1.36k
98.2M
id
stringlengths
23
24
file_path
stringclasses
49 values
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.214922Z", "iopub.status.busy": "2021-10-07T06:52:24.214472Z", "iopub.status.idle": "2021-10-07T06:52:24.219972Z", "shell.execute_reply": "2021-10-07T06:52:24.219374Z", "shell.execute_reply.started": "2021-10-07T06:52:24.214868Z" } }, "outputs": [], "source": [ "import numpy as np\n", "from numpy.linalg import eig\n", "from numpy import matrix\n", "import sympy as sy\n", "import mpmath\n", "from sympy import *\n", "from mpmath import *\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.221870Z", "iopub.status.busy": "2021-10-07T06:52:24.221430Z", "iopub.status.idle": "2021-10-07T06:52:24.233504Z", "shell.execute_reply": "2021-10-07T06:52:24.232823Z", "shell.execute_reply.started": "2021-10-07T06:52:24.221812Z" } }, "outputs": [], "source": [ "x=sy.Symbol('x')\n", "y=sy.Symbol('y')\n", "z=sy.Symbol('z')" ] }, { "cell_type": "markdown", "metadata": { "execution": { "iopub.execute_input": "2021-10-05T07:32:12.720671Z", "iopub.status.busy": "2021-10-05T07:32:12.720204Z", "iopub.status.idle": "2021-10-05T07:32:12.727169Z", "shell.execute_reply": "2021-10-05T07:32:12.725992Z", "shell.execute_reply.started": "2021-10-05T07:32:12.720628Z" } }, "source": [ "**Lets define a Matrix** " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.236323Z", "iopub.status.busy": "2021-10-07T06:52:24.235736Z", "iopub.status.idle": "2021-10-07T06:52:24.248682Z", "shell.execute_reply": "2021-10-07T06:52:24.247566Z", "shell.execute_reply.started": "2021-10-07T06:52:24.236044Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 & 2\\\\9 & 4\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1, 2],\n", "[9, 4]])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a= sy.Matrix(2,2,[1,2,9,4])\n", "a" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.250628Z", "iopub.status.busy": "2021-10-07T06:52:24.250254Z", "iopub.status.idle": "2021-10-07T06:52:24.263720Z", "shell.execute_reply": "2021-10-07T06:52:24.262482Z", "shell.execute_reply.started": "2021-10-07T06:52:24.250560Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 & 2\\\\1 & 1\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1, 2],\n", "[1, 1]])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b = sy.Matrix( [ [1,2] , [1,1] ] )\n", "b" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.265779Z", "iopub.status.busy": "2021-10-07T06:52:24.265417Z", "iopub.status.idle": "2021-10-07T06:52:24.280015Z", "shell.execute_reply": "2021-10-07T06:52:24.279161Z", "shell.execute_reply.started": "2021-10-07T06:52:24.265711Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}3 & 1 & -1\\\\2 & 2 & -1\\\\2 & 2 & 0\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[3, 1, -1],\n", "[2, 2, -1],\n", "[2, 2, 0]])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = sy.Matrix(3,3,[3,1,-1,2,2,-1,2,2,0])\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Lets do some basic Matrix operations**\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.283417Z", "iopub.status.busy": "2021-10-07T06:52:24.282643Z", "iopub.status.idle": "2021-10-07T06:52:24.292536Z", "shell.execute_reply": "2021-10-07T06:52:24.291436Z", "shell.execute_reply.started": "2021-10-07T06:52:24.283357Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}2 & 4\\\\10 & 5\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[ 2, 4],\n", "[10, 5]])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a + b" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.294375Z", "iopub.status.busy": "2021-10-07T06:52:24.294092Z", "iopub.status.idle": "2021-10-07T06:52:24.306825Z", "shell.execute_reply": "2021-10-07T06:52:24.306082Z", "shell.execute_reply.started": "2021-10-07T06:52:24.294298Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}3 & 4\\\\13 & 22\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[ 3, 4],\n", "[13, 22]])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a*b # this ai * bj" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**inverse**" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.308526Z", "iopub.status.busy": "2021-10-07T06:52:24.308095Z", "iopub.status.idle": "2021-10-07T06:52:24.323283Z", "shell.execute_reply": "2021-10-07T06:52:24.322431Z", "shell.execute_reply.started": "2021-10-07T06:52:24.308465Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}- \\frac{2}{7} & \\frac{1}{7}\\\\\\frac{9}{14} & - \\frac{1}{14}\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[-2/7, 1/7],\n", "[9/14, -1/14]])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a**-1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**transpose**" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.325020Z", "iopub.status.busy": "2021-10-07T06:52:24.324567Z", "iopub.status.idle": "2021-10-07T06:52:24.335774Z", "shell.execute_reply": "2021-10-07T06:52:24.334920Z", "shell.execute_reply.started": "2021-10-07T06:52:24.324980Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 & 9\\\\2 & 4\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1, 9],\n", "[2, 4]])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a.T" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**identity matrix**" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.337431Z", "iopub.status.busy": "2021-10-07T06:52:24.337016Z", "iopub.status.idle": "2021-10-07T06:52:24.351792Z", "shell.execute_reply": "2021-10-07T06:52:24.350998Z", "shell.execute_reply.started": "2021-10-07T06:52:24.337281Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 & 0 & 0\\\\0 & 1 & 0\\\\0 & 0 & 1\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1, 0, 0],\n", "[0, 1, 0],\n", "[0, 0, 1]])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sy.eye(3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**diagonal matrix**" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.354994Z", "iopub.status.busy": "2021-10-07T06:52:24.354432Z", "iopub.status.idle": "2021-10-07T06:52:24.365365Z", "shell.execute_reply": "2021-10-07T06:52:24.363954Z", "shell.execute_reply.started": "2021-10-07T06:52:24.354938Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 & 0 & 0\\\\0 & 2 & 0\\\\0 & 0 & 3\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1, 0, 0],\n", "[0, 2, 0],\n", "[0, 0, 3]])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sy.diag(1,2,3)\n", "#sy.diag(x+1,x+2,x+3) # diagonal matrix" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**determinant of matrix**" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.368737Z", "iopub.status.busy": "2021-10-07T06:52:24.368319Z", "iopub.status.idle": "2021-10-07T06:52:24.378041Z", "shell.execute_reply": "2021-10-07T06:52:24.377358Z", "shell.execute_reply.started": "2021-10-07T06:52:24.368679Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle -14$" ], "text/plain": [ "-14" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sy.det(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Find dot/inner product of a vector**" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.379824Z", "iopub.status.busy": "2021-10-07T06:52:24.379373Z", "iopub.status.idle": "2021-10-07T06:52:24.391822Z", "shell.execute_reply": "2021-10-07T06:52:24.390586Z", "shell.execute_reply.started": "2021-10-07T06:52:24.379782Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 1$" ], "text/plain": [ "1" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = sy.Matrix([3,4,-1])\n", "b = sy.Matrix([2,-1,1])\n", "\n", "a.dot(b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**find unit length of vectoer**" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.393956Z", "iopub.status.busy": "2021-10-07T06:52:24.393524Z", "iopub.status.idle": "2021-10-07T06:52:24.402002Z", "shell.execute_reply": "2021-10-07T06:52:24.401301Z", "shell.execute_reply.started": "2021-10-07T06:52:24.393898Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 2.44948974278318$" ], "text/plain": [ "2.44948974278318" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def magnitude(vector) :\n", " return sy.sqrt(vector.dot(vector))\n", "magnitude(b).evalf()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Find angle bet 2 vectors**" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.403918Z", "iopub.status.busy": "2021-10-07T06:52:24.403501Z", "iopub.status.idle": "2021-10-07T06:52:24.412512Z", "shell.execute_reply": "2021-10-07T06:52:24.411844Z", "shell.execute_reply.started": "2021-10-07T06:52:24.403864Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle 85.407751113661$" ], "text/plain": [ "85.4077511136610" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "angle = sy.acos(a.dot(b) /(magnitude(a)*magnitude(b)) ).evalf()\n", "angle*180/pi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Orthogonality**" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.414273Z", "iopub.status.busy": "2021-10-07T06:52:24.414023Z", "iopub.status.idle": "2021-10-07T06:52:24.423988Z", "shell.execute_reply": "2021-10-07T06:52:24.422686Z", "shell.execute_reply.started": "2021-10-07T06:52:24.414230Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a & b are not orthogonal sets in R\n" ] } ], "source": [ "if a.dot(b) == 0 :\n", " if a.dot(a) == b.dot(b) == 1 :\n", " print('a & b are orthonormal sets in R')\n", " else :\n", " print('a & b are not orthonormal sets in R')\n", " print('But a & b are orthogonal sets in R')\n", "else : \n", " print('a & b are not orthogonal sets in R')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Linear Dependence / Independence**" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.426596Z", "iopub.status.busy": "2021-10-07T06:52:24.425967Z", "iopub.status.idle": "2021-10-07T06:52:24.434998Z", "shell.execute_reply": "2021-10-07T06:52:24.434043Z", "shell.execute_reply.started": "2021-10-07T06:52:24.426268Z" } }, "outputs": [], "source": [ "a = sy.Matrix([1,3,0])\n", "b = sy.Matrix([2,0,1])\n", "c = sy.Matrix([3,3,1])\n", "\n", "solve1 = x*a + y*b + z*c\n", "\n", "#L = sy.Matrix(sy.solve_poly_system ( [solve1[0] , solve1[1],solve1[2]], x, y,z))\n", "#r,c = L.shape\n", "\n", "#if L == sy.zeros(r,c) :\n", "# print('a,b,c are linearly independent')\n", "#else :\n", "# print('a,b,c are linearly dependent')\n", " " ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.437110Z", "iopub.status.busy": "2021-10-07T06:52:24.436581Z", "iopub.status.idle": "2021-10-07T06:52:24.451973Z", "shell.execute_reply": "2021-10-07T06:52:24.450766Z", "shell.execute_reply.started": "2021-10-07T06:52:24.437051Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}x + 2 y + 3 z\\\\3 x + 3 z\\\\y + z\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[x + 2*y + 3*z],\n", "[ 3*x + 3*z],\n", "[ y + z]])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "solve1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**find eigenvalue/vector**" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:04:26.813233Z", "iopub.status.busy": "2021-10-07T07:04:26.812906Z", "iopub.status.idle": "2021-10-07T07:04:26.823731Z", "shell.execute_reply": "2021-10-07T07:04:26.822166Z", "shell.execute_reply.started": "2021-10-07T07:04:26.813169Z" } }, "outputs": [], "source": [ "M = sy.Matrix(4,3,[1,-1,2,2,3,4,-3,2,3,3,4,5])\n", "m = M*M.T" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "execution": { "iopub.status.busy": "2021-10-07T07:54:14.636935Z", "iopub.status.idle": "2021-10-07T07:54:14.637626Z" } }, "outputs": [], "source": [ "#q = m.eigenvects()\n", "#for i in range(len(q)):\n", "# print('Eigenvalue ', q[i][0].evalf() , ' has multiciplity ',q[i][1],' & eigenvector ',q[i][-1])" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:13:04.579873Z", "iopub.status.busy": "2021-10-07T07:13:04.579502Z", "iopub.status.idle": "2021-10-07T07:13:04.604246Z", "shell.execute_reply": "2021-10-07T07:13:04.602748Z", "shell.execute_reply.started": "2021-10-07T07:13:04.579817Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Eigenvalue 85.934903833959 - 0.e-20*I has multiciplity 1\n", "Eigenvalue 4.03935299870572 + 0.e-21*I has multiciplity 1\n", "Eigenvalue 17.0257431673353 - 0.e-21*I has multiciplity 1\n", "Eigenvalue 0 has multiciplity 1\n" ] } ], "source": [ "p = m.eigenvals()\n", "for key,value in p.items():\n", " print('Eigenvalue ',key.evalf() ,' has multiciplity ' , value)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**OR**" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:46:43.166960Z", "iopub.status.busy": "2021-10-07T07:46:43.166656Z", "iopub.status.idle": "2021-10-07T07:46:43.177211Z", "shell.execute_reply": "2021-10-07T07:46:43.175854Z", "shell.execute_reply.started": "2021-10-07T07:46:43.166918Z" } }, "outputs": [ { "data": { "text/plain": [ "(array([ 8.59349038e+01, 1.70257432e+01, 4.03935300e+00, -2.10376436e-15]),\n", " array([[-0.13910258, -0.17261518, -0.9737285 , 0.05203149],\n", " [-0.5788883 , -0.10522179, 0.05825542, -0.80648807],\n", " [-0.27605195, 0.95067628, -0.12561769, 0.06503936],\n", " [-0.75454233, -0.23525938, 0.18077418, 0.58535425]]))" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = np.array([[1,-1,2],[2,3,4],[-3,2,3],[3,4,5]])\n", "a = np.matmul(A,A.T)\n", "np.linalg.eig(a)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**find characterploynomial**" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.496532Z", "iopub.status.busy": "2021-10-07T06:52:24.495835Z", "iopub.status.idle": "2021-10-07T06:52:24.512774Z", "shell.execute_reply": "2021-10-07T06:52:24.511739Z", "shell.execute_reply.started": "2021-10-07T06:52:24.496270Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the character ploynomial is PurePoly(x**4 - 107*x**3 + 1879*x**2 - 5910*x, x, domain='ZZ')\n", "the factors are \n" ] }, { "data": { "text/latex": [ "$\\displaystyle x \\left(x^{3} - 107 x^{2} + 1879 x - 5910\\right)$" ], "text/plain": [ "x*(x**3 - 107*x**2 + 1879*x - 5910)" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c = m.charpoly(x)\n", "print('the character ploynomial is ',c)\n", "\n", "print('the factors are ')\n", "sy.factor(c)" ] }, { "cell_type": "markdown", "metadata": { "execution": { "iopub.execute_input": "2021-09-27T15:42:17.303606Z", "iopub.status.busy": "2021-09-27T15:42:17.303325Z", "iopub.status.idle": "2021-09-27T15:42:17.313166Z", "shell.execute_reply": "2021-09-27T15:42:17.312216Z", "shell.execute_reply.started": "2021-09-27T15:42:17.303555Z" } }, "source": [ "**Diagonalize a matrix**" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.514556Z", "iopub.status.busy": "2021-10-07T06:52:24.514283Z", "iopub.status.idle": "2021-10-07T06:52:24.578454Z", "shell.execute_reply": "2021-10-07T06:52:24.577360Z", "shell.execute_reply.started": "2021-10-07T06:52:24.514510Z" } }, "outputs": [], "source": [ "b = sy.Matrix( [ [1,2] , [1,1] ] )\n", "(P,D) = b.diagonalize()" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.580516Z", "iopub.status.busy": "2021-10-07T06:52:24.580139Z", "iopub.status.idle": "2021-10-07T06:52:24.589141Z", "shell.execute_reply": "2021-10-07T06:52:24.588022Z", "shell.execute_reply.started": "2021-10-07T06:52:24.580445Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}1 - \\sqrt{2} & 0\\\\0 & 1 + \\sqrt{2}\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[1 - sqrt(2), 0],\n", "[ 0, 1 + sqrt(2)]])" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "D" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.591687Z", "iopub.status.busy": "2021-10-07T06:52:24.591358Z", "iopub.status.idle": "2021-10-07T06:52:24.600987Z", "shell.execute_reply": "2021-10-07T06:52:24.599754Z", "shell.execute_reply.started": "2021-10-07T06:52:24.591646Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}- \\sqrt{2} & \\sqrt{2}\\\\1 & 1\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[-sqrt(2), sqrt(2)],\n", "[ 1, 1]])" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.602661Z", "iopub.status.busy": "2021-10-07T06:52:24.602320Z", "iopub.status.idle": "2021-10-07T06:52:24.615890Z", "shell.execute_reply": "2021-10-07T06:52:24.614571Z", "shell.execute_reply.started": "2021-10-07T06:52:24.602610Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "P**-1 * b * P == D" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Check if a matrix is diagonalizable**" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:44:57.922240Z", "iopub.status.busy": "2021-10-07T07:44:57.921906Z", "iopub.status.idle": "2021-10-07T07:44:57.929470Z", "shell.execute_reply": "2021-10-07T07:44:57.928359Z", "shell.execute_reply.started": "2021-10-07T07:44:57.922187Z" } }, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m.is_diagonalizable()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**find singular value decomposition**" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:51:20.931238Z", "iopub.status.busy": "2021-10-07T07:51:20.930834Z", "iopub.status.idle": "2021-10-07T07:51:20.937585Z", "shell.execute_reply": "2021-10-07T07:51:20.935870Z", "shell.execute_reply.started": "2021-10-07T07:51:20.931175Z" } }, "outputs": [], "source": [ "#A = np.array([[1,2],[3,4],[5,6],[7,8]])\n", "U, S, V = np.linalg.svd(A)\n" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:51:25.353534Z", "iopub.status.busy": "2021-10-07T07:51:25.353144Z", "iopub.status.idle": "2021-10-07T07:51:25.358348Z", "shell.execute_reply": "2021-10-07T07:51:25.357474Z", "shell.execute_reply.started": "2021-10-07T07:51:25.353469Z" } }, "outputs": [], "source": [ "r,c = A.shape" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:51:27.045817Z", "iopub.status.busy": "2021-10-07T07:51:27.045243Z", "iopub.status.idle": "2021-10-07T07:51:27.054849Z", "shell.execute_reply": "2021-10-07T07:51:27.053519Z", "shell.execute_reply.started": "2021-10-07T07:51:27.045749Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[-0.13910258, 0.17261518, -0.9737285 , 0.05203149],\n", " [-0.5788883 , 0.10522179, 0.05825542, -0.80648807],\n", " [-0.27605195, -0.95067628, -0.12561769, 0.06503936],\n", " [-0.75454233, 0.23525938, 0.18077418, 0.58535425]])" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "U" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:51:28.685691Z", "iopub.status.busy": "2021-10-07T07:51:28.685300Z", "iopub.status.idle": "2021-10-07T07:51:28.692505Z", "shell.execute_reply": "2021-10-07T07:51:28.691822Z", "shell.execute_reply.started": "2021-10-07T07:51:28.685636Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[9.27010808, 0. , 0. ],\n", " [0. , 4.12622626, 0. ],\n", " [0. , 0. , 2.00981417],\n", " [0. , 0. , 0. ]])" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "S \n", "s = np.zeros((r, c))\n", "np.fill_diagonal(s, S) #s = np.array([[14.2690955,0],[0,0.62682823],[0,0],[0,0]])\n", "s" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:51:39.306340Z", "iopub.status.busy": "2021-10-07T07:51:39.305840Z", "iopub.status.idle": "2021-10-07T07:51:39.312474Z", "shell.execute_reply": "2021-10-07T07:51:39.311594Z", "shell.execute_reply.started": "2021-10-07T07:51:39.306284Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[-0.29474849, -0.55747306, -0.77611025],\n", " [ 0.95507747, -0.19806593, -0.22044705],\n", " [ 0.03082771, 0.80622185, -0.5908096 ]])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "V" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:51:40.677665Z", "iopub.status.busy": "2021-10-07T07:51:40.677197Z", "iopub.status.idle": "2021-10-07T07:51:40.684755Z", "shell.execute_reply": "2021-10-07T07:51:40.683968Z", "shell.execute_reply.started": "2021-10-07T07:51:40.677600Z" } }, "outputs": [ { "data": { "text/plain": [ "array([[ 1., -1., 2.],\n", " [ 2., 3., 4.],\n", " [-3., 2., 3.],\n", " [ 3., 4., 5.]])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.matmul(np.matmul(U,s),V)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**hence proved U*S*V is A**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Find hessian of matrix**" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.746445Z", "iopub.status.busy": "2021-10-07T06:52:24.746124Z", "iopub.status.idle": "2021-10-07T06:52:24.753620Z", "shell.execute_reply": "2021-10-07T06:52:24.752574Z", "shell.execute_reply.started": "2021-10-07T06:52:24.746392Z" } }, "outputs": [], "source": [ "from sympy import hessian , Function , pprint" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.756625Z", "iopub.status.busy": "2021-10-07T06:52:24.755997Z", "iopub.status.idle": "2021-10-07T06:52:24.765530Z", "shell.execute_reply": "2021-10-07T06:52:24.764452Z", "shell.execute_reply.started": "2021-10-07T06:52:24.756527Z" } }, "outputs": [], "source": [ "f = Function('f')(x,y,z)\n", "g1 = Function('g')(x,y,z)\n", "g2 = sy.sin(x*y*z)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "execution": { "iopub.execute_input": "2021-10-07T06:52:24.767695Z", "iopub.status.busy": "2021-10-07T06:52:24.767344Z", "iopub.status.idle": "2021-10-07T06:52:24.808346Z", "shell.execute_reply": "2021-10-07T06:52:24.807203Z", "shell.execute_reply.started": "2021-10-07T06:52:24.767627Z" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[\\begin{matrix}0 & 0 & \\frac{\\partial}{\\partial x} g{\\left(x,y,z \\right)} & \\frac{\\partial}{\\partial y} g{\\left(x,y,z \\right)} & \\frac{\\partial}{\\partial z} g{\\left(x,y,z \\right)}\\\\0 & 0 & y z \\cos{\\left(x y z \\right)} & x z \\cos{\\left(x y z \\right)} & x y \\cos{\\left(x y z \\right)}\\\\\\frac{\\partial}{\\partial x} g{\\left(x,y,z \\right)} & y z \\cos{\\left(x y z \\right)} & \\frac{\\partial^{2}}{\\partial x^{2}} f{\\left(x,y,z \\right)} & \\frac{\\partial^{2}}{\\partial y\\partial x} f{\\left(x,y,z \\right)} & \\frac{\\partial^{2}}{\\partial z\\partial x} f{\\left(x,y,z \\right)}\\\\\\frac{\\partial}{\\partial y} g{\\left(x,y,z \\right)} & x z \\cos{\\left(x y z \\right)} & \\frac{\\partial^{2}}{\\partial y\\partial x} f{\\left(x,y,z \\right)} & \\frac{\\partial^{2}}{\\partial y^{2}} f{\\left(x,y,z \\right)} & \\frac{\\partial^{2}}{\\partial z\\partial y} f{\\left(x,y,z \\right)}\\\\\\frac{\\partial}{\\partial z} g{\\left(x,y,z \\right)} & x y \\cos{\\left(x y z \\right)} & \\frac{\\partial^{2}}{\\partial z\\partial x} f{\\left(x,y,z \\right)} & \\frac{\\partial^{2}}{\\partial z\\partial y} f{\\left(x,y,z \\right)} & \\frac{\\partial^{2}}{\\partial z^{2}} f{\\left(x,y,z \\right)}\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", "[ 0, 0, Derivative(g(x, y, z), x), Derivative(g(x, y, z), y), Derivative(g(x, y, z), z)],\n", "[ 0, 0, y*z*cos(x*y*z), x*z*cos(x*y*z), x*y*cos(x*y*z)],\n", "[Derivative(g(x, y, z), x), y*z*cos(x*y*z), Derivative(f(x, y, z), (x, 2)), Derivative(f(x, y, z), x, y), Derivative(f(x, y, z), x, z)],\n", "[Derivative(g(x, y, z), y), x*z*cos(x*y*z), Derivative(f(x, y, z), x, y), Derivative(f(x, y, z), (y, 2)), Derivative(f(x, y, z), y, z)],\n", "[Derivative(g(x, y, z), z), x*y*cos(x*y*z), Derivative(f(x, y, z), x, z), Derivative(f(x, y, z), y, z), Derivative(f(x, y, z), (z, 2))]])" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hessian(f,(x,y,z),[g1,g2])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" } }, "nbformat": 4, "nbformat_minor": 4 }
0076/528/76528856.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
{ "cells": [ { "cell_type": "markdown", "id": "f8cd47c7", "metadata": { "_cell_guid": "af4252ad-f822-45d3-b9c2-f26af7608ef4", "_uuid": "de34d146-4c69-4b7c-82f6-11d6287f6094", "execution": { "iopub.execute_input": "2021-10-07T06:47:44.152391Z", "iopub.status.busy": "2021-10-07T06:47:44.152048Z", "iopub.status.idle": "2021-10-07T06:47:44.18282Z", "shell.execute_reply": "2021-10-07T06:47:44.182194Z", "shell.execute_reply.started": "2021-10-07T06:47:44.152311Z" }, "jupyter": { "outputs_hidden": false }, "papermill": { "duration": 0.007756, "end_time": "2021-10-07T07:58:11.138368", "exception": false, "start_time": "2021-10-07T07:58:11.130612", "status": "completed" }, "tags": [] }, "source": [ "## 문제1\n", "- 데이터셋(basic1.csv)의 'f5' 컬럼을 기준으로 상위 10개의 데이터를 구하고,\n", "- 'f5'컬럼 10개 중 최소값으로 데이터를 대체한 후, \n", "- 'age'컬럼에서 80 이상인 데이터의'f5 컬럼 평균값 구하기" ] }, { "cell_type": "code", "execution_count": 1, "id": "eb7b7db1", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:11.164660Z", "iopub.status.busy": "2021-10-07T07:58:11.163756Z", "iopub.status.idle": "2021-10-07T07:58:11.167623Z", "shell.execute_reply": "2021-10-07T07:58:11.167021Z", "shell.execute_reply.started": "2021-10-07T07:48:20.293391Z" }, "papermill": { "duration": 0.020766, "end_time": "2021-10-07T07:58:11.167790", "exception": false, "start_time": "2021-10-07T07:58:11.147024", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# 라이브러리\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "id": "060280e8", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:11.185256Z", "iopub.status.busy": "2021-10-07T07:58:11.184650Z", "iopub.status.idle": "2021-10-07T07:58:11.240426Z", "shell.execute_reply": "2021-10-07T07:58:11.240960Z", "shell.execute_reply.started": "2021-10-07T07:48:20.578043Z" }, "papermill": { "duration": 0.066847, "end_time": "2021-10-07T07:58:11.241133", "exception": false, "start_time": "2021-10-07T07:58:11.174286", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>id</th>\n", " <th>age</th>\n", " <th>city</th>\n", " <th>f1</th>\n", " <th>f2</th>\n", " <th>f3</th>\n", " <th>f4</th>\n", " <th>f5</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>id01</td>\n", " <td>2.0</td>\n", " <td>서울</td>\n", " <td>NaN</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ENFJ</td>\n", " <td>91.297791</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>id02</td>\n", " <td>9.0</td>\n", " <td>서울</td>\n", " <td>70.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>ENFJ</td>\n", " <td>60.339826</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>id03</td>\n", " <td>27.0</td>\n", " <td>서울</td>\n", " <td>61.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>ISTJ</td>\n", " <td>17.252986</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>id04</td>\n", " <td>75.0</td>\n", " <td>서울</td>\n", " <td>NaN</td>\n", " <td>2</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>52.667078</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>id05</td>\n", " <td>24.0</td>\n", " <td>서울</td>\n", " <td>85.0</td>\n", " <td>2</td>\n", " <td>NaN</td>\n", " <td>ISFJ</td>\n", " <td>29.269869</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " id age city f1 f2 f3 f4 f5\n", "0 id01 2.0 서울 NaN 0 NaN ENFJ 91.297791\n", "1 id02 9.0 서울 70.0 1 NaN ENFJ 60.339826\n", "2 id03 27.0 서울 61.0 1 NaN ISTJ 17.252986\n", "3 id04 75.0 서울 NaN 2 NaN INFP 52.667078\n", "4 id05 24.0 서울 85.0 2 NaN ISFJ 29.269869" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 데이터 불러오기\n", "df = pd.read_csv('../input/bigdatacertificationkr/basic1.csv')\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 3, "id": "07da7f32", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:11.285160Z", "iopub.status.busy": "2021-10-07T07:58:11.268917Z", "iopub.status.idle": "2021-10-07T07:58:11.289062Z", "shell.execute_reply": "2021-10-07T07:58:11.289569Z", "shell.execute_reply.started": "2021-10-07T07:48:26.526653Z" }, "papermill": { "duration": 0.041263, "end_time": "2021-10-07T07:58:11.289781", "exception": false, "start_time": "2021-10-07T07:58:11.248518", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>id</th>\n", " <th>age</th>\n", " <th>city</th>\n", " <th>f1</th>\n", " <th>f2</th>\n", " <th>f3</th>\n", " <th>f4</th>\n", " <th>f5</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>10</th>\n", " <td>id11</td>\n", " <td>40.0</td>\n", " <td>서울</td>\n", " <td>68.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ENFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>97</th>\n", " <td>id98</td>\n", " <td>39.0</td>\n", " <td>경기</td>\n", " <td>58.0</td>\n", " <td>2</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>9</th>\n", " <td>id10</td>\n", " <td>95.0</td>\n", " <td>서울</td>\n", " <td>74.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>ISFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>76</th>\n", " <td>id77</td>\n", " <td>77.0</td>\n", " <td>경기</td>\n", " <td>31.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>98</th>\n", " <td>id99</td>\n", " <td>1.0</td>\n", " <td>경기</td>\n", " <td>47.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ESFJ</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>91</th>\n", " <td>id92</td>\n", " <td>97.0</td>\n", " <td>경기</td>\n", " <td>78.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>86</th>\n", " <td>id87</td>\n", " <td>19.0</td>\n", " <td>경기</td>\n", " <td>NaN</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>ISFP</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>71</th>\n", " <td>id72</td>\n", " <td>8.0</td>\n", " <td>경기</td>\n", " <td>97.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ESTJ</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>11</th>\n", " <td>id12</td>\n", " <td>20.0</td>\n", " <td>서울</td>\n", " <td>NaN</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ESTP</td>\n", " <td>91.297791</td>\n", " </tr>\n", " <tr>\n", " <th>19</th>\n", " <td>id20</td>\n", " <td>11.0</td>\n", " <td>서울</td>\n", " <td>51.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>INTJ</td>\n", " <td>91.297791</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " id age city f1 f2 f3 f4 f5\n", "10 id11 40.0 서울 68.0 0 NaN ENFP 98.429899\n", "97 id98 39.0 경기 58.0 2 NaN INFP 98.429899\n", "9 id10 95.0 서울 74.0 1 NaN ISFP 98.429899\n", "76 id77 77.0 경기 31.0 0 NaN INFP 98.429899\n", "98 id99 1.0 경기 47.0 0 NaN ESFJ 97.381034\n", "91 id92 97.0 경기 78.0 1 NaN INFP 97.381034\n", "86 id87 19.0 경기 NaN 1 NaN ISFP 97.381034\n", "71 id72 8.0 경기 97.0 0 NaN ESTJ 97.381034\n", "11 id12 20.0 서울 NaN 0 NaN ESTP 91.297791\n", "19 id20 11.0 서울 51.0 1 NaN INTJ 91.297791" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# f5컬럼을 기준으로 내림차순 정렬\n", "df = df.sort_values('f5', ascending=False)\n", "df.head(10)" ] }, { "cell_type": "code", "execution_count": 4, "id": "6eb3e173", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:11.332757Z", "iopub.status.busy": "2021-10-07T07:58:11.332069Z", "iopub.status.idle": "2021-10-07T07:58:11.339449Z", "shell.execute_reply": "2021-10-07T07:58:11.338680Z", "shell.execute_reply.started": "2021-10-07T07:49:06.481390Z" }, "papermill": { "duration": 0.041207, "end_time": "2021-10-07T07:58:11.339657", "exception": false, "start_time": "2021-10-07T07:58:11.298450", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>id</th>\n", " <th>age</th>\n", " <th>city</th>\n", " <th>f1</th>\n", " <th>f2</th>\n", " <th>f3</th>\n", " <th>f4</th>\n", " <th>f5</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>id11</td>\n", " <td>40.0</td>\n", " <td>서울</td>\n", " <td>68.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ENFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>id98</td>\n", " <td>39.0</td>\n", " <td>경기</td>\n", " <td>58.0</td>\n", " <td>2</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>id10</td>\n", " <td>95.0</td>\n", " <td>서울</td>\n", " <td>74.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>ISFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>id77</td>\n", " <td>77.0</td>\n", " <td>경기</td>\n", " <td>31.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>98.429899</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>id99</td>\n", " <td>1.0</td>\n", " <td>경기</td>\n", " <td>47.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ESFJ</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>5</th>\n", " <td>id92</td>\n", " <td>97.0</td>\n", " <td>경기</td>\n", " <td>78.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>INFP</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>6</th>\n", " <td>id87</td>\n", " <td>19.0</td>\n", " <td>경기</td>\n", " <td>NaN</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>ISFP</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>7</th>\n", " <td>id72</td>\n", " <td>8.0</td>\n", " <td>경기</td>\n", " <td>97.0</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ESTJ</td>\n", " <td>97.381034</td>\n", " </tr>\n", " <tr>\n", " <th>8</th>\n", " <td>id12</td>\n", " <td>20.0</td>\n", " <td>서울</td>\n", " <td>NaN</td>\n", " <td>0</td>\n", " <td>NaN</td>\n", " <td>ESTP</td>\n", " <td>91.297791</td>\n", " </tr>\n", " <tr>\n", " <th>9</th>\n", " <td>id20</td>\n", " <td>11.0</td>\n", " <td>서울</td>\n", " <td>51.0</td>\n", " <td>1</td>\n", " <td>NaN</td>\n", " <td>INTJ</td>\n", " <td>91.297791</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " id age city f1 f2 f3 f4 f5\n", "0 id11 40.0 서울 68.0 0 NaN ENFP 98.429899\n", "1 id98 39.0 경기 58.0 2 NaN INFP 98.429899\n", "2 id10 95.0 서울 74.0 1 NaN ISFP 98.429899\n", "3 id77 77.0 경기 31.0 0 NaN INFP 98.429899\n", "4 id99 1.0 경기 47.0 0 NaN ESFJ 97.381034\n", "5 id92 97.0 경기 78.0 1 NaN INFP 97.381034\n", "6 id87 19.0 경기 NaN 1 NaN ISFP 97.381034\n", "7 id72 8.0 경기 97.0 0 NaN ESTJ 97.381034\n", "8 id12 20.0 서울 NaN 0 NaN ESTP 91.297791\n", "9 id20 11.0 서울 51.0 1 NaN INTJ 91.297791" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 참고 - 인덱스 초기화\n", "df = df.reset_index(drop=True)\n", "df.head(10)" ] }, { "cell_type": "code", "execution_count": 5, "id": "7b024069", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:11.370039Z", "iopub.status.busy": "2021-10-07T07:58:11.366031Z", "iopub.status.idle": "2021-10-07T07:58:11.374498Z", "shell.execute_reply": "2021-10-07T07:58:11.373969Z", "shell.execute_reply.started": "2021-10-07T07:56:04.887174Z" }, "papermill": { "duration": 0.021698, "end_time": "2021-10-07T07:58:11.374667", "exception": false, "start_time": "2021-10-07T07:58:11.352969", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "91.29779092" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# 최소값 찾기\n", "min = df['f5'][:10].min()\n", "# min = 91.297791\n", "min" ] }, { "cell_type": "code", "execution_count": 6, "id": "0970494a", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:11.399396Z", "iopub.status.busy": "2021-10-07T07:58:11.398601Z", "iopub.status.idle": "2021-10-07T07:58:11.402277Z", "shell.execute_reply": "2021-10-07T07:58:11.402783Z", "shell.execute_reply.started": "2021-10-07T07:57:51.730517Z" }, "papermill": { "duration": 0.018661, "end_time": "2021-10-07T07:58:11.402945", "exception": false, "start_time": "2021-10-07T07:58:11.384284", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "63.07232761739131\n" ] } ], "source": [ "# 80세 이상의 f5컬럼 평균\n", "print(df[df['age']>=80]['f5'].mean())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" }, "papermill": { "default_parameters": {}, "duration": 8.541935, "end_time": "2021-10-07T07:58:11.921041", "environment_variables": {}, "exception": null, "input_path": "__notebook__.ipynb", "output_path": "__notebook__.ipynb", "parameters": {}, "start_time": "2021-10-07T07:58:03.379106", "version": "2.3.3" } }, "nbformat": 4, "nbformat_minor": 5 }
0076/528/76528885.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "992d5174", "metadata": { "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", "execution": { "iopub.execute_input": "2021-10-07T07:58:48.144085Z", "iopub.status.busy": "2021-10-07T07:58:48.142938Z", "iopub.status.idle": "2021-10-07T07:58:48.155267Z", "shell.execute_reply": "2021-10-07T07:58:48.155854Z", "shell.execute_reply.started": "2021-10-07T06:36:22.220383Z" }, "papermill": { "duration": 0.030253, "end_time": "2021-10-07T07:58:48.156199", "exception": false, "start_time": "2021-10-07T07:58:48.125946", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/kaggle/input/titanic/train.csv\n", "/kaggle/input/titanic/test.csv\n", "/kaggle/input/titanic/gender_submission.csv\n" ] } ], "source": [ "# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load\n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the read-only \"../input/\" directory\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n", "\n", "import os\n", "for dirname, _, filenames in os.walk('/kaggle/input'):\n", " for filename in filenames:\n", " print(os.path.join(dirname, filename))\n", "\n", "# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n", "# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session" ] }, { "cell_type": "code", "execution_count": 2, "id": "a013691a", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.184093Z", "iopub.status.busy": "2021-10-07T07:58:48.183464Z", "iopub.status.idle": "2021-10-07T07:58:48.205922Z", "shell.execute_reply": "2021-10-07T07:58:48.205306Z", "shell.execute_reply.started": "2021-10-07T06:36:22.256601Z" }, "papermill": { "duration": 0.037168, "end_time": "2021-10-07T07:58:48.206085", "exception": false, "start_time": "2021-10-07T07:58:48.168917", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "df_train = pd.read_csv(\"/kaggle/input/titanic/train.csv\")\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "ce94a037", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.241201Z", "iopub.status.busy": "2021-10-07T07:58:48.240530Z", "iopub.status.idle": "2021-10-07T07:58:48.268739Z", "shell.execute_reply": "2021-10-07T07:58:48.269247Z", "shell.execute_reply.started": "2021-10-07T06:36:22.281072Z" }, "papermill": { "duration": 0.050652, "end_time": "2021-10-07T07:58:48.269418", "exception": false, "start_time": "2021-10-07T07:58:48.218766", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>PassengerId</th>\n", " <th>Survived</th>\n", " <th>Pclass</th>\n", " <th>Name</th>\n", " <th>Sex</th>\n", " <th>Age</th>\n", " <th>SibSp</th>\n", " <th>Parch</th>\n", " <th>Ticket</th>\n", " <th>Fare</th>\n", " <th>Cabin</th>\n", " <th>Embarked</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>1</td>\n", " <td>0</td>\n", " <td>3</td>\n", " <td>Braund, Mr. Owen Harris</td>\n", " <td>male</td>\n", " <td>22.0</td>\n", " <td>1</td>\n", " <td>0</td>\n", " <td>A/5 21171</td>\n", " <td>7.2500</td>\n", " <td>NaN</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>2</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n", " <td>female</td>\n", " <td>38.0</td>\n", " <td>1</td>\n", " <td>0</td>\n", " <td>PC 17599</td>\n", " <td>71.2833</td>\n", " <td>C85</td>\n", " <td>C</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>3</td>\n", " <td>1</td>\n", " <td>3</td>\n", " <td>Heikkinen, Miss. Laina</td>\n", " <td>female</td>\n", " <td>26.0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>STON/O2. 3101282</td>\n", " <td>7.9250</td>\n", " <td>NaN</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>4</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n", " <td>female</td>\n", " <td>35.0</td>\n", " <td>1</td>\n", " <td>0</td>\n", " <td>113803</td>\n", " <td>53.1000</td>\n", " <td>C123</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>5</td>\n", " <td>0</td>\n", " <td>3</td>\n", " <td>Allen, Mr. William Henry</td>\n", " <td>male</td>\n", " <td>35.0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>373450</td>\n", " <td>8.0500</td>\n", " <td>NaN</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>...</th>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " <td>...</td>\n", " </tr>\n", " <tr>\n", " <th>886</th>\n", " <td>887</td>\n", " <td>0</td>\n", " <td>2</td>\n", " <td>Montvila, Rev. Juozas</td>\n", " <td>male</td>\n", " <td>27.0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>211536</td>\n", " <td>13.0000</td>\n", " <td>NaN</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>887</th>\n", " <td>888</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>Graham, Miss. Margaret Edith</td>\n", " <td>female</td>\n", " <td>19.0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>112053</td>\n", " <td>30.0000</td>\n", " <td>B42</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>888</th>\n", " <td>889</td>\n", " <td>0</td>\n", " <td>3</td>\n", " <td>Johnston, Miss. Catherine Helen \"Carrie\"</td>\n", " <td>female</td>\n", " <td>NaN</td>\n", " <td>1</td>\n", " <td>2</td>\n", " <td>W./C. 6607</td>\n", " <td>23.4500</td>\n", " <td>NaN</td>\n", " <td>S</td>\n", " </tr>\n", " <tr>\n", " <th>889</th>\n", " <td>890</td>\n", " <td>1</td>\n", " <td>1</td>\n", " <td>Behr, Mr. Karl Howell</td>\n", " <td>male</td>\n", " <td>26.0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>111369</td>\n", " <td>30.0000</td>\n", " <td>C148</td>\n", " <td>C</td>\n", " </tr>\n", " <tr>\n", " <th>890</th>\n", " <td>891</td>\n", " <td>0</td>\n", " <td>3</td>\n", " <td>Dooley, Mr. Patrick</td>\n", " <td>male</td>\n", " <td>32.0</td>\n", " <td>0</td>\n", " <td>0</td>\n", " <td>370376</td>\n", " <td>7.7500</td>\n", " <td>NaN</td>\n", " <td>Q</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "<p>891 rows × 12 columns</p>\n", "</div>" ], "text/plain": [ " PassengerId Survived Pclass \\\n", "0 1 0 3 \n", "1 2 1 1 \n", "2 3 1 3 \n", "3 4 1 1 \n", "4 5 0 3 \n", ".. ... ... ... \n", "886 887 0 2 \n", "887 888 1 1 \n", "888 889 0 3 \n", "889 890 1 1 \n", "890 891 0 3 \n", "\n", " Name Sex Age SibSp \\\n", "0 Braund, Mr. Owen Harris male 22.0 1 \n", "1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n", "2 Heikkinen, Miss. Laina female 26.0 0 \n", "3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n", "4 Allen, Mr. William Henry male 35.0 0 \n", ".. ... ... ... ... \n", "886 Montvila, Rev. Juozas male 27.0 0 \n", "887 Graham, Miss. Margaret Edith female 19.0 0 \n", "888 Johnston, Miss. Catherine Helen \"Carrie\" female NaN 1 \n", "889 Behr, Mr. Karl Howell male 26.0 0 \n", "890 Dooley, Mr. Patrick male 32.0 0 \n", "\n", " Parch Ticket Fare Cabin Embarked \n", "0 0 A/5 21171 7.2500 NaN S \n", "1 0 PC 17599 71.2833 C85 C \n", "2 0 STON/O2. 3101282 7.9250 NaN S \n", "3 0 113803 53.1000 C123 S \n", "4 0 373450 8.0500 NaN S \n", ".. ... ... ... ... ... \n", "886 0 211536 13.0000 NaN S \n", "887 0 112053 30.0000 B42 S \n", "888 2 W./C. 6607 23.4500 NaN S \n", "889 0 111369 30.0000 C148 C \n", "890 0 370376 7.7500 NaN Q \n", "\n", "[891 rows x 12 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_train" ] }, { "cell_type": "code", "execution_count": 4, "id": "a3bc3dd3", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.300309Z", "iopub.status.busy": "2021-10-07T07:58:48.299569Z", "iopub.status.idle": "2021-10-07T07:58:48.302850Z", "shell.execute_reply": "2021-10-07T07:58:48.302307Z", "shell.execute_reply.started": "2021-10-07T06:36:29.200469Z" }, "papermill": { "duration": 0.020884, "end_time": "2021-10-07T07:58:48.303032", "exception": false, "start_time": "2021-10-07T07:58:48.282148", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "df = df_train.copy()" ] }, { "cell_type": "code", "execution_count": 5, "id": "aec94879", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.333294Z", "iopub.status.busy": "2021-10-07T07:58:48.332605Z", "iopub.status.idle": "2021-10-07T07:58:48.342745Z", "shell.execute_reply": "2021-10-07T07:58:48.342285Z", "shell.execute_reply.started": "2021-10-07T06:42:34.423009Z" }, "papermill": { "duration": 0.027154, "end_time": "2021-10-07T07:58:48.342922", "exception": false, "start_time": "2021-10-07T07:58:48.315768", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "30.62617924528302\n" ] } ], "source": [ "## 1.\tKazada ölenlerin yaş ortalamasını bulunuz\n", "average_age = df.loc[df[\"Survived\"] == 0][\"Age\"].mean()\n", "print(average_age)" ] }, { "cell_type": "code", "execution_count": 6, "id": "1996097e", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.373829Z", "iopub.status.busy": "2021-10-07T07:58:48.373231Z", "iopub.status.idle": "2021-10-07T07:58:48.383106Z", "shell.execute_reply": "2021-10-07T07:58:48.382590Z", "shell.execute_reply.started": "2021-10-07T06:39:18.856226Z" }, "papermill": { "duration": 0.026533, "end_time": "2021-10-07T07:58:48.383266", "exception": false, "start_time": "2021-10-07T07:58:48.356733", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "34.94558161648169 13.5\n" ] } ], "source": [ "## 2.\tKazada ölenlerin bilet fiyatlarının ortalamasını ve medyanını bulunuz\n", "average_fare = df.loc[df[\"Age\"] > 15][\"Fare\"].mean()\n", "median_fare = df.loc[df[\"Age\"] > 15][\"Fare\"].median() \n", "print(average_fare, median_fare)" ] }, { "cell_type": "code", "execution_count": 7, "id": "bd9e29ad", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.416892Z", "iopub.status.busy": "2021-10-07T07:58:48.416170Z", "iopub.status.idle": "2021-10-07T07:58:48.420651Z", "shell.execute_reply": "2021-10-07T07:58:48.421162Z", "shell.execute_reply.started": "2021-10-07T06:43:08.820288Z" }, "papermill": { "duration": 0.024792, "end_time": "2021-10-07T07:58:48.421346", "exception": false, "start_time": "2021-10-07T07:58:48.396554", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "31.618055555555557\n" ] } ], "source": [ "## 3.\tKazada ölen erkeklerin yaş ortalamasını bulunuz\n", "average_male_age = df.loc[(df[\"Sex\"] == \"male\") & (df[\"Survived\"] == 0)][\"Age\"].mean()\n", "print(average_male_age)" ] }, { "cell_type": "code", "execution_count": 8, "id": "c6c6796c", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.455733Z", "iopub.status.busy": "2021-10-07T07:58:48.451560Z", "iopub.status.idle": "2021-10-07T07:58:48.458366Z", "shell.execute_reply": "2021-10-07T07:58:48.459001Z", "shell.execute_reply.started": "2021-10-07T06:43:33.760068Z" }, "papermill": { "duration": 0.02398, "end_time": "2021-10-07T07:58:48.459173", "exception": false, "start_time": "2021-10-07T07:58:48.435193", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "25.046875\n" ] } ], "source": [ "## 4.\tKazada ölen Kadınların yaş ortalamasını bulunuz\n", "average_female_age = df.loc[(df[\"Sex\"] == \"female\") & (df[\"Survived\"] == 0)][\"Age\"].mean()\n", "print(average_female_age)\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "db1e517f", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.492218Z", "iopub.status.busy": "2021-10-07T07:58:48.491578Z", "iopub.status.idle": "2021-10-07T07:58:48.498319Z", "shell.execute_reply": "2021-10-07T07:58:48.498792Z", "shell.execute_reply.started": "2021-10-07T06:44:27.494586Z" }, "papermill": { "duration": 0.02491, "end_time": "2021-10-07T07:58:48.498994", "exception": false, "start_time": "2021-10-07T07:58:48.474084", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "28.343689655172415\n" ] } ], "source": [ "## 5.\tKazadan kurtulanların yaş ortalamasını bulunuz\n", "average_age = df.loc[df[\"Survived\"] == 1][\"Age\"].mean()\n", "print(average_age)" ] }, { "cell_type": "code", "execution_count": 10, "id": "2081a228", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.536232Z", "iopub.status.busy": "2021-10-07T07:58:48.535299Z", "iopub.status.idle": "2021-10-07T07:58:48.539378Z", "shell.execute_reply": "2021-10-07T07:58:48.540597Z", "shell.execute_reply.started": "2021-10-07T06:45:42.479088Z" }, "papermill": { "duration": 0.026039, "end_time": "2021-10-07T07:58:48.540829", "exception": false, "start_time": "2021-10-07T07:58:48.514790", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "48.39540760233917\n" ] } ], "source": [ "## 6.\tKazadan kurtulanların bilet fiyatlarının ortalamasını bulunuz\n", "average_fare_srv = df.loc[df[\"Survived\"]==1][\"Fare\"].mean()\n", "print(average_fare_srv)" ] }, { "cell_type": "code", "execution_count": 11, "id": "a4e66451", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.573240Z", "iopub.status.busy": "2021-10-07T07:58:48.572598Z", "iopub.status.idle": "2021-10-07T07:58:48.579967Z", "shell.execute_reply": "2021-10-07T07:58:48.579454Z", "shell.execute_reply.started": "2021-10-07T06:48:36.828598Z" }, "papermill": { "duration": 0.024846, "end_time": "2021-10-07T07:58:48.580107", "exception": false, "start_time": "2021-10-07T07:58:48.555261", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "342\n" ] } ], "source": [ "## 7.\tKazadan kurtulan toplam kişi sayısını bulunuz… \n", "survived = len(df.loc[df[\"Survived\"]==1])\n", "print(survived)" ] }, { "cell_type": "code", "execution_count": 12, "id": "dcca28d6", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.617812Z", "iopub.status.busy": "2021-10-07T07:58:48.616278Z", "iopub.status.idle": "2021-10-07T07:58:48.621082Z", "shell.execute_reply": "2021-10-07T07:58:48.621493Z", "shell.execute_reply.started": "2021-10-07T06:49:41.264858Z" }, "papermill": { "duration": 0.026527, "end_time": "2021-10-07T07:58:48.621662", "exception": false, "start_time": "2021-10-07T07:58:48.595135", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "13.92915\n" ] } ], "source": [ "## 8.\t10 yaşından küçüklerin bilet fiyatlarının medyan değerini bulunuz\n", "\n", "blw_ten = df.loc[df[\"Age\"] > 10][\"Fare\"].median()\n", "print(blw_ten)" ] }, { "cell_type": "code", "execution_count": 13, "id": "7dd8bace", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.663355Z", "iopub.status.busy": "2021-10-07T07:58:48.662132Z", "iopub.status.idle": "2021-10-07T07:58:48.672707Z", "shell.execute_reply": "2021-10-07T07:58:48.671961Z", "shell.execute_reply.started": "2021-10-07T06:54:52.961382Z" }, "papermill": { "duration": 0.035896, "end_time": "2021-10-07T07:58:48.672924", "exception": false, "start_time": "2021-10-07T07:58:48.637028", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pclass\n", "1 84.154687\n", "2 20.662183\n", "3 13.675550\n", "Name: Fare, dtype: float64 Pclass\n", "1 60.2875\n", "2 14.2500\n", "3 8.0500\n", "Name: Fare, dtype: float64\n" ] } ], "source": [ "## 9.\t1.sınıf, 2.sınıf ve 3.sınıf bilet fiyatlarının ortalama ve medyanlarını karşılaştırınız.\n", "\n", "price_comp_mean = df.groupby(\"Pclass\")[\"Fare\"].mean()\n", "price_comp_median = df.groupby(\"Pclass\")[\"Fare\"].median()\n", "\n", "print(price_comp_mean, price_comp_median)" ] }, { "cell_type": "code", "execution_count": 14, "id": "ae45bb6d", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.717774Z", "iopub.status.busy": "2021-10-07T07:58:48.716844Z", "iopub.status.idle": "2021-10-07T07:58:48.720813Z", "shell.execute_reply": "2021-10-07T07:58:48.721521Z", "shell.execute_reply.started": "2021-10-07T07:56:11.857142Z" }, "papermill": { "duration": 0.031719, "end_time": "2021-10-07T07:58:48.721751", "exception": false, "start_time": "2021-10-07T07:58:48.690032", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Sex\n", "female 0.257962\n", "male 0.811092\n", "Name: Survived, dtype: float64\n" ] } ], "source": [ "## 10.\tKazada ölen kadınların oranı ile erkeklerin oranını karşılaştırınız. \n", "## (Örnek: erkekler için; ölen erkeklerin, erkek sayısına bölümü bu oranı vermektetedir.\n", "\n", "death_by_sex = 1- df.groupby(\"Sex\")[\"Survived\"].mean()\n", "print(death_by_sex)" ] }, { "cell_type": "code", "execution_count": 15, "id": "5d5b0ef0", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.773133Z", "iopub.status.busy": "2021-10-07T07:58:48.772177Z", "iopub.status.idle": "2021-10-07T07:58:48.776746Z", "shell.execute_reply": "2021-10-07T07:58:48.776258Z", "shell.execute_reply.started": "2021-10-07T07:46:49.623765Z" }, "papermill": { "duration": 0.037604, "end_time": "2021-10-07T07:58:48.776909", "exception": false, "start_time": "2021-10-07T07:58:48.739305", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "<div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>PassengerId</th>\n", " <th>Survived</th>\n", " <th>Pclass</th>\n", " <th>Age</th>\n", " <th>SibSp</th>\n", " <th>Parch</th>\n", " <th>Fare</th>\n", " </tr>\n", " <tr>\n", " <th>Sex</th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " <th></th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>female</th>\n", " <td>429.699571</td>\n", " <td>1.0</td>\n", " <td>1.918455</td>\n", " <td>28.847716</td>\n", " <td>0.515021</td>\n", " <td>0.515021</td>\n", " <td>51.938573</td>\n", " </tr>\n", " <tr>\n", " <th>male</th>\n", " <td>475.724771</td>\n", " <td>1.0</td>\n", " <td>2.018349</td>\n", " <td>27.276022</td>\n", " <td>0.385321</td>\n", " <td>0.357798</td>\n", " <td>40.821484</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>" ], "text/plain": [ " PassengerId Survived Pclass Age SibSp Parch \\\n", "Sex \n", "female 429.699571 1.0 1.918455 28.847716 0.515021 0.515021 \n", "male 475.724771 1.0 2.018349 27.276022 0.385321 0.357798 \n", "\n", " Fare \n", "Sex \n", "female 51.938573 \n", "male 40.821484 " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[df[\"Survived\"] == 1].groupby(\"Sex\").mean()" ] }, { "cell_type": "code", "execution_count": 16, "id": "842053dd", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.819913Z", "iopub.status.busy": "2021-10-07T07:58:48.819243Z", "iopub.status.idle": "2021-10-07T07:58:48.831051Z", "shell.execute_reply": "2021-10-07T07:58:48.831904Z", "shell.execute_reply.started": "2021-10-07T07:08:35.813180Z" }, "papermill": { "duration": 0.038979, "end_time": "2021-10-07T07:58:48.832147", "exception": false, "start_time": "2021-10-07T07:58:48.793168", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "Sex Survived\n", "female 1 233\n", " 0 81\n", "male 0 468\n", " 1 109\n", "Name: Survived, dtype: int64" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.groupby(\"Sex\")[\"Survived\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 17, "id": "248a2f4f", "metadata": { "execution": { "iopub.execute_input": "2021-10-07T07:58:48.882217Z", "iopub.status.busy": "2021-10-07T07:58:48.881283Z", "iopub.status.idle": "2021-10-07T07:58:48.886753Z", "shell.execute_reply": "2021-10-07T07:58:48.887281Z", "shell.execute_reply.started": "2021-10-07T07:36:41.021739Z" }, "papermill": { "duration": 0.029773, "end_time": "2021-10-07T07:58:48.887447", "exception": false, "start_time": "2021-10-07T07:58:48.857674", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "0.18890814558058924" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "109 / (109+468)" ] }, { "cell_type": "code", "execution_count": null, "id": "8917fd2b", "metadata": { "papermill": { "duration": 0.015704, "end_time": "2021-10-07T07:58:48.918949", "exception": false, "start_time": "2021-10-07T07:58:48.903245", "status": "completed" }, "tags": [] }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" }, "papermill": { "default_parameters": {}, "duration": 9.78779, "end_time": "2021-10-07T07:58:50.231709", "environment_variables": {}, "exception": null, "input_path": "__notebook__.ipynb", "output_path": "__notebook__.ipynb", "parameters": {}, "start_time": "2021-10-07T07:58:40.443919", "version": "2.3.3" } }, "nbformat": 4, "nbformat_minor": 5 }
0076/528/76528925.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"id\": \"797036(...TRUNCATED)
0076/528/76528930.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"id\": \"18085b(...TRUNCATED)
0076/529/76529224.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"id\": \"0c128a(...TRUNCATED)
0076/530/76530551.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\"metadata\":{\"kernelspec\":{\"language\":\"python\",\"display_name\":\"Python 3\",\"name\":\"pyt(...TRUNCATED)
0076/530/76530917.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\"metadata\":{\"kernelspec\":{\"language\":\"python\",\"display_name\":\"Python 3\",\"name\":\"pyt(...TRUNCATED)
0076/531/76531099.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\n \"cells\": [\n {\n \"cell_type\": \"code\",\n \"execution_count\": 1,\n \"id\": \"a34438(...TRUNCATED)
0076/531/76531303.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
"{\"metadata\":{\"kernelspec\":{\"language\":\"python\",\"display_name\":\"Python 3\",\"name\":\"pyt(...TRUNCATED)
0076/531/76531383.ipynb
s3://data-agents/kaggle-outputs/sharded/018_00076.jsonl.gz
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
26