{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from sklearn.preprocessing import MinMaxScaler" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "data = np.random.randint(0,100,(10,2))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[53, 52],\n", " [82, 96],\n", " [60, 84],\n", " [15, 90],\n", " [78, 31],\n", " [ 5, 12],\n", " [32, 75],\n", " [80, 39],\n", " [31, 46],\n", " [22, 29]])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "scaler_model = MinMaxScaler()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "sklearn.preprocessing._data.MinMaxScaler" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(scaler_model)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "MinMaxScaler(copy=True, feature_range=(0, 1))" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scaler_model.fit(data)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.62337662, 0.47619048],\n", " [1. , 1. ],\n", " [0.71428571, 0.85714286],\n", " [0.12987013, 0.92857143],\n", " [0.94805195, 0.22619048],\n", " [0. , 0. ],\n", " [0.35064935, 0.75 ],\n", " [0.97402597, 0.32142857],\n", " [0.33766234, 0.4047619 ],\n", " [0.22077922, 0.20238095]])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scaler_model.transform(data)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[0.62337662, 0.47619048],\n", " [1. , 1. ],\n", " [0.71428571, 0.85714286],\n", " [0.12987013, 0.92857143],\n", " [0.94805195, 0.22619048],\n", " [0. , 0. ],\n", " [0.35064935, 0.75 ],\n", " [0.97402597, 0.32142857],\n", " [0.33766234, 0.4047619 ],\n", " [0.22077922, 0.20238095]])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "scaler_model.fit_transform(data)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/eddie/.pyenv/versions/3.7.3/envs/tensorflow-1.14/lib/python3.7/site-packages/pandas/compat/__init__.py:117: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.\n", " warnings.warn(msg)\n" ] } ], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "mydata = np.random.randint(0,101,(50,4))" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 97, 70, 23, 81],\n", " [ 60, 40, 73, 7],\n", " [ 60, 88, 87, 67],\n", " [ 42, 25, 81, 100],\n", " [ 45, 30, 69, 72],\n", " [ 16, 100, 70, 14],\n", " [ 25, 76, 32, 70],\n", " [ 2, 29, 46, 65],\n", " [ 71, 33, 11, 79],\n", " [ 98, 16, 76, 9],\n", " [ 0, 78, 61, 34],\n", " [ 78, 43, 45, 87],\n", " [ 95, 78, 6, 34],\n", " [ 14, 44, 95, 27],\n", " [ 32, 31, 90, 58],\n", " [ 72, 15, 16, 59],\n", " [ 5, 72, 31, 36],\n", " [ 72, 30, 94, 55],\n", " [ 55, 19, 91, 74],\n", " [ 9, 20, 10, 34],\n", " [ 3, 6, 25, 49],\n", " [ 63, 61, 86, 55],\n", " [ 25, 21, 0, 85],\n", " [ 80, 66, 73, 51],\n", " [ 96, 46, 35, 58],\n", " [ 7, 4, 89, 25],\n", " [ 92, 11, 77, 59],\n", " [ 38, 94, 19, 46],\n", " [ 34, 24, 94, 70],\n", " [100, 91, 46, 76],\n", " [ 43, 10, 35, 78],\n", " [ 15, 24, 57, 6],\n", " [ 51, 47, 47, 55],\n", " [ 83, 5, 84, 40],\n", " [100, 22, 26, 72],\n", " [ 60, 83, 80, 92],\n", " [ 28, 39, 82, 17],\n", " [ 56, 20, 94, 85],\n", " [ 72, 56, 63, 54],\n", " [ 15, 60, 30, 72],\n", " [ 41, 21, 86, 54],\n", " [ 85, 7, 50, 87],\n", " [ 48, 13, 69, 93],\n", " [ 75, 20, 98, 96],\n", " [ 41, 18, 14, 31],\n", " [ 84, 13, 62, 6],\n", " [ 13, 40, 77, 60],\n", " [ 70, 18, 84, 26],\n", " [ 97, 22, 24, 34],\n", " [ 56, 83, 9, 95]])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mydata" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data=mydata, columns = ['f1','f2','f3','label'])" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
f1f2f3label
097702381
16040737
260888767
3422581100
445306972
5161007014
625763270
72294665
871331179
99816769
100786134
1178434587
129578634
1314449527
1432319058
1572151659
165723136
1772309455
1855199174
199201034
20362549
2163618655
222521085
2380667351
2496463558
25748925
2692117759
2738941946
2834249470
29100914676
3043103578
311524576
3251474755
338358440
34100222672
3560838092
3628398217
3756209485
3872566354
3915603072
4041218654
418575087
4248136993
4375209896
4441181431
458413626
4613407760
4770188426
4897222434
495683995
\n", "
" ], "text/plain": [ " f1 f2 f3 label\n", "0 97 70 23 81\n", "1 60 40 73 7\n", "2 60 88 87 67\n", "3 42 25 81 100\n", "4 45 30 69 72\n", "5 16 100 70 14\n", "6 25 76 32 70\n", "7 2 29 46 65\n", "8 71 33 11 79\n", "9 98 16 76 9\n", "10 0 78 61 34\n", "11 78 43 45 87\n", "12 95 78 6 34\n", "13 14 44 95 27\n", "14 32 31 90 58\n", "15 72 15 16 59\n", "16 5 72 31 36\n", "17 72 30 94 55\n", "18 55 19 91 74\n", "19 9 20 10 34\n", "20 3 6 25 49\n", "21 63 61 86 55\n", "22 25 21 0 85\n", "23 80 66 73 51\n", "24 96 46 35 58\n", "25 7 4 89 25\n", "26 92 11 77 59\n", "27 38 94 19 46\n", "28 34 24 94 70\n", "29 100 91 46 76\n", "30 43 10 35 78\n", "31 15 24 57 6\n", "32 51 47 47 55\n", "33 83 5 84 40\n", "34 100 22 26 72\n", "35 60 83 80 92\n", "36 28 39 82 17\n", "37 56 20 94 85\n", "38 72 56 63 54\n", "39 15 60 30 72\n", "40 41 21 86 54\n", "41 85 7 50 87\n", "42 48 13 69 93\n", "43 75 20 98 96\n", "44 41 18 14 31\n", "45 84 13 62 6\n", "46 13 40 77 60\n", "47 70 18 84 26\n", "48 97 22 24 34\n", "49 56 83 9 95" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "X = df[['f1','f2','f3']]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "y = df['label']" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(33, 3)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X_train.shape" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(17, 3)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "X_test.shape" ] }, { "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.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }