{ "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", " | f1 | \n", "f2 | \n", "f3 | \n", "label | \n", "
---|---|---|---|---|
0 | \n", "97 | \n", "70 | \n", "23 | \n", "81 | \n", "
1 | \n", "60 | \n", "40 | \n", "73 | \n", "7 | \n", "
2 | \n", "60 | \n", "88 | \n", "87 | \n", "67 | \n", "
3 | \n", "42 | \n", "25 | \n", "81 | \n", "100 | \n", "
4 | \n", "45 | \n", "30 | \n", "69 | \n", "72 | \n", "
5 | \n", "16 | \n", "100 | \n", "70 | \n", "14 | \n", "
6 | \n", "25 | \n", "76 | \n", "32 | \n", "70 | \n", "
7 | \n", "2 | \n", "29 | \n", "46 | \n", "65 | \n", "
8 | \n", "71 | \n", "33 | \n", "11 | \n", "79 | \n", "
9 | \n", "98 | \n", "16 | \n", "76 | \n", "9 | \n", "
10 | \n", "0 | \n", "78 | \n", "61 | \n", "34 | \n", "
11 | \n", "78 | \n", "43 | \n", "45 | \n", "87 | \n", "
12 | \n", "95 | \n", "78 | \n", "6 | \n", "34 | \n", "
13 | \n", "14 | \n", "44 | \n", "95 | \n", "27 | \n", "
14 | \n", "32 | \n", "31 | \n", "90 | \n", "58 | \n", "
15 | \n", "72 | \n", "15 | \n", "16 | \n", "59 | \n", "
16 | \n", "5 | \n", "72 | \n", "31 | \n", "36 | \n", "
17 | \n", "72 | \n", "30 | \n", "94 | \n", "55 | \n", "
18 | \n", "55 | \n", "19 | \n", "91 | \n", "74 | \n", "
19 | \n", "9 | \n", "20 | \n", "10 | \n", "34 | \n", "
20 | \n", "3 | \n", "6 | \n", "25 | \n", "49 | \n", "
21 | \n", "63 | \n", "61 | \n", "86 | \n", "55 | \n", "
22 | \n", "25 | \n", "21 | \n", "0 | \n", "85 | \n", "
23 | \n", "80 | \n", "66 | \n", "73 | \n", "51 | \n", "
24 | \n", "96 | \n", "46 | \n", "35 | \n", "58 | \n", "
25 | \n", "7 | \n", "4 | \n", "89 | \n", "25 | \n", "
26 | \n", "92 | \n", "11 | \n", "77 | \n", "59 | \n", "
27 | \n", "38 | \n", "94 | \n", "19 | \n", "46 | \n", "
28 | \n", "34 | \n", "24 | \n", "94 | \n", "70 | \n", "
29 | \n", "100 | \n", "91 | \n", "46 | \n", "76 | \n", "
30 | \n", "43 | \n", "10 | \n", "35 | \n", "78 | \n", "
31 | \n", "15 | \n", "24 | \n", "57 | \n", "6 | \n", "
32 | \n", "51 | \n", "47 | \n", "47 | \n", "55 | \n", "
33 | \n", "83 | \n", "5 | \n", "84 | \n", "40 | \n", "
34 | \n", "100 | \n", "22 | \n", "26 | \n", "72 | \n", "
35 | \n", "60 | \n", "83 | \n", "80 | \n", "92 | \n", "
36 | \n", "28 | \n", "39 | \n", "82 | \n", "17 | \n", "
37 | \n", "56 | \n", "20 | \n", "94 | \n", "85 | \n", "
38 | \n", "72 | \n", "56 | \n", "63 | \n", "54 | \n", "
39 | \n", "15 | \n", "60 | \n", "30 | \n", "72 | \n", "
40 | \n", "41 | \n", "21 | \n", "86 | \n", "54 | \n", "
41 | \n", "85 | \n", "7 | \n", "50 | \n", "87 | \n", "
42 | \n", "48 | \n", "13 | \n", "69 | \n", "93 | \n", "
43 | \n", "75 | \n", "20 | \n", "98 | \n", "96 | \n", "
44 | \n", "41 | \n", "18 | \n", "14 | \n", "31 | \n", "
45 | \n", "84 | \n", "13 | \n", "62 | \n", "6 | \n", "
46 | \n", "13 | \n", "40 | \n", "77 | \n", "60 | \n", "
47 | \n", "70 | \n", "18 | \n", "84 | \n", "26 | \n", "
48 | \n", "97 | \n", "22 | \n", "24 | \n", "34 | \n", "
49 | \n", "56 | \n", "83 | \n", "9 | \n", "95 | \n", "