Created
August 5, 2019 04:41
-
-
Save taruma/d9ee843e8553477f5a0ad972404b1ca7 to your computer and use it in GitHub Desktop.
taruma_PI_126907.ipynb
This file contains 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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "taruma_PI_126907.ipynb", | |
"version": "0.3.2", | |
"provenance": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/taruma/d9ee843e8553477f5a0ad972404b1ca7/taruma_pi_126907.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "8x0AtGCVE-lb", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"berdasarkan: https://t.me/pythonID/126907" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "w7CteKIxD2DY", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 204 | |
}, | |
"outputId": "0c4ced7b-3e31-4e11-9c24-b514d5f8c922" | |
}, | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"\n", | |
"columns_name = 'puji alam sayang maha nama tuhan semesta murah'.split()\n", | |
"X = pd.DataFrame(\n", | |
" columns=columns_name,\n", | |
" data=np.random.rand(100, len(columns_name))\n", | |
")\n", | |
"\n", | |
"X.head()" | |
], | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"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>puji</th>\n", | |
" <th>alam</th>\n", | |
" <th>sayang</th>\n", | |
" <th>maha</th>\n", | |
" <th>nama</th>\n", | |
" <th>tuhan</th>\n", | |
" <th>semesta</th>\n", | |
" <th>murah</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>0.841253</td>\n", | |
" <td>0.200102</td>\n", | |
" <td>0.494680</td>\n", | |
" <td>0.128288</td>\n", | |
" <td>0.814720</td>\n", | |
" <td>0.658413</td>\n", | |
" <td>0.135724</td>\n", | |
" <td>0.931693</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>0.116108</td>\n", | |
" <td>0.145618</td>\n", | |
" <td>0.925706</td>\n", | |
" <td>0.479615</td>\n", | |
" <td>0.978343</td>\n", | |
" <td>0.055701</td>\n", | |
" <td>0.838612</td>\n", | |
" <td>0.923255</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>0.999052</td>\n", | |
" <td>0.267923</td>\n", | |
" <td>0.348844</td>\n", | |
" <td>0.609648</td>\n", | |
" <td>0.388583</td>\n", | |
" <td>0.978295</td>\n", | |
" <td>0.084873</td>\n", | |
" <td>0.369663</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>0.919730</td>\n", | |
" <td>0.161474</td>\n", | |
" <td>0.135100</td>\n", | |
" <td>0.995756</td>\n", | |
" <td>0.825695</td>\n", | |
" <td>0.436864</td>\n", | |
" <td>0.737513</td>\n", | |
" <td>0.272068</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>0.669651</td>\n", | |
" <td>0.591095</td>\n", | |
" <td>0.171624</td>\n", | |
" <td>0.917126</td>\n", | |
" <td>0.764302</td>\n", | |
" <td>0.686185</td>\n", | |
" <td>0.486569</td>\n", | |
" <td>0.255821</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" puji alam sayang ... tuhan semesta murah\n", | |
"0 0.841253 0.200102 0.494680 ... 0.658413 0.135724 0.931693\n", | |
"1 0.116108 0.145618 0.925706 ... 0.055701 0.838612 0.923255\n", | |
"2 0.999052 0.267923 0.348844 ... 0.978295 0.084873 0.369663\n", | |
"3 0.919730 0.161474 0.135100 ... 0.436864 0.737513 0.272068\n", | |
"4 0.669651 0.591095 0.171624 ... 0.686185 0.486569 0.255821\n", | |
"\n", | |
"[5 rows x 8 columns]" | |
] | |
}, | |
"metadata": { | |
"tags": [] | |
}, | |
"execution_count": 11 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "FQp2WKoyD4BR", | |
"colab_type": "code", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 884 | |
}, | |
"outputId": "198f13fa-d728-4a3e-c7b4-7579305bc06c" | |
}, | |
"source": [ | |
"from scipy import sparse\n", | |
"matrix_sparse = sparse.csr_matrix(X.values)\n", | |
"print(matrix_sparse)" | |
], | |
"execution_count": 10, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
" (0, 0)\t0.4152583895652301\n", | |
" (0, 1)\t0.483934313883452\n", | |
" (0, 2)\t0.629866878814283\n", | |
" (0, 3)\t0.6718100601516879\n", | |
" (0, 4)\t0.7922897726821555\n", | |
" (0, 5)\t0.17373046813031368\n", | |
" (0, 6)\t0.5913104644196245\n", | |
" (0, 7)\t0.9794258267599093\n", | |
" (1, 0)\t0.6298729378859312\n", | |
" (1, 1)\t0.7018833833528486\n", | |
" (1, 2)\t0.8597220515001217\n", | |
" (1, 3)\t0.5917449218594172\n", | |
" (1, 4)\t0.4399350429776686\n", | |
" (1, 5)\t0.8982016406327463\n", | |
" (1, 6)\t0.5511021490333579\n", | |
" (1, 7)\t0.19016069521900203\n", | |
" (2, 0)\t0.9544452178004732\n", | |
" (2, 1)\t0.9146469688761368\n", | |
" (2, 2)\t0.9166962483876098\n", | |
" (2, 3)\t0.8633954466855117\n", | |
" (2, 4)\t0.5124110651801803\n", | |
" (2, 5)\t0.7683833769452809\n", | |
" (2, 6)\t0.5643979727509826\n", | |
" (2, 7)\t0.29945883357827086\n", | |
" (3, 0)\t0.8383820779782111\n", | |
" :\t:\n", | |
" (96, 7)\t0.2668444220767342\n", | |
" (97, 0)\t0.9490211834203077\n", | |
" (97, 1)\t0.3988238426771983\n", | |
" (97, 2)\t0.5989677188151593\n", | |
" (97, 3)\t0.28143920687125246\n", | |
" (97, 4)\t0.3014851114175028\n", | |
" (97, 5)\t0.8839194551706707\n", | |
" (97, 6)\t0.9201167289874009\n", | |
" (97, 7)\t0.7383299615850075\n", | |
" (98, 0)\t0.4905722582840186\n", | |
" (98, 1)\t0.7514363141452598\n", | |
" (98, 2)\t0.4398341566128843\n", | |
" (98, 3)\t0.8964035281237029\n", | |
" (98, 4)\t0.5021449652649039\n", | |
" (98, 5)\t0.5689631120134958\n", | |
" (98, 6)\t0.8695199103376536\n", | |
" (98, 7)\t0.48533512977763205\n", | |
" (99, 0)\t0.16408114559593467\n", | |
" (99, 1)\t0.9995355769075824\n", | |
" (99, 2)\t0.724864696924347\n", | |
" (99, 3)\t0.7549029908207381\n", | |
" (99, 4)\t0.6572112957920095\n", | |
" (99, 5)\t0.8788837911771098\n", | |
" (99, 6)\t0.2757142180438097\n", | |
" (99, 7)\t0.9215395254053284\n" | |
], | |
"name": "stdout" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment