Skip to content

Commit

Permalink
Added all the Regression models and datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
screwgoth committed Jun 1, 2020
1 parent bdc2f91 commit 6713ba8
Show file tree
Hide file tree
Showing 7 changed files with 1,207 additions and 0 deletions.
215 changes: 215 additions & 0 deletions Regression/Decision_Tree_Regression/decision_tree_regression.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "r3cas2_1T98w"
},
"source": [
"# Decision Tree Regression"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "IODliia6U1xO"
},
"source": [
"## Importing the libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "y98nA5UdU6Hf"
},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "jpjZ43YlU8eI"
},
"source": [
"## Importing the dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "pLVaXoYVU_Uy"
},
"outputs": [],
"source": [
"dataset = pd.read_csv('../../datasets/Position_Salaries.csv')\n",
"X = dataset.iloc[:, 1:-1].values\n",
"y = dataset.iloc[:, -1].values"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "g16qFkFQVC35"
},
"source": [
"## Training the Decision Tree Regression model on the whole dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 121
},
"colab_type": "code",
"executionInfo": {
"elapsed": 1050,
"status": "ok",
"timestamp": 1587885283111,
"user": {
"displayName": "Hadelin de Ponteves",
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64",
"userId": "15047218817161520419"
},
"user_tz": -240
},
"id": "SLDKyv1SVUqS",
"outputId": "a633ebbf-6fea-4b97-ccd8-1f8851e9d363"
},
"outputs": [],
"source": [
"from sklearn.tree import DecisionTreeRegressor\n",
"regressor = DecisionTreeRegressor(random_state = 0)\n",
"regressor.fit(X, y)"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "MQRGPTH3VcOn"
},
"source": [
"## Predicting a new result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"colab_type": "code",
"executionInfo": {
"elapsed": 991,
"status": "ok",
"timestamp": 1587885288845,
"user": {
"displayName": "Hadelin de Ponteves",
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64",
"userId": "15047218817161520419"
},
"user_tz": -240
},
"id": "_FpGZf7vVgrK",
"outputId": "54f36048-d4a1-4143-8b2b-b5aa32233b68"
},
"outputs": [],
"source": [
"regressor.predict([[6.5]])"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "ph8ExBj0VkIT"
},
"source": [
"## Visualising the Decision Tree Regression results (higher resolution)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"colab_type": "code",
"executionInfo": {
"elapsed": 975,
"status": "ok",
"timestamp": 1587885301261,
"user": {
"displayName": "Hadelin de Ponteves",
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64",
"userId": "15047218817161520419"
},
"user_tz": -240
},
"id": "zzH1Vv1oVrqe",
"outputId": "84111519-5c51-498c-c330-0d53825849e3"
},
"outputs": [],
"source": [
"X_grid = np.arange(min(X), max(X), 0.01)\n",
"X_grid = X_grid.reshape((len(X_grid), 1))\n",
"plt.scatter(X, y, color = 'red')\n",
"plt.plot(X_grid, regressor.predict(X_grid), color = 'blue')\n",
"plt.title('Truth or Bluff (Decision Tree Regression)')\n",
"plt.xlabel('Position level')\n",
"plt.ylabel('Salary')\n",
"plt.show()"
]
}
],
"metadata": {
"colab": {
"authorship_tag": "ABX9TyPkSAAyT6lZPl3l4/vYw79H",
"collapsed_sections": [],
"name": "decision_tree_regression.ipynb",
"provenance": [],
"toc_visible": true
},
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading

0 comments on commit 6713ba8

Please sign in to comment.