mirror of
https://github.com/deepseek-ai/DeepSeek-Coder
synced 2025-04-08 14:34:23 +00:00
1045 lines
46 KiB
Plaintext
1045 lines
46 KiB
Plaintext
{
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0,
|
|
"metadata": {
|
|
"colab": {
|
|
"provenance": [],
|
|
"include_colab_link": true
|
|
},
|
|
"kernelspec": {
|
|
"name": "python3",
|
|
"display_name": "Python 3"
|
|
},
|
|
"language_info": {
|
|
"name": "python"
|
|
}
|
|
},
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "view-in-github",
|
|
"colab_type": "text"
|
|
},
|
|
"source": [
|
|
"<a href=\"https://colab.research.google.com/github/Orrm23/DeepSeek-Coder/blob/main/14_Stock_prediction_using_SVM_REGRESSION.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "NdHIE4CSDCp3"
|
|
},
|
|
"source": [
|
|
"# **Day-14 | Stock Prediction using SUPPORT VECTOR REGRESSION**"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "1NTrKL3eIgZ8"
|
|
},
|
|
"source": [
|
|
"### *Importing Libraries*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "ae6Pxuc-CNeu"
|
|
},
|
|
"source": [
|
|
"import pandas as pd\n",
|
|
"import numpy as np"
|
|
],
|
|
"execution_count": 1,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "6oo4HsbHInXM"
|
|
},
|
|
"source": [
|
|
"### *Load Dataset from Local directory*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "w0WCVounIsJ5",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 73
|
|
},
|
|
"outputId": "72f5c938-c267-41f9-ee2a-6d6563b5664f"
|
|
},
|
|
"source": [
|
|
"from google.colab import files\n",
|
|
"uploaded = files.upload()"
|
|
],
|
|
"execution_count": 2,
|
|
"outputs": [
|
|
{
|
|
"output_type": "display_data",
|
|
"data": {
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
],
|
|
"text/html": [
|
|
"\n",
|
|
" <input type=\"file\" id=\"files-0176166e-506d-47a4-b7b8-ce8cc8eee744\" name=\"files[]\" multiple disabled\n",
|
|
" style=\"border:none\" />\n",
|
|
" <output id=\"result-0176166e-506d-47a4-b7b8-ce8cc8eee744\">\n",
|
|
" Upload widget is only available when the cell has been executed in the\n",
|
|
" current browser session. Please rerun this cell to enable.\n",
|
|
" </output>\n",
|
|
" <script>// Copyright 2017 Google LLC\n",
|
|
"//\n",
|
|
"// Licensed under the Apache License, Version 2.0 (the \"License\");\n",
|
|
"// you may not use this file except in compliance with the License.\n",
|
|
"// You may obtain a copy of the License at\n",
|
|
"//\n",
|
|
"// http://www.apache.org/licenses/LICENSE-2.0\n",
|
|
"//\n",
|
|
"// Unless required by applicable law or agreed to in writing, software\n",
|
|
"// distributed under the License is distributed on an \"AS IS\" BASIS,\n",
|
|
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
|
|
"// See the License for the specific language governing permissions and\n",
|
|
"// limitations under the License.\n",
|
|
"\n",
|
|
"/**\n",
|
|
" * @fileoverview Helpers for google.colab Python module.\n",
|
|
" */\n",
|
|
"(function(scope) {\n",
|
|
"function span(text, styleAttributes = {}) {\n",
|
|
" const element = document.createElement('span');\n",
|
|
" element.textContent = text;\n",
|
|
" for (const key of Object.keys(styleAttributes)) {\n",
|
|
" element.style[key] = styleAttributes[key];\n",
|
|
" }\n",
|
|
" return element;\n",
|
|
"}\n",
|
|
"\n",
|
|
"// Max number of bytes which will be uploaded at a time.\n",
|
|
"const MAX_PAYLOAD_SIZE = 100 * 1024;\n",
|
|
"\n",
|
|
"function _uploadFiles(inputId, outputId) {\n",
|
|
" const steps = uploadFilesStep(inputId, outputId);\n",
|
|
" const outputElement = document.getElementById(outputId);\n",
|
|
" // Cache steps on the outputElement to make it available for the next call\n",
|
|
" // to uploadFilesContinue from Python.\n",
|
|
" outputElement.steps = steps;\n",
|
|
"\n",
|
|
" return _uploadFilesContinue(outputId);\n",
|
|
"}\n",
|
|
"\n",
|
|
"// This is roughly an async generator (not supported in the browser yet),\n",
|
|
"// where there are multiple asynchronous steps and the Python side is going\n",
|
|
"// to poll for completion of each step.\n",
|
|
"// This uses a Promise to block the python side on completion of each step,\n",
|
|
"// then passes the result of the previous step as the input to the next step.\n",
|
|
"function _uploadFilesContinue(outputId) {\n",
|
|
" const outputElement = document.getElementById(outputId);\n",
|
|
" const steps = outputElement.steps;\n",
|
|
"\n",
|
|
" const next = steps.next(outputElement.lastPromiseValue);\n",
|
|
" return Promise.resolve(next.value.promise).then((value) => {\n",
|
|
" // Cache the last promise value to make it available to the next\n",
|
|
" // step of the generator.\n",
|
|
" outputElement.lastPromiseValue = value;\n",
|
|
" return next.value.response;\n",
|
|
" });\n",
|
|
"}\n",
|
|
"\n",
|
|
"/**\n",
|
|
" * Generator function which is called between each async step of the upload\n",
|
|
" * process.\n",
|
|
" * @param {string} inputId Element ID of the input file picker element.\n",
|
|
" * @param {string} outputId Element ID of the output display.\n",
|
|
" * @return {!Iterable<!Object>} Iterable of next steps.\n",
|
|
" */\n",
|
|
"function* uploadFilesStep(inputId, outputId) {\n",
|
|
" const inputElement = document.getElementById(inputId);\n",
|
|
" inputElement.disabled = false;\n",
|
|
"\n",
|
|
" const outputElement = document.getElementById(outputId);\n",
|
|
" outputElement.innerHTML = '';\n",
|
|
"\n",
|
|
" const pickedPromise = new Promise((resolve) => {\n",
|
|
" inputElement.addEventListener('change', (e) => {\n",
|
|
" resolve(e.target.files);\n",
|
|
" });\n",
|
|
" });\n",
|
|
"\n",
|
|
" const cancel = document.createElement('button');\n",
|
|
" inputElement.parentElement.appendChild(cancel);\n",
|
|
" cancel.textContent = 'Cancel upload';\n",
|
|
" const cancelPromise = new Promise((resolve) => {\n",
|
|
" cancel.onclick = () => {\n",
|
|
" resolve(null);\n",
|
|
" };\n",
|
|
" });\n",
|
|
"\n",
|
|
" // Wait for the user to pick the files.\n",
|
|
" const files = yield {\n",
|
|
" promise: Promise.race([pickedPromise, cancelPromise]),\n",
|
|
" response: {\n",
|
|
" action: 'starting',\n",
|
|
" }\n",
|
|
" };\n",
|
|
"\n",
|
|
" cancel.remove();\n",
|
|
"\n",
|
|
" // Disable the input element since further picks are not allowed.\n",
|
|
" inputElement.disabled = true;\n",
|
|
"\n",
|
|
" if (!files) {\n",
|
|
" return {\n",
|
|
" response: {\n",
|
|
" action: 'complete',\n",
|
|
" }\n",
|
|
" };\n",
|
|
" }\n",
|
|
"\n",
|
|
" for (const file of files) {\n",
|
|
" const li = document.createElement('li');\n",
|
|
" li.append(span(file.name, {fontWeight: 'bold'}));\n",
|
|
" li.append(span(\n",
|
|
" `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n",
|
|
" `last modified: ${\n",
|
|
" file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n",
|
|
" 'n/a'} - `));\n",
|
|
" const percent = span('0% done');\n",
|
|
" li.appendChild(percent);\n",
|
|
"\n",
|
|
" outputElement.appendChild(li);\n",
|
|
"\n",
|
|
" const fileDataPromise = new Promise((resolve) => {\n",
|
|
" const reader = new FileReader();\n",
|
|
" reader.onload = (e) => {\n",
|
|
" resolve(e.target.result);\n",
|
|
" };\n",
|
|
" reader.readAsArrayBuffer(file);\n",
|
|
" });\n",
|
|
" // Wait for the data to be ready.\n",
|
|
" let fileData = yield {\n",
|
|
" promise: fileDataPromise,\n",
|
|
" response: {\n",
|
|
" action: 'continue',\n",
|
|
" }\n",
|
|
" };\n",
|
|
"\n",
|
|
" // Use a chunked sending to avoid message size limits. See b/62115660.\n",
|
|
" let position = 0;\n",
|
|
" do {\n",
|
|
" const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n",
|
|
" const chunk = new Uint8Array(fileData, position, length);\n",
|
|
" position += length;\n",
|
|
"\n",
|
|
" const base64 = btoa(String.fromCharCode.apply(null, chunk));\n",
|
|
" yield {\n",
|
|
" response: {\n",
|
|
" action: 'append',\n",
|
|
" file: file.name,\n",
|
|
" data: base64,\n",
|
|
" },\n",
|
|
" };\n",
|
|
"\n",
|
|
" let percentDone = fileData.byteLength === 0 ?\n",
|
|
" 100 :\n",
|
|
" Math.round((position / fileData.byteLength) * 100);\n",
|
|
" percent.textContent = `${percentDone}% done`;\n",
|
|
"\n",
|
|
" } while (position < fileData.byteLength);\n",
|
|
" }\n",
|
|
"\n",
|
|
" // All done.\n",
|
|
" yield {\n",
|
|
" response: {\n",
|
|
" action: 'complete',\n",
|
|
" }\n",
|
|
" };\n",
|
|
"}\n",
|
|
"\n",
|
|
"scope.google = scope.google || {};\n",
|
|
"scope.google.colab = scope.google.colab || {};\n",
|
|
"scope.google.colab._files = {\n",
|
|
" _uploadFiles,\n",
|
|
" _uploadFilesContinue,\n",
|
|
"};\n",
|
|
"})(self);\n",
|
|
"</script> "
|
|
]
|
|
},
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"Saving data.csv to data.csv\n"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "NHijCKx7I0k8"
|
|
},
|
|
"source": [
|
|
"### *Load Dataset*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "zxBak91bI2yh"
|
|
},
|
|
"source": [
|
|
"dataset = pd.read_csv('data.csv')"
|
|
],
|
|
"execution_count": 3,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "5XKSRUPWI5Q-"
|
|
},
|
|
"source": [
|
|
"### *Summarize Dataset*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "63BR2xiKI7oZ",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"outputId": "7bcfc903-7216-4aa7-c079-b13837f2fb72"
|
|
},
|
|
"source": [
|
|
"print(dataset.shape)\n",
|
|
"print(dataset.head(5))"
|
|
],
|
|
"execution_count": 4,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"(94, 2)\n",
|
|
" x y\n",
|
|
"0 168.181818 160.840244\n",
|
|
"1 187.878788 159.413657\n",
|
|
"2 207.575758 157.136809\n",
|
|
"3 227.272727 159.357847\n",
|
|
"4 246.969697 157.542862\n"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "Zv8cn1g8Jix-"
|
|
},
|
|
"source": [
|
|
"### *Segregate Dataset into Input X & Output Y*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "iR3g4pDjJoj9",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"outputId": "a0374808-f07f-487b-d913-fa21394a2d3d"
|
|
},
|
|
"source": [
|
|
"X = dataset.iloc[:, :-1].values\n",
|
|
"X"
|
|
],
|
|
"execution_count": 5,
|
|
"outputs": [
|
|
{
|
|
"output_type": "execute_result",
|
|
"data": {
|
|
"text/plain": [
|
|
"array([[ 168.18181818],\n",
|
|
" [ 187.87878788],\n",
|
|
" [ 207.57575758],\n",
|
|
" [ 227.27272727],\n",
|
|
" [ 246.96969697],\n",
|
|
" [ 266.66666667],\n",
|
|
" [ 286.36363636],\n",
|
|
" [ 306.06060606],\n",
|
|
" [ 325.75757576],\n",
|
|
" [ 345.45454545],\n",
|
|
" [ 365.15151515],\n",
|
|
" [ 384.84848485],\n",
|
|
" [ 404.54545455],\n",
|
|
" [ 424.24242424],\n",
|
|
" [ 443.93939394],\n",
|
|
" [ 463.63636364],\n",
|
|
" [ 483.33333333],\n",
|
|
" [ 503.03030303],\n",
|
|
" [ 522.72727273],\n",
|
|
" [ 542.42424242],\n",
|
|
" [ 562.12121212],\n",
|
|
" [ 581.81818182],\n",
|
|
" [ 601.51515152],\n",
|
|
" [ 621.21212121],\n",
|
|
" [ 640.90909091],\n",
|
|
" [ 660.60606061],\n",
|
|
" [ 680.3030303 ],\n",
|
|
" [ 700. ],\n",
|
|
" [ 719.6969697 ],\n",
|
|
" [ 739.39393939],\n",
|
|
" [ 759.09090909],\n",
|
|
" [ 778.78787879],\n",
|
|
" [ 798.48484848],\n",
|
|
" [ 818.18181818],\n",
|
|
" [ 837.87878788],\n",
|
|
" [ 857.57575758],\n",
|
|
" [ 877.27272727],\n",
|
|
" [ 896.96969697],\n",
|
|
" [ 916.66666667],\n",
|
|
" [ 936.36363636],\n",
|
|
" [ 956.06060606],\n",
|
|
" [ 975.75757576],\n",
|
|
" [ 995.45454545],\n",
|
|
" [1015.15151515],\n",
|
|
" [1034.84848485],\n",
|
|
" [1054.54545455],\n",
|
|
" [1074.24242424],\n",
|
|
" [1093.93939394],\n",
|
|
" [1113.63636364],\n",
|
|
" [1133.33333333],\n",
|
|
" [1153.03030303],\n",
|
|
" [1172.72727273],\n",
|
|
" [1192.42424242],\n",
|
|
" [1212.12121212],\n",
|
|
" [1231.81818182],\n",
|
|
" [1251.51515152],\n",
|
|
" [1271.21212121],\n",
|
|
" [1290.90909091],\n",
|
|
" [1310.60606061],\n",
|
|
" [1330.3030303 ],\n",
|
|
" [1350. ],\n",
|
|
" [1369.6969697 ],\n",
|
|
" [1389.39393939],\n",
|
|
" [1409.09090909],\n",
|
|
" [1428.78787879],\n",
|
|
" [1448.48484848],\n",
|
|
" [1468.18181818],\n",
|
|
" [1487.87878788],\n",
|
|
" [1507.57575758],\n",
|
|
" [1527.27272727],\n",
|
|
" [1546.96969697],\n",
|
|
" [1566.66666667],\n",
|
|
" [1586.36363636],\n",
|
|
" [1606.06060606],\n",
|
|
" [1625.75757576],\n",
|
|
" [1645.45454545],\n",
|
|
" [1665.15151515],\n",
|
|
" [1684.84848485],\n",
|
|
" [1704.54545455],\n",
|
|
" [1724.24242424],\n",
|
|
" [1743.93939394],\n",
|
|
" [1763.63636364],\n",
|
|
" [1783.33333333],\n",
|
|
" [1803.03030303],\n",
|
|
" [1822.72727273],\n",
|
|
" [1842.42424242],\n",
|
|
" [1862.12121212],\n",
|
|
" [1881.81818182],\n",
|
|
" [1901.51515152],\n",
|
|
" [1921.21212121],\n",
|
|
" [1940.90909091],\n",
|
|
" [1960.60606061],\n",
|
|
" [1980.3030303 ],\n",
|
|
" [2000. ]])"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"execution_count": 5
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "LyJ8ghMFKcMe",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"outputId": "1ffa4118-7ce7-47fe-c462-1b63f2830057"
|
|
},
|
|
"source": [
|
|
"Y = dataset.iloc[:, -1].values\n",
|
|
"Y"
|
|
],
|
|
"execution_count": 6,
|
|
"outputs": [
|
|
{
|
|
"output_type": "execute_result",
|
|
"data": {
|
|
"text/plain": [
|
|
"array([160.84024381, 159.41365734, 157.1368088 , 159.35784736,\n",
|
|
" 157.54286158, 157.73520716, 159.34756091, 155.23404557,\n",
|
|
" 155.80774009, 158.3299704 , 157.62585291, 160.47697951,\n",
|
|
" 158.22940639, 157.41781684, 163.37069148, 160.18481104,\n",
|
|
" 160.96838974, 158.18080666, 160.13850728, 161.6460876 ,\n",
|
|
" 159.31922497, 162.56957785, 160.81387414, 161.62873371,\n",
|
|
" 161.20567768, 166.31061698, 162.77603585, 160.88457814,\n",
|
|
" 164.84205952, 160.95225209, 164.00863628, 159.86853854,\n",
|
|
" 161.32847639, 164.57554065, 165.85572104, 164.91849414,\n",
|
|
" 164.54143071, 164.36748958, 162.20962269, 163.92394795,\n",
|
|
" 164.63932852, 167.87182021, 166.64178203, 162.62543484,\n",
|
|
" 166.99665279, 165.77528998, 165.38858024, 168.16274652,\n",
|
|
" 169.19836268, 169.19589357, 165.85186798, 167.10884798,\n",
|
|
" 168.58676929, 170.07230238, 167.35983334, 168.14383356,\n",
|
|
" 166.49945126, 166.51667766, 170.73111225, 172.01551036,\n",
|
|
" 169.35597976, 171.70403549, 170.61721144, 168.80066958,\n",
|
|
" 171.01067 , 173.56092162, 170.6101661 , 174.00807519,\n",
|
|
" 165.83626737, 172.91653228, 171.64379111, 171.06865197,\n",
|
|
" 172.04715792, 168.08546823, 171.81823198, 173.1687706 ,\n",
|
|
" 175.60730324, 171.81194441, 171.42846734, 172.23891016,\n",
|
|
" 175.27019817, 174.29386586, 172.77381293, 175.0568379 ,\n",
|
|
" 174.42142783, 176.36153241, 173.21710593, 174.16285752,\n",
|
|
" 174.23093521, 172.28509132, 176.00133146, 176.12817115,\n",
|
|
" 175.81325722, 175.53082573])"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"execution_count": 6
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "z5kccmBcw1PQ"
|
|
},
|
|
"source": [
|
|
"### *Splitting Dataset for Testing our Model*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "Pc4kGEuDw36Q"
|
|
},
|
|
"source": [
|
|
"from sklearn.model_selection import train_test_split\n",
|
|
"x_train,x_test,y_train,y_test = train_test_split(X,Y,test_size=0.20,random_state=0)"
|
|
],
|
|
"execution_count": 7,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "XP-L6ZRyL30I"
|
|
},
|
|
"source": [
|
|
"### *Training Dataset using Support Vector Regression*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "c4x1C89ZVjr9",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/",
|
|
"height": 80
|
|
},
|
|
"outputId": "7713001d-363a-449f-8ccb-b224e7435310"
|
|
},
|
|
"source": [
|
|
"from sklearn.svm import SVR\n",
|
|
"model = SVR()\n",
|
|
"model.fit(x_train,y_train)"
|
|
],
|
|
"execution_count": 8,
|
|
"outputs": [
|
|
{
|
|
"output_type": "execute_result",
|
|
"data": {
|
|
"text/plain": [
|
|
"SVR()"
|
|
],
|
|
"text/html": [
|
|
"<style>#sk-container-id-1 {\n",
|
|
" /* Definition of color scheme common for light and dark mode */\n",
|
|
" --sklearn-color-text: #000;\n",
|
|
" --sklearn-color-text-muted: #666;\n",
|
|
" --sklearn-color-line: gray;\n",
|
|
" /* Definition of color scheme for unfitted estimators */\n",
|
|
" --sklearn-color-unfitted-level-0: #fff5e6;\n",
|
|
" --sklearn-color-unfitted-level-1: #f6e4d2;\n",
|
|
" --sklearn-color-unfitted-level-2: #ffe0b3;\n",
|
|
" --sklearn-color-unfitted-level-3: chocolate;\n",
|
|
" /* Definition of color scheme for fitted estimators */\n",
|
|
" --sklearn-color-fitted-level-0: #f0f8ff;\n",
|
|
" --sklearn-color-fitted-level-1: #d4ebff;\n",
|
|
" --sklearn-color-fitted-level-2: #b3dbfd;\n",
|
|
" --sklearn-color-fitted-level-3: cornflowerblue;\n",
|
|
"\n",
|
|
" /* Specific color for light theme */\n",
|
|
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
|
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
|
|
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
|
" --sklearn-color-icon: #696969;\n",
|
|
"\n",
|
|
" @media (prefers-color-scheme: dark) {\n",
|
|
" /* Redefinition of color scheme for dark theme */\n",
|
|
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
|
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
|
|
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
|
" --sklearn-color-icon: #878787;\n",
|
|
" }\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 {\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 pre {\n",
|
|
" padding: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 input.sk-hidden--visually {\n",
|
|
" border: 0;\n",
|
|
" clip: rect(1px 1px 1px 1px);\n",
|
|
" clip: rect(1px, 1px, 1px, 1px);\n",
|
|
" height: 1px;\n",
|
|
" margin: -1px;\n",
|
|
" overflow: hidden;\n",
|
|
" padding: 0;\n",
|
|
" position: absolute;\n",
|
|
" width: 1px;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-dashed-wrapped {\n",
|
|
" border: 1px dashed var(--sklearn-color-line);\n",
|
|
" margin: 0 0.4em 0.5em 0.4em;\n",
|
|
" box-sizing: border-box;\n",
|
|
" padding-bottom: 0.4em;\n",
|
|
" background-color: var(--sklearn-color-background);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-container {\n",
|
|
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
|
|
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
|
|
" so we also need the `!important` here to be able to override the\n",
|
|
" default hidden behavior on the sphinx rendered scikit-learn.org.\n",
|
|
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
|
|
" display: inline-block !important;\n",
|
|
" position: relative;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-text-repr-fallback {\n",
|
|
" display: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
"div.sk-parallel-item,\n",
|
|
"div.sk-serial,\n",
|
|
"div.sk-item {\n",
|
|
" /* draw centered vertical line to link estimators */\n",
|
|
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
|
|
" background-size: 2px 100%;\n",
|
|
" background-repeat: no-repeat;\n",
|
|
" background-position: center center;\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Parallel-specific style estimator block */\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-parallel-item::after {\n",
|
|
" content: \"\";\n",
|
|
" width: 100%;\n",
|
|
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
|
|
" flex-grow: 1;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-parallel {\n",
|
|
" display: flex;\n",
|
|
" align-items: stretch;\n",
|
|
" justify-content: center;\n",
|
|
" background-color: var(--sklearn-color-background);\n",
|
|
" position: relative;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-parallel-item {\n",
|
|
" display: flex;\n",
|
|
" flex-direction: column;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
|
|
" align-self: flex-end;\n",
|
|
" width: 50%;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
|
|
" align-self: flex-start;\n",
|
|
" width: 50%;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
|
|
" width: 0;\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Serial-specific style estimator block */\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-serial {\n",
|
|
" display: flex;\n",
|
|
" flex-direction: column;\n",
|
|
" align-items: center;\n",
|
|
" background-color: var(--sklearn-color-background);\n",
|
|
" padding-right: 1em;\n",
|
|
" padding-left: 1em;\n",
|
|
"}\n",
|
|
"\n",
|
|
"\n",
|
|
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
|
|
"clickable and can be expanded/collapsed.\n",
|
|
"- Pipeline and ColumnTransformer use this feature and define the default style\n",
|
|
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
|
|
"*/\n",
|
|
"\n",
|
|
"/* Pipeline and ColumnTransformer style (default) */\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-toggleable {\n",
|
|
" /* Default theme specific background. It is overwritten whether we have a\n",
|
|
" specific estimator or a Pipeline/ColumnTransformer */\n",
|
|
" background-color: var(--sklearn-color-background);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Toggleable label */\n",
|
|
"#sk-container-id-1 label.sk-toggleable__label {\n",
|
|
" cursor: pointer;\n",
|
|
" display: flex;\n",
|
|
" width: 100%;\n",
|
|
" margin-bottom: 0;\n",
|
|
" padding: 0.5em;\n",
|
|
" box-sizing: border-box;\n",
|
|
" text-align: center;\n",
|
|
" align-items: start;\n",
|
|
" justify-content: space-between;\n",
|
|
" gap: 0.5em;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 label.sk-toggleable__label .caption {\n",
|
|
" font-size: 0.6rem;\n",
|
|
" font-weight: lighter;\n",
|
|
" color: var(--sklearn-color-text-muted);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
|
|
" /* Arrow on the left of the label */\n",
|
|
" content: \"▸\";\n",
|
|
" float: left;\n",
|
|
" margin-right: 0.25em;\n",
|
|
" color: var(--sklearn-color-icon);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Toggleable content - dropdown */\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-toggleable__content {\n",
|
|
" max-height: 0;\n",
|
|
" max-width: 0;\n",
|
|
" overflow: hidden;\n",
|
|
" text-align: left;\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
|
|
" /* fitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-toggleable__content pre {\n",
|
|
" margin: 0.2em;\n",
|
|
" border-radius: 0.25em;\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
|
|
" /* Expand drop-down */\n",
|
|
" max-height: 200px;\n",
|
|
" max-width: 100%;\n",
|
|
" overflow: auto;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
|
|
" content: \"▾\";\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Pipeline/ColumnTransformer-specific style */\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Estimator-specific style */\n",
|
|
"\n",
|
|
"/* Colorize estimator box */\n",
|
|
"#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
|
" /* fitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
|
|
"#sk-container-id-1 div.sk-label label {\n",
|
|
" /* The background is the default theme color */\n",
|
|
" color: var(--sklearn-color-text-on-default-background);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* On hover, darken the color of the background */\n",
|
|
"#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Label box, darken color on hover, fitted */\n",
|
|
"#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Estimator label */\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-label label {\n",
|
|
" font-family: monospace;\n",
|
|
" font-weight: bold;\n",
|
|
" display: inline-block;\n",
|
|
" line-height: 1.2em;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-label-container {\n",
|
|
" text-align: center;\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Estimator-specific */\n",
|
|
"#sk-container-id-1 div.sk-estimator {\n",
|
|
" font-family: monospace;\n",
|
|
" border: 1px dotted var(--sklearn-color-border-box);\n",
|
|
" border-radius: 0.25em;\n",
|
|
" box-sizing: border-box;\n",
|
|
" margin-bottom: 0.5em;\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-estimator.fitted {\n",
|
|
" /* fitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* on hover */\n",
|
|
"#sk-container-id-1 div.sk-estimator:hover {\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
|
|
" /* fitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
|
|
"\n",
|
|
"/* Common style for \"i\" and \"?\" */\n",
|
|
"\n",
|
|
".sk-estimator-doc-link,\n",
|
|
"a:link.sk-estimator-doc-link,\n",
|
|
"a:visited.sk-estimator-doc-link {\n",
|
|
" float: right;\n",
|
|
" font-size: smaller;\n",
|
|
" line-height: 1em;\n",
|
|
" font-family: monospace;\n",
|
|
" background-color: var(--sklearn-color-background);\n",
|
|
" border-radius: 1em;\n",
|
|
" height: 1em;\n",
|
|
" width: 1em;\n",
|
|
" text-decoration: none !important;\n",
|
|
" margin-left: 0.5em;\n",
|
|
" text-align: center;\n",
|
|
" /* unfitted */\n",
|
|
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
|
" color: var(--sklearn-color-unfitted-level-1);\n",
|
|
"}\n",
|
|
"\n",
|
|
".sk-estimator-doc-link.fitted,\n",
|
|
"a:link.sk-estimator-doc-link.fitted,\n",
|
|
"a:visited.sk-estimator-doc-link.fitted {\n",
|
|
" /* fitted */\n",
|
|
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
|
" color: var(--sklearn-color-fitted-level-1);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* On hover */\n",
|
|
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
|
|
".sk-estimator-doc-link:hover,\n",
|
|
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
|
|
".sk-estimator-doc-link:hover {\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
|
" color: var(--sklearn-color-background);\n",
|
|
" text-decoration: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
|
|
".sk-estimator-doc-link.fitted:hover,\n",
|
|
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
|
|
".sk-estimator-doc-link.fitted:hover {\n",
|
|
" /* fitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
|
" color: var(--sklearn-color-background);\n",
|
|
" text-decoration: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* Span, style for the box shown on hovering the info icon */\n",
|
|
".sk-estimator-doc-link span {\n",
|
|
" display: none;\n",
|
|
" z-index: 9999;\n",
|
|
" position: relative;\n",
|
|
" font-weight: normal;\n",
|
|
" right: .2ex;\n",
|
|
" padding: .5ex;\n",
|
|
" margin: .5ex;\n",
|
|
" width: min-content;\n",
|
|
" min-width: 20ex;\n",
|
|
" max-width: 50ex;\n",
|
|
" color: var(--sklearn-color-text);\n",
|
|
" box-shadow: 2pt 2pt 4pt #999;\n",
|
|
" /* unfitted */\n",
|
|
" background: var(--sklearn-color-unfitted-level-0);\n",
|
|
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
|
|
"}\n",
|
|
"\n",
|
|
".sk-estimator-doc-link.fitted span {\n",
|
|
" /* fitted */\n",
|
|
" background: var(--sklearn-color-fitted-level-0);\n",
|
|
" border: var(--sklearn-color-fitted-level-3);\n",
|
|
"}\n",
|
|
"\n",
|
|
".sk-estimator-doc-link:hover span {\n",
|
|
" display: block;\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
|
|
"\n",
|
|
"#sk-container-id-1 a.estimator_doc_link {\n",
|
|
" float: right;\n",
|
|
" font-size: 1rem;\n",
|
|
" line-height: 1em;\n",
|
|
" font-family: monospace;\n",
|
|
" background-color: var(--sklearn-color-background);\n",
|
|
" border-radius: 1rem;\n",
|
|
" height: 1rem;\n",
|
|
" width: 1rem;\n",
|
|
" text-decoration: none;\n",
|
|
" /* unfitted */\n",
|
|
" color: var(--sklearn-color-unfitted-level-1);\n",
|
|
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 a.estimator_doc_link.fitted {\n",
|
|
" /* fitted */\n",
|
|
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
|
" color: var(--sklearn-color-fitted-level-1);\n",
|
|
"}\n",
|
|
"\n",
|
|
"/* On hover */\n",
|
|
"#sk-container-id-1 a.estimator_doc_link:hover {\n",
|
|
" /* unfitted */\n",
|
|
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
|
" color: var(--sklearn-color-background);\n",
|
|
" text-decoration: none;\n",
|
|
"}\n",
|
|
"\n",
|
|
"#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
|
|
" /* fitted */\n",
|
|
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
|
"}\n",
|
|
"</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>SVR()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>SVR</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.6/modules/generated/sklearn.svm.SVR.html\">?<span>Documentation for SVR</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\"><pre>SVR()</pre></div> </div></div></div></div>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"execution_count": 8
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "4YOj1wVjerek"
|
|
},
|
|
"source": [
|
|
"### *Prediction for all test data for validation*\n",
|
|
"### *SSres is the sum of squares of the residual errors.*\n",
|
|
"### *SStot is the total sum of the errors.*\n",
|
|
"# "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"metadata": {
|
|
"id": "mt_Z7EDqWhdB",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"outputId": "869e495f-65a3-43e1-c195-e201aad9217f"
|
|
},
|
|
"source": [
|
|
"ypred = model.predict(x_test)\n",
|
|
"\n",
|
|
"from sklearn.metrics import r2_score,mean_squared_error\n",
|
|
"mse = mean_squared_error(y_test,ypred)\n",
|
|
"rmse=np.sqrt(mse)\n",
|
|
"print(\"Root Mean Square Error:\",rmse)\n",
|
|
"r2score = r2_score(y_test,ypred)\n",
|
|
"print(\"R2Score\",r2score*100)"
|
|
],
|
|
"execution_count": 9,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"Root Mean Square Error: 2.3594718844452056\n",
|
|
"R2Score 86.64242653738367\n"
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
} |