Skip to content

Commit

Permalink
Added Regression notebook. Updated older notebooks by clearing the ou…
Browse files Browse the repository at this point in the history
…tput.
  • Loading branch information
screwgoth committed Jun 1, 2020
1 parent d34a65b commit 9fc9737
Show file tree
Hide file tree
Showing 4 changed files with 948 additions and 2 deletions.
264 changes: 264 additions & 0 deletions Regression/Simple_Regression/simple_linear_regression.ipynb
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
}
31 changes: 31 additions & 0 deletions datasets/Salary_Data.csv
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
Loading

0 comments on commit 9fc9737

Please sign in to comment.