-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Regression notebook. Updated older notebooks by clearing the ou…
…tput.
- Loading branch information
Showing
4 changed files
with
948 additions
and
2 deletions.
There are no files selected for viewing
264 changes: 264 additions & 0 deletions
264
Regression/Simple_Regression/simple_linear_regression.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,264 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "l_LulNCC8z96" | ||
}, | ||
"source": [ | ||
"# Simple Linear Regression" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "xpXdowrE9DxW" | ||
}, | ||
"source": [ | ||
"## Importing the libraries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": {}, | ||
"colab_type": "code", | ||
"id": "nhKd4hWx9GFt" | ||
}, | ||
"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": "6JhpWJi59J1p" | ||
}, | ||
"source": [ | ||
"## Importing the dataset" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": {}, | ||
"colab_type": "code", | ||
"id": "f8GfYDZ59O18" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"dataset = pd.read_csv('../../datasets/Salary_Data.csv')\n", | ||
"X = dataset.iloc[:, :-1].values\n", | ||
"y = dataset.iloc[:, -1].values" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "AyhQaTwP9RzG" | ||
}, | ||
"source": [ | ||
"## Splitting the dataset into the Training set and Test set" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": {}, | ||
"colab_type": "code", | ||
"id": "bxOOauiN9VpC" | ||
}, | ||
"outputs": [], | ||
"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 = 1/3, random_state = 0)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "ZijQwFMQ9itx" | ||
}, | ||
"source": [ | ||
"## Training the Simple Linear Regression model on the Training set" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 34 | ||
}, | ||
"colab_type": "code", | ||
"executionInfo": { | ||
"elapsed": 882, | ||
"status": "ok", | ||
"timestamp": 1586352495803, | ||
"user": { | ||
"displayName": "Hadelin de Ponteves", | ||
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", | ||
"userId": "15047218817161520419" | ||
}, | ||
"user_tz": -240 | ||
}, | ||
"id": "B4Aj_8YJ9l7J", | ||
"outputId": "15363111-2a76-4774-88ad-48db22159e9d" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from sklearn.linear_model import LinearRegression\n", | ||
"regressor = LinearRegression()\n", | ||
"regressor.fit(X_train, y_train)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "wa2T1Lq89o5H" | ||
}, | ||
"source": [ | ||
"## Predicting the Test set results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": {}, | ||
"colab_type": "code", | ||
"id": "Rn_sTJ2o9smm" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"y_pred = regressor.predict(X_test)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "-zSoMZ-P9v8t" | ||
}, | ||
"source": [ | ||
"## Visualising the Training set results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 295 | ||
}, | ||
"colab_type": "code", | ||
"executionInfo": { | ||
"elapsed": 763, | ||
"status": "ok", | ||
"timestamp": 1586352502760, | ||
"user": { | ||
"displayName": "Hadelin de Ponteves", | ||
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", | ||
"userId": "15047218817161520419" | ||
}, | ||
"user_tz": -240 | ||
}, | ||
"id": "IAePn_u-93tI", | ||
"outputId": "b860fdce-5757-4104-b6e9-0f180e3fca05" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"plt.scatter(X_train, y_train, color = 'red')\n", | ||
"plt.plot(X_train, regressor.predict(X_train), color = 'blue')\n", | ||
"plt.title('Salary vs Experience (Training set)')\n", | ||
"plt.xlabel('Years of Experience')\n", | ||
"plt.ylabel('Salary')\n", | ||
"plt.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"colab_type": "text", | ||
"id": "EUX1Vhsv97ZT" | ||
}, | ||
"source": [ | ||
"## Visualising the Test set results" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 295 | ||
}, | ||
"colab_type": "code", | ||
"executionInfo": { | ||
"elapsed": 1097, | ||
"status": "ok", | ||
"timestamp": 1586352506966, | ||
"user": { | ||
"displayName": "Hadelin de Ponteves", | ||
"photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", | ||
"userId": "15047218817161520419" | ||
}, | ||
"user_tz": -240 | ||
}, | ||
"id": "Ze9vpBTf-Bol", | ||
"outputId": "58359ab2-7a52-4960-f49e-3d8b5ef6f7a1" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"plt.scatter(X_test, y_test, color = 'red')\n", | ||
"plt.plot(X_train, regressor.predict(X_train), color = 'blue')\n", | ||
"plt.title('Salary vs Experience (Test set)')\n", | ||
"plt.xlabel('Years of Experience')\n", | ||
"plt.ylabel('Salary')\n", | ||
"plt.show()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"colab": { | ||
"authorship_tag": "ABX9TyP1VVwrQU8S68bmX5lftYWC", | ||
"name": "Simple Linear Regression", | ||
"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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
YearsExperience,Salary | ||
1.1,39343.00 | ||
1.3,46205.00 | ||
1.5,37731.00 | ||
2.0,43525.00 | ||
2.2,39891.00 | ||
2.9,56642.00 | ||
3.0,60150.00 | ||
3.2,54445.00 | ||
3.2,64445.00 | ||
3.7,57189.00 | ||
3.9,63218.00 | ||
4.0,55794.00 | ||
4.0,56957.00 | ||
4.1,57081.00 | ||
4.5,61111.00 | ||
4.9,67938.00 | ||
5.1,66029.00 | ||
5.3,83088.00 | ||
5.9,81363.00 | ||
6.0,93940.00 | ||
6.8,91738.00 | ||
7.1,98273.00 | ||
7.9,101302.00 | ||
8.2,113812.00 | ||
8.7,109431.00 | ||
9.0,105582.00 | ||
9.5,116969.00 | ||
9.6,112635.00 | ||
10.3,122391.00 | ||
10.5,121872.00 |
Oops, something went wrong.