{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# xi. Model Inference" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pickle\n", "import pandas as pd\n", "import numpy as np\n", "import random" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#load model scaler dan model knn yang sudah disimpen dalam bentuk pkl\n", "with open('scaler.pkl', 'rb') as file_1:\n", " scaler = pickle.load(file_1)\n", "\n", "with open('model_knn.pkl', 'rb') as file_2:\n", " model_knn = pickle.load(file_2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Membuat data dummy" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Atur seed di sini\n", "seed_value = 777\n", "random.seed(seed_value)\n", "np.random.seed(seed_value)\n", "\n", "# Jumlah data point yang ingin dibuat\n", "n = 100\n", "\n", "# Membuat data untuk kolom 'distance'\n", "limit_balance = np.round(np.random.uniform(10000, 800000, n), 2)\n", "\n", "# Membuat data untuk kolom 'surge_multiplier'\n", "pay_1 = [-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]\n", "pay_1 = random.choices(pay_1, k=n)\n", "\n", "pay_2 = [-2.0,-1.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0]\n", "pay_2 = random.choices(pay_2, k=n)\n", "\n", "pay_3 = [-2.0,-1.0,0.0,2.0,3.0,4.0,5.0,6.0,7.0]\n", "pay_3 = random.choices(pay_3, k=n)\n", "\n", "pay_4 = [-2.0,-1.0,0.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]\n", "pay_4 = random.choices(pay_4, k=n)\n", "\n", "pay_5 = [-2.0,-1.0,0.0,2.0,3.0,4.0,5.0,6.0,7.0]\n", "pay_5 = random.choices(pay_5, k=n)\n", "\n", "pay_6 = [-2.0,-1.0,0.0,2.0,3.0,4.0,6.0,7.0]\n", "pay_6 = random.choices(pay_6, k=n)\n", "\n", "# Membuat DataFrame\n", "df_inf = pd.DataFrame({\n", " 'limit_balance': limit_balance,\n", " 'pay_1': pay_1,\n", " 'pay_2': pay_2,\n", " 'pay_3': pay_3,\n", " 'pay_4': pay_4,\n", " 'pay_5': pay_5,\n", " 'pay_6': pay_6,\n", " \n", "})" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | limit_balance | \n", "pay_1 | \n", "pay_2 | \n", "pay_3 | \n", "pay_4 | \n", "pay_5 | \n", "pay_6 | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "130604.35 | \n", "0.0 | \n", "7.0 | \n", "5.0 | \n", "5.0 | \n", "2.0 | \n", "6.0 | \n", "
1 | \n", "248861.72 | \n", "2.0 | \n", "-2.0 | \n", "3.0 | \n", "0.0 | \n", "-2.0 | \n", "6.0 | \n", "
2 | \n", "59008.77 | \n", "2.0 | \n", "-2.0 | \n", "3.0 | \n", "5.0 | \n", "2.0 | \n", "7.0 | \n", "
3 | \n", "373289.67 | \n", "0.0 | \n", "7.0 | \n", "2.0 | \n", "2.0 | \n", "-2.0 | \n", "0.0 | \n", "
4 | \n", "669850.17 | \n", "1.0 | \n", "4.0 | \n", "-1.0 | \n", "0.0 | \n", "7.0 | \n", "7.0 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "772548.37 | \n", "2.0 | \n", "-2.0 | \n", "0.0 | \n", "0.0 | \n", "6.0 | \n", "3.0 | \n", "
96 | \n", "780417.84 | \n", "7.0 | \n", "6.0 | \n", "7.0 | \n", "5.0 | \n", "3.0 | \n", "-2.0 | \n", "
97 | \n", "169988.27 | \n", "4.0 | \n", "2.0 | \n", "3.0 | \n", "-2.0 | \n", "-1.0 | \n", "4.0 | \n", "
98 | \n", "547083.91 | \n", "4.0 | \n", "1.0 | \n", "4.0 | \n", "-1.0 | \n", "5.0 | \n", "2.0 | \n", "
99 | \n", "377622.60 | \n", "-2.0 | \n", "5.0 | \n", "3.0 | \n", "7.0 | \n", "3.0 | \n", "7.0 | \n", "
100 rows × 7 columns
\n", "\n", " | 0 | \n", "
---|---|
0 | \n", "0.241209 | \n", "
1 | \n", "0.477723 | \n", "
2 | \n", "0.098018 | \n", "
3 | \n", "0.726579 | \n", "
4 | \n", "1.319700 | \n", "
... | \n", "... | \n", "
95 | \n", "1.525097 | \n", "
96 | \n", "1.540836 | \n", "
97 | \n", "0.319977 | \n", "
98 | \n", "1.074168 | \n", "
99 | \n", "0.735245 | \n", "
100 rows × 1 columns
\n", "\n", " | Def_payment - Prediction | \n", "
---|---|
0 | \n", "0 | \n", "
1 | \n", "1 | \n", "
2 | \n", "0 | \n", "
3 | \n", "1 | \n", "
4 | \n", "1 | \n", "
... | \n", "... | \n", "
95 | \n", "1 | \n", "
96 | \n", "1 | \n", "
97 | \n", "1 | \n", "
98 | \n", "1 | \n", "
99 | \n", "1 | \n", "
100 rows × 1 columns
\n", "\n", " | limit_balance | \n", "pay_1 | \n", "pay_2 | \n", "pay_3 | \n", "pay_4 | \n", "pay_5 | \n", "pay_6 | \n", "Def_payment - Prediction | \n", "
---|---|---|---|---|---|---|---|---|
0 | \n", "130604.35 | \n", "0.0 | \n", "7.0 | \n", "5.0 | \n", "5.0 | \n", "2.0 | \n", "6.0 | \n", "0 | \n", "
1 | \n", "248861.72 | \n", "2.0 | \n", "-2.0 | \n", "3.0 | \n", "0.0 | \n", "-2.0 | \n", "6.0 | \n", "1 | \n", "
2 | \n", "59008.77 | \n", "2.0 | \n", "-2.0 | \n", "3.0 | \n", "5.0 | \n", "2.0 | \n", "7.0 | \n", "0 | \n", "
3 | \n", "373289.67 | \n", "0.0 | \n", "7.0 | \n", "2.0 | \n", "2.0 | \n", "-2.0 | \n", "0.0 | \n", "1 | \n", "
4 | \n", "669850.17 | \n", "1.0 | \n", "4.0 | \n", "-1.0 | \n", "0.0 | \n", "7.0 | \n", "7.0 | \n", "1 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
95 | \n", "772548.37 | \n", "2.0 | \n", "-2.0 | \n", "0.0 | \n", "0.0 | \n", "6.0 | \n", "3.0 | \n", "1 | \n", "
96 | \n", "780417.84 | \n", "7.0 | \n", "6.0 | \n", "7.0 | \n", "5.0 | \n", "3.0 | \n", "-2.0 | \n", "1 | \n", "
97 | \n", "169988.27 | \n", "4.0 | \n", "2.0 | \n", "3.0 | \n", "-2.0 | \n", "-1.0 | \n", "4.0 | \n", "1 | \n", "
98 | \n", "547083.91 | \n", "4.0 | \n", "1.0 | \n", "4.0 | \n", "-1.0 | \n", "5.0 | \n", "2.0 | \n", "1 | \n", "
99 | \n", "377622.60 | \n", "-2.0 | \n", "5.0 | \n", "3.0 | \n", "7.0 | \n", "3.0 | \n", "7.0 | \n", "1 | \n", "
100 rows × 8 columns
\n", "