├── 01- Numpy └── NumPy_Notes.pdf ├── 02- Pandas └── Pandas_Notes.pdf ├── 03- Data Reprocessing ├── Data.csv ├── data_preprocessing_template -Full.py ├── data_preprocessing_template.ipynb ├── data_preprocessing_template.py ├── data_preprocessing_tools.ipynb └── data_preprocessing_tools.py ├── 04-05- Simple Linear Regression ├── Salary_Data.csv ├── Simple_Linear_Regression.py ├── Simple_Linear_Regression_Colab.ipynb └── data_preprocessing_template.py ├── 06- Multiple Linear Regression Intuition ├── 50_Startups.csv ├── Multiple_Linear_Regression_Colab.ipynb └── data_preprocessing_template.py ├── 07- Polynomial Regression ├── Polynomial_regression_Colab.ipynb ├── Position_Salaries.csv ├── Regression_Template.py └── data_preprocessing_template.py ├── 08- Support Vector Regression (SVR) ├── Position_Salaries.csv ├── SVR_Colab.ipynb └── SVR_Regression_Template.py ├── 09- Decision_Tree_Regression ├── Decision_Tree_Regression.py ├── Decision_Tree_Regression_Colab.ipynb └── Position_Salaries.csv ├── 10- Random Forest ├── Position_Salaries.csv ├── Random Forest Regressor.py └── Random_Forest_Colab.ipynb ├── 11- Logistic_Regression ├── Classifer_template.py ├── Logistic_regression_py_Colab.ipynb ├── Logistic_regression_template .py └── Social_Network_Ads.csv ├── 12- K_Nearest_Neighbors ├── KNN_template.py ├── Section_15_KNN_files_Colab.ipynb └── Social_Network_Ads.csv ├── 13- SVM ├── SVM_Colab.ipynb ├── SVM_template.py └── Social_Network_Ads.csv ├── 14- Naive_Bayes ├── NB.py ├── NB_Colab.ipynb └── Social_Network_Ads.csv ├── 15- Decision_Tree_Classification ├── Decision_Tree_Classification.py ├── Decision_Tree_Classification_Colab.ipynb └── Social_Network_Ads.csv ├── 16- Random_Forest_Classification ├── Social_Network_Ads.csv ├── random_forest_classification.R └── random_forest_classification.py ├── 17- K_Means ├── K_means.py ├── Kmeans_Colab.ipynb └── Mall_Customers.csv ├── 18- Hierarchical_Clustering ├── K_means.py ├── Mall_Customers.csv └── hc_Colab.ipynb ├── 19- Apriori_Python ├── Apriori.py ├── Apriori_Colab.ipynb ├── Market_Basket_Optimisation.csv ├── __pycache__ │ └── apyori.cpython-38.pyc ├── apyori-1.1.2.tar.gz └── apyori.py ├── 20- Upper Confidence Bound ├── Ads_CTR_Optimisation.csv ├── UCB.py └── random_selection.py ├── 21-Thompson_Sampling ├── Ads_CTR_Optimisation.csv ├── thompson_sampling.py └── thompson_sampling_Colab.ipynb ├── 22- Natural_Language_Processing ├── NLP.py ├── Restaurant_Reviews.tsv └── natural_language_processing_Colab.ipynb ├── 23- Artificial_Neural_Networks ├── ANN.py ├── Churn_Modelling.csv ├── Stochastic_Gradient_Descent.png └── ann_Colab.ipynb ├── 24- Convolutional_Neural_Networks ├── CNN.py └── cnn_Colab.ipynb ├── 25- PCA ├── Juices.csv ├── PCA.py └── pca_Colab.ipynb ├── 26- LDA ├── Juices.csv ├── LDA.py └── lda_Colab.ipynb ├── 27- Kernel_PCA ├── Social_Network_Ads.csv ├── kernel_pca.py └── kernel_pca_Colab.ipynb ├── 28- Model_Selection ├── Grid_search.py ├── Grid_search_Colab.ipynb ├── K_fold_cross.py ├── K_fold_cross_Colab.ipynb └── Social_Network_Ads.csv ├── 29- Kernel_SVM ├── Kernel_SVM_Colab.ipynb └── Social_Network_Ads.csv ├── 30- XGBoost ├── Churn_Modelling.csv ├── XGBoost.py ├── XGBoost_Colab.ipynb ├── XGBoost_installation_Test.py └── xgboost+installation.pdf ├── Machine-Learning-A-Z-Q-A.pdf └── README.md /01- Numpy/NumPy_Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/01- Numpy/NumPy_Notes.pdf -------------------------------------------------------------------------------- /02- Pandas/Pandas_Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/02- Pandas/Pandas_Notes.pdf -------------------------------------------------------------------------------- /03- Data Reprocessing/Data.csv: -------------------------------------------------------------------------------- 1 | Country,Age,Salary,Purchased 2 | France,44,72000,No 3 | Spain,27,48000,Yes 4 | Germany,30,54000,No 5 | Spain,38,61000,No 6 | Germany,40,,Yes 7 | France,35,58000,Yes 8 | Spain,,52000,No 9 | France,48,79000,Yes 10 | Germany,50,83000,No 11 | France,37,67000,Yes -------------------------------------------------------------------------------- /03- Data Reprocessing/data_preprocessing_template -Full.py: -------------------------------------------------------------------------------- 1 | 2 | # Data Preprocessing Template: 3 | 4 | # Importing the libraries: 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | import pandas as pd 8 | 9 | # Importing the dataset 10 | data = pd.read_csv('Data.csv') 11 | X = data.iloc[:,:3].values 12 | y = data.iloc[:,-1].values 13 | 14 | 15 | # Scikit learn library: handling missing values 16 | from sklearn.impute import SimpleImputer 17 | # strategy can be: mean , median , most_frequent 18 | imputer = SimpleImputer(missing_values=np.nan, strategy = 'mean') 19 | imputer = imputer.fit(X[:,1:3]) 20 | X[:,1:3] = imputer.transform(X[:,1:3]) 21 | 22 | 23 | # Encoding categorical data from Labels into continious 0 1: 24 | from sklearn.preprocessing import LabelEncoder , OneHotEncoder 25 | from sklearn.compose import ColumnTransformer 26 | 27 | # The new method doesn't require to use LabelEncoder and you can make it by two lines 28 | ct_X = ColumnTransformer([('0', OneHotEncoder(), [0])], remainder = 'passthrough') 29 | X = ct_X.fit_transform(X) 30 | 31 | LabelEncoder_y = LabelEncoder() 32 | y= LabelEncoder_y.fit_transform(y) 33 | 34 | 35 | # Splitting the dataset into training set and test set : 36 | from sklearn.model_selection import train_test_split 37 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 38 | 39 | # Features Scaling 40 | from sklearn.preprocessing import StandardScaler 41 | sc_X = StandardScaler() 42 | X_train = sc_X.fit_transform(X_train) 43 | X_test = sc_X.fit_transform(X_test) -------------------------------------------------------------------------------- /03- Data Reprocessing/data_preprocessing_template.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"data_preprocessing_template.ipynb","provenance":[],"collapsed_sections":[],"toc_visible":true,"authorship_tag":"ABX9TyOD2/gZgY69JdiiGJVNfu7s"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"WOw8yMd1VlnD","colab_type":"text"},"source":["# Data Preprocessing Template"]},{"cell_type":"markdown","metadata":{"id":"NvUGC8QQV6bV","colab_type":"text"},"source":["## Importing the libraries"]},{"cell_type":"code","metadata":{"id":"wfFEXZC0WS-V","colab_type":"code","colab":{}},"source":["import numpy as np\n","import matplotlib.pyplot as plt\n","import pandas as pd"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"fhYaZ-ENV_c5","colab_type":"text"},"source":["## Importing the dataset"]},{"cell_type":"code","metadata":{"id":"aqHTg9bxWT_u","colab_type":"code","colab":{}},"source":["dataset = pd.read_csv('Data.csv')\n","X = dataset.iloc[:, :-1].values\n","y = dataset.iloc[:, -1].values"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"3abSxRqvWEIB","colab_type":"text"},"source":["## Splitting the dataset into the Training set and Test set"]},{"cell_type":"code","metadata":{"id":"hm48sif-WWsh","colab_type":"code","colab":{}},"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.2, random_state = 0)"],"execution_count":0,"outputs":[]}]} -------------------------------------------------------------------------------- /03- Data Reprocessing/data_preprocessing_template.py: -------------------------------------------------------------------------------- 1 | 2 | # Data Preprocessing Template: 3 | 4 | # Importing the libraries: 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | import pandas as pd 8 | 9 | # Importing the dataset 10 | data = pd.read_csv('Data.csv') 11 | X = data.iloc[:,:3].values 12 | y = data.iloc[:,-1].values 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 17 | 18 | # Features Scaling 19 | """from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test)""" 23 | 24 | -------------------------------------------------------------------------------- /03- Data Reprocessing/data_preprocessing_tools.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Tools 2 | 3 | # Importing the libraries 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, -1].values 12 | print(X) 13 | print(y) 14 | 15 | # Taking care of missing data 16 | from sklearn.impute import SimpleImputer 17 | imputer = SimpleImputer(missing_values=np.nan, strategy='mean') 18 | imputer.fit(X[:, 1:3]) 19 | X[:, 1:3] = imputer.transform(X[:, 1:3]) 20 | print(X) 21 | 22 | # Encoding categorical data 23 | # Encoding the Independent Variable 24 | from sklearn.compose import ColumnTransformer 25 | from sklearn.preprocessing import OneHotEncoder 26 | ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [0])], remainder='passthrough') 27 | X = np.array(ct.fit_transform(X)) 28 | print(X) 29 | # Encoding the Dependent Variable 30 | from sklearn.preprocessing import LabelEncoder 31 | le = LabelEncoder() 32 | y = le.fit_transform(y) 33 | print(y) 34 | 35 | # Splitting the dataset into the Training set and Test set 36 | from sklearn.model_selection import train_test_split 37 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 1) 38 | print(X_train) 39 | print(X_test) 40 | print(y_train) 41 | print(y_test) 42 | 43 | # Feature Scaling 44 | from sklearn.preprocessing import StandardScaler 45 | sc = StandardScaler() 46 | X_train[:, 3:] = sc.fit_transform(X_train[:, 3:]) 47 | X_test[:, 3:] = sc.transform(X_test[:, 3:]) 48 | print(X_train) 49 | print(X_test) -------------------------------------------------------------------------------- /04-05- Simple Linear Regression/Salary_Data.csv: -------------------------------------------------------------------------------- 1 | YearsExperience,Salary 2 | 1.1,39343.00 3 | 1.3,46205.00 4 | 1.5,37731.00 5 | 2.0,43525.00 6 | 2.2,39891.00 7 | 2.9,56642.00 8 | 3.0,60150.00 9 | 3.2,54445.00 10 | 3.2,64445.00 11 | 3.7,57189.00 12 | 3.9,63218.00 13 | 4.0,55794.00 14 | 4.0,56957.00 15 | 4.1,57081.00 16 | 4.5,61111.00 17 | 4.9,67938.00 18 | 5.1,66029.00 19 | 5.3,83088.00 20 | 5.9,81363.00 21 | 6.0,93940.00 22 | 6.8,91738.00 23 | 7.1,98273.00 24 | 7.9,101302.00 25 | 8.2,113812.00 26 | 8.7,109431.00 27 | 9.0,105582.00 28 | 9.5,116969.00 29 | 9.6,112635.00 30 | 10.3,122391.00 31 | 10.5,121872.00 32 | -------------------------------------------------------------------------------- /04-05- Simple Linear Regression/Simple_Linear_Regression.py: -------------------------------------------------------------------------------- 1 | # Importing the libraries: 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import pandas as pd 5 | 6 | # Importing the dataset 7 | data = pd.read_csv('Salary_Data.csv') 8 | # Train set must be matrix because that I performed [:,0:1] 9 | X = data.iloc[:,0:1].values 10 | y = data.iloc[:,1].values 11 | 12 | # Splitting the dataset into training set and test set : 13 | from sklearn.model_selection import train_test_split 14 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 1/3 , random_state = 0) 15 | 16 | 17 | # Fitting Simple Linear Regression to the Training set 18 | from sklearn.linear_model import LinearRegression 19 | regressor = LinearRegression() 20 | regressor.fit(X_train,y_train) 21 | 22 | # Predicting the Test set result: 23 | y_pred = regressor.predict(X_test) 24 | y_pred_train = regressor.predict(X_train) 25 | 26 | # Visualising the Training set results 27 | plt.scatter(X_train, y_train, color = 'green') 28 | plt.plot(X_train, regressor.predict(X_train), color = 'blue') 29 | plt.title('Salary vs Experience (Training Set)') 30 | plt.xlabel('Experience in years') 31 | plt.ylabel('Salary in USD $') 32 | plt.show() 33 | 34 | # Visualising the Test set results 35 | plt.scatter(X_test, y_test, color = 'orange') 36 | plt.plot(X_train, regressor.predict(X_train), color = 'blue') 37 | plt.title('Salary vs Experience (Test Set)') 38 | plt.xlabel('Experience in years') 39 | plt.ylabel('Salary in USD $') 40 | plt.show() 41 | 42 | -------------------------------------------------------------------------------- /04-05- Simple Linear Regression/data_preprocessing_template.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Data.csv') 10 | X = data.iloc[:,:3].values 11 | y = data.iloc[:,-1].values 12 | 13 | # Splitting the dataset into training set and test set : 14 | from sklearn.model_selection import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 16 | 17 | # Features Scaling 18 | """from sklearn.preprocessing import StandardScaler 19 | sc_X = StandardScaler() 20 | X_train = sc_X.fit_transform(X_train) 21 | X_test = sc_X.fit_transform(X_test)""" 22 | 23 | -------------------------------------------------------------------------------- /06- Multiple Linear Regression Intuition/50_Startups.csv: -------------------------------------------------------------------------------- 1 | R&D Spend,Administration,Marketing Spend,State,Profit 2 | 165349.2,136897.8,471784.1,New York,192261.83 3 | 162597.7,151377.59,443898.53,California,191792.06 4 | 153441.51,101145.55,407934.54,Florida,191050.39 5 | 144372.41,118671.85,383199.62,New York,182901.99 6 | 142107.34,91391.77,366168.42,Florida,166187.94 7 | 131876.9,99814.71,362861.36,New York,156991.12 8 | 134615.46,147198.87,127716.82,California,156122.51 9 | 130298.13,145530.06,323876.68,Florida,155752.6 10 | 120542.52,148718.95,311613.29,New York,152211.77 11 | 123334.88,108679.17,304981.62,California,149759.96 12 | 101913.08,110594.11,229160.95,Florida,146121.95 13 | 100671.96,91790.61,249744.55,California,144259.4 14 | 93863.75,127320.38,249839.44,Florida,141585.52 15 | 91992.39,135495.07,252664.93,California,134307.35 16 | 119943.24,156547.42,256512.92,Florida,132602.65 17 | 114523.61,122616.84,261776.23,New York,129917.04 18 | 78013.11,121597.55,264346.06,California,126992.93 19 | 94657.16,145077.58,282574.31,New York,125370.37 20 | 91749.16,114175.79,294919.57,Florida,124266.9 21 | 86419.7,153514.11,0,New York,122776.86 22 | 76253.86,113867.3,298664.47,California,118474.03 23 | 78389.47,153773.43,299737.29,New York,111313.02 24 | 73994.56,122782.75,303319.26,Florida,110352.25 25 | 67532.53,105751.03,304768.73,Florida,108733.99 26 | 77044.01,99281.34,140574.81,New York,108552.04 27 | 64664.71,139553.16,137962.62,California,107404.34 28 | 75328.87,144135.98,134050.07,Florida,105733.54 29 | 72107.6,127864.55,353183.81,New York,105008.31 30 | 66051.52,182645.56,118148.2,Florida,103282.38 31 | 65605.48,153032.06,107138.38,New York,101004.64 32 | 61994.48,115641.28,91131.24,Florida,99937.59 33 | 61136.38,152701.92,88218.23,New York,97483.56 34 | 63408.86,129219.61,46085.25,California,97427.84 35 | 55493.95,103057.49,214634.81,Florida,96778.92 36 | 46426.07,157693.92,210797.67,California,96712.8 37 | 46014.02,85047.44,205517.64,New York,96479.51 38 | 28663.76,127056.21,201126.82,Florida,90708.19 39 | 44069.95,51283.14,197029.42,California,89949.14 40 | 20229.59,65947.93,185265.1,New York,81229.06 41 | 38558.51,82982.09,174999.3,California,81005.76 42 | 28754.33,118546.05,172795.67,California,78239.91 43 | 27892.92,84710.77,164470.71,Florida,77798.83 44 | 23640.93,96189.63,148001.11,California,71498.49 45 | 15505.73,127382.3,35534.17,New York,69758.98 46 | 22177.74,154806.14,28334.72,California,65200.33 47 | 1000.23,124153.04,1903.93,New York,64926.08 48 | 1315.46,115816.21,297114.46,Florida,49490.75 49 | 0,135426.92,0,California,42559.73 50 | 542.05,51743.15,0,New York,35673.41 51 | 0,116983.8,45173.06,California,14681.4 -------------------------------------------------------------------------------- /06- Multiple Linear Regression Intuition/Multiple_Linear_Regression_Colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Multiple_Linear_Regression_Colab.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "code", 18 | "metadata": { 19 | "id": "AZ2WadBmnm5H", 20 | "colab_type": "code", 21 | "colab": {} 22 | }, 23 | "source": [ 24 | "#import data (test CSV)\n", 25 | "from google.colab import drive\n", 26 | "drive.mount('/content/drive')" 27 | ], 28 | "execution_count": 0, 29 | "outputs": [] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "metadata": { 34 | "id": "a_dVGD5sn2k2", 35 | "colab_type": "code", 36 | "colab": {} 37 | }, 38 | "source": [ 39 | " #cd (change directory) to the file/folder location\n", 40 | " " 41 | ], 42 | "execution_count": 0, 43 | "outputs": [] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "metadata": { 48 | "id": "4LskbY47sPeX", 49 | "colab_type": "code", 50 | "colab": {} 51 | }, 52 | "source": [ 53 | "# Multiple Linear Regression\n", 54 | "\n", 55 | "# Importing the libraries\n", 56 | "import numpy as np\n", 57 | "import matplotlib.pyplot as plt\n", 58 | "import pandas as pd\n", 59 | "\n", 60 | "# Importing the dataset\n", 61 | "dataset = pd.read_csv('50_Startups.csv')\n", 62 | "X = dataset.iloc[:, :-1].values\n", 63 | "y = dataset.iloc[:, 4].values\n", 64 | "\n", 65 | "# Encoding categorical data\n", 66 | "from sklearn.preprocessing import OneHotEncoder\n", 67 | "from sklearn.compose import ColumnTransformer\n", 68 | "from sklearn.preprocessing import LabelEncoder\n", 69 | "labelencoder = LabelEncoder()\n", 70 | "X[:, 3] = labelencoder.fit_transform(X[:, 3])\n", 71 | "ct =ColumnTransformer([('encoder', OneHotEncoder(), [3])],\n", 72 | "remainder='passthrough')\n", 73 | "X= np.array(ct.fit_transform(X), dtype=np.float)\n", 74 | "\n", 75 | "# Avoiding the Dummy Variable Trap\n", 76 | "X = X[:, 1:]\n", 77 | "\n", 78 | "# Splitting the dataset into the Training set and Test set\n", 79 | "from sklearn.model_selection import train_test_split\n", 80 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)\n", 81 | "\n", 82 | "# Feature Scaling\n", 83 | "\"\"\"from sklearn.preprocessing import StandardScaler\n", 84 | "sc_X = StandardScaler()\n", 85 | "X_train = sc_X.fit_transform(X_train)\n", 86 | "X_test = sc_X.transform(X_test)\n", 87 | "sc_y = StandardScaler()\n", 88 | "y_train = sc_y.fit_transform(y_train)\"\"\"\n", 89 | "\n", 90 | "# Fitting Multiple Linear Regression to the Training set\n", 91 | "from sklearn.linear_model import LinearRegression\n", 92 | "regressor = LinearRegression()\n", 93 | "regressor.fit(X_train, y_train)\n", 94 | "\n", 95 | "# Predicting the Test set results\n", 96 | "y_pred = regressor.predict(X_test)" 97 | ], 98 | "execution_count": 0, 99 | "outputs": [] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "metadata": { 104 | "id": "Ae2iFe3Rn2iO", 105 | "colab_type": "code", 106 | "colab": {} 107 | }, 108 | "source": [ 109 | "print (y_pred)" 110 | ], 111 | "execution_count": 0, 112 | "outputs": [] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "metadata": { 117 | "id": "tPXrnm0Dn2ek", 118 | "colab_type": "code", 119 | "colab": {} 120 | }, 121 | "source": [ 122 | "" 123 | ], 124 | "execution_count": 0, 125 | "outputs": [] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "metadata": { 130 | "id": "W6My8YVOpFYl", 131 | "colab_type": "code", 132 | "colab": {} 133 | }, 134 | "source": [ 135 | "" 136 | ], 137 | "execution_count": 0, 138 | "outputs": [] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "metadata": { 143 | "id": "J6epjyw1pFgc", 144 | "colab_type": "code", 145 | "colab": {} 146 | }, 147 | "source": [ 148 | "" 149 | ], 150 | "execution_count": 0, 151 | "outputs": [] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "metadata": { 156 | "id": "spYXA5FApFpd", 157 | "colab_type": "code", 158 | "colab": {} 159 | }, 160 | "source": [ 161 | "" 162 | ], 163 | "execution_count": 0, 164 | "outputs": [] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "metadata": { 169 | "id": "0guxKKH0pFnv", 170 | "colab_type": "code", 171 | "colab": {} 172 | }, 173 | "source": [ 174 | "" 175 | ], 176 | "execution_count": 0, 177 | "outputs": [] 178 | } 179 | ] 180 | } -------------------------------------------------------------------------------- /06- Multiple Linear Regression Intuition/data_preprocessing_template.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('50_Startups.csv') 10 | X = data.iloc[:,:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Encoding categorical data from Labels into continious 0 1: 15 | from sklearn.preprocessing import LabelEncoder , OneHotEncoder 16 | from sklearn.compose import ColumnTransformer 17 | 18 | # The new method doesn't require to use LabelEncoder and you can make it by two lines 19 | ct_X = ColumnTransformer([('3', OneHotEncoder(), [3])], remainder = 'passthrough') 20 | X = ct_X.fit_transform(X) 21 | 22 | # Avoiding Dummy Variable Trap: 23 | X = X[:,1:] 24 | # Splitting the dataset into training set and test set : 25 | from sklearn.model_selection import train_test_split 26 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 27 | 28 | 29 | # Fitting Multiple Linear Regression to the training set 30 | from sklearn.linear_model import LinearRegression 31 | regressor = LinearRegression() 32 | regressor.fit(X_train, y_train) 33 | 34 | # Predecting the Test set values: 35 | y_pred = regressor.predict(X_test) 36 | 37 | 38 | '''Note: we can't visulaize the data because it has a lot of 39 | independent variabbles (features) in contrast of single linear 40 | regression which has one feature and one output 41 | So compare manually between y_pred & y_test ! ''' 42 | 43 | 44 | # Building the optimal model using Backward elimination: 45 | 46 | #X = np.append(arr = X , values = np.ones((50,1)).astype(int) , axis = 1 ) 47 | # a small trick to make the b0 variable at the begining of our dataset: 48 | X = np.append(arr = np.ones((50,1)).astype(int) , values = X , axis = 1 ) 49 | 50 | import statsmodels.api as sm 51 | X_opt = np.array(X[:,[0,1,2,3,4,5]],dtype = float) 52 | regressor_OLS = sm.OLS(endog = y, exog=X_opt).fit() 53 | print(regressor_OLS.summary()) 54 | 55 | X_opt = np.array(X[:,[0,1,3,4,5]],dtype = float) 56 | regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit() 57 | print(regressor_OLS.summary()) 58 | 59 | X_opt = np.array(X[:,[0,3,4,5]],dtype = float) 60 | regressor_OLS = sm.OLS(endog = y, exog =X_opt).fit() 61 | print(regressor_OLS.summary()) 62 | 63 | X_opt = np.array(X[:,[0,3,5]],dtype = float) 64 | regressor_OLS = sm.OLS(endog = y, exog =X_opt).fit() 65 | print(regressor_OLS.summary()) 66 | 67 | X_opt = np.array(X[:,[0,3]],dtype = float) 68 | regressor_OLS = sm.OLS(endog = y, exog =X_opt).fit() 69 | print(regressor_OLS.summary()) 70 | 71 | -------------------------------------------------------------------------------- /07- Polynomial Regression/Position_Salaries.csv: -------------------------------------------------------------------------------- 1 | Position,Level,Salary 2 | Business Analyst,1,45000 3 | Junior Consultant,2,50000 4 | Senior Consultant,3,60000 5 | Manager,4,80000 6 | Country Manager,5,110000 7 | Region Manager,6,150000 8 | Partner,7,200000 9 | Senior Partner,8,300000 10 | C-level,9,500000 11 | CEO,10,1000000 -------------------------------------------------------------------------------- /07- Polynomial Regression/Regression_Template.py: -------------------------------------------------------------------------------- 1 | #Regression Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Data.csv') 10 | X = data.iloc[:,1:2].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | ''' 16 | from sklearn.model_selection import train_test_split 17 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 18 | ''' 19 | 20 | # Features Scaling 21 | """from sklearn.preprocessing import StandardScaler 22 | sc_X = StandardScaler() 23 | X_train = sc_X.fit_transform(X_train) 24 | X_test = sc_X.fit_transform(X_test)""" 25 | 26 | # Fitting The Regression model with the Dataset: 27 | 28 | 29 | 30 | # Prediction a new value 31 | print(regressor.predict([[6.5]])) 32 | 33 | 34 | # Visulaization of the Regression Model 35 | plt.scatter(X,y, color = 'red') 36 | plt.plot(X,regressor.predict(X), color = 'blue') 37 | plt.title('Truth or bluff (Regression Model)') 38 | plt.xlabel('X-axis') 39 | plt.ylabel('Y-axis') 40 | plt.show() 41 | 42 | X_grid = np.arange(min(X), max(X)+0.1, 0.1) 43 | X_grid = X_grid.reshape(len(X_grid),1) 44 | plt.scatter(X,y) 45 | plt.plot(X_grid,lin_reg_2.predict(poly_reg.fit_transform(X_grid)), color = 'orange') 46 | plt.title('Truth or bluff (Polynomial Regression)') 47 | plt.xlabel('Position Level') 48 | plt.ylabel('Salary') 49 | plt.show() 50 | 51 | 52 | # Better Visulaization of the Regression Model 53 | X_grid = np.arange(min(X), max(X)+0.1, 0.1) 54 | X_grid = X_grid.reshape(len(X_grid),1) 55 | 56 | plt.scatter(X,y) 57 | plt.plot(X_grid,lin_reg_2.predict(poly_reg.fit_transform(X_grid)), color = 'orange') 58 | 59 | plt.title('Truth or bluff (Regression Model)') 60 | plt.xlabel('X-axis') 61 | plt.ylabel('Y-axis') 62 | plt.show() -------------------------------------------------------------------------------- /07- Polynomial Regression/data_preprocessing_template.py: -------------------------------------------------------------------------------- 1 | 2 | # Data Preprocessing Template: 3 | 4 | # Importing the libraries: 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | import pandas as pd 8 | 9 | # Importing the dataset 10 | data = pd.read_csv('Position_Salaries.csv') 11 | X = data.iloc[:,1:2].values 12 | y = data.iloc[:,-1].values 13 | 14 | 15 | ''' 16 | # Splitting the dataset into training set and test set : 17 | from sklearn.model_selection import train_test_split 18 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 19 | ''' 20 | 21 | # Features Scaling 22 | """from sklearn.preprocessing import StandardScaler 23 | sc_X = StandardScaler() 24 | X_train = sc_X.fit_transform(X_train) 25 | X_test = sc_X.fit_transform(X_test)""" 26 | 27 | # Fitting Linear Regression Model: 28 | from sklearn.linear_model import LinearRegression 29 | lin_reg = LinearRegression() 30 | lin_reg.fit(X,y) 31 | 32 | 33 | 34 | # Fitting Polynomyal Regression Model: 35 | from sklearn.preprocessing import PolynomialFeatures 36 | poly_reg = PolynomialFeatures(degree = 4) 37 | X_poly = poly_reg.fit_transform(X) 38 | lin_reg_2 = LinearRegression() 39 | lin_reg_2.fit(X_poly,y) 40 | 41 | 42 | # Visulaization the Linear Regression Model 43 | plt.scatter(X,y, color = 'red') 44 | plt.plot(X,lin_reg.predict(X), color = 'blue') 45 | plt.title('Truth or bluff (linear Regression)') 46 | plt.xlabel('Position Level') 47 | plt.ylabel('Salary') 48 | plt.show() 49 | 50 | # Visulaization the Polynomial Regression Model 51 | plt.scatter(X,y, color = 'red') 52 | plt.plot(X,lin_reg_2.predict(poly_reg.fit_transform(X)), color = 'blue') 53 | plt.title('Truth or bluff (Polynomial Regression)') 54 | plt.xlabel('Position Level') 55 | plt.ylabel('Salary') 56 | plt.show() 57 | 58 | # Visulaization the Polynomial Regression Model with better curvature: 59 | X_grid = np.arange(min(X), max(X)+0.1, 0.1) 60 | X_grid = X_grid.reshape(len(X_grid),1) 61 | plt.scatter(X,y) 62 | plt.plot(X_grid,lin_reg_2.predict(poly_reg.fit_transform(X_grid)), color = 'orange') 63 | plt.title('Truth or bluff (Polynomial Regression)') 64 | plt.xlabel('Position Level') 65 | plt.ylabel('Salary') 66 | plt.show() 67 | 68 | 69 | # Prediction a new value for a person with 6.5 level and claim that he deserves 160k$ 70 | 71 | # By Using Simple Linear Regression: 72 | print('The person deserves by Simple Linear Regression:') 73 | print(lin_reg.predict([[6.5]])) 74 | 75 | # By Using Polynomial Linear Regression: 76 | print('The person deserves by Polynomial Linear Regression:') 77 | print(lin_reg_2.predict(poly_reg.fit_transform([[6.5]]))) 78 | 79 | 80 | -------------------------------------------------------------------------------- /08- Support Vector Regression (SVR)/Position_Salaries.csv: -------------------------------------------------------------------------------- 1 | Position,Level,Salary 2 | Business Analyst,1,45000 3 | Junior Consultant,2,50000 4 | Senior Consultant,3,60000 5 | Manager,4,80000 6 | Country Manager,5,110000 7 | Region Manager,6,150000 8 | Partner,7,200000 9 | Senior Partner,8,300000 10 | C-level,9,500000 11 | CEO,10,1000000 -------------------------------------------------------------------------------- /08- Support Vector Regression (SVR)/SVR_Regression_Template.py: -------------------------------------------------------------------------------- 1 | #Regression Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Position_Salaries.csv') 10 | X = data.iloc[:,1:2].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | 16 | from sklearn.model_selection import train_test_split 17 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 18 | ''' 19 | ''' 20 | # Features Scaling 21 | from sklearn.preprocessing import StandardScaler 22 | sc_X = StandardScaler() 23 | sc_y = StandardScaler() 24 | 25 | X = sc_X.fit_transform(X) 26 | y = np.ravel(sc_y.fit_transform(y.reshape(-1,1))) 27 | 28 | 29 | # Fitting The SVR model with the Dataset: 30 | from sklearn.svm import SVR 31 | regressor = SVR(kernel='rbf') 32 | regressor.fit(X,y) 33 | 34 | # Prediction a new value 35 | y_pred = regressor.predict(sc_X.transform([[6.5]])) 36 | print(y_pred) 37 | print(sc_y.inverse_transform(y_pred)) 38 | 39 | 40 | # Visulaization of the Regression Model 41 | plt.scatter(X,y, color = 'red') 42 | plt.plot(X,regressor.predict(X), color = 'blue') 43 | plt.title('Truth or bluff (Regression Model)') 44 | plt.xlabel('X-axis') 45 | plt.ylabel('Y-axis') 46 | plt.show() 47 | 48 | -------------------------------------------------------------------------------- /09- Decision_Tree_Regression/Decision_Tree_Regression.py: -------------------------------------------------------------------------------- 1 | #Regression Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Position_Salaries.csv') 10 | X = data.iloc[:,1:2].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | ''' 16 | from sklearn.model_selection import train_test_split 17 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 18 | ''' 19 | 20 | ''' 21 | # Features Scaling 22 | from sklearn.preprocessing import StandardScaler 23 | sc_X = StandardScaler() 24 | sc_y = StandardScaler() 25 | 26 | X = sc_X.fit_transform(X) 27 | y = np.ravel(sc_y.fit_transform(y.reshape(-1,1))) 28 | ''' 29 | 30 | # Fitting The Decision Tree model with the Dataset: 31 | from sklearn.tree import DecisionTreeRegressor 32 | regressor = DecisionTreeRegressor(random_state = 0) 33 | regressor.fit(X,y) 34 | 35 | 36 | # Prediction a new value 37 | y_pred = regressor.predict([[6.5]]) 38 | print(y_pred) 39 | 40 | 41 | # Visulaization of the Decision_Tree Model 42 | X_grid = np.arange(min(X), max(X)+0.1, 0.1) 43 | X_grid = X_grid.reshape(len(X_grid),1) 44 | plt.scatter(X,y) 45 | plt.plot(X_grid,regressor.predict(X_grid), color = 'orange') 46 | plt.title('Truth or bluff (Polynomial Regression)') 47 | plt.xlabel('Position Level') 48 | plt.ylabel('Salary') 49 | plt.show() 50 | 51 | 52 | -------------------------------------------------------------------------------- /09- Decision_Tree_Regression/Position_Salaries.csv: -------------------------------------------------------------------------------- 1 | Position,Level,Salary 2 | Business Analyst,1,45000 3 | Junior Consultant,2,50000 4 | Senior Consultant,3,60000 5 | Manager,4,80000 6 | Country Manager,5,110000 7 | Region Manager,6,150000 8 | Partner,7,200000 9 | Senior Partner,8,300000 10 | C-level,9,500000 11 | CEO,10,1000000 -------------------------------------------------------------------------------- /10- Random Forest/Position_Salaries.csv: -------------------------------------------------------------------------------- 1 | Position,Level,Salary 2 | Business Analyst,1,45000 3 | Junior Consultant,2,50000 4 | Senior Consultant,3,60000 5 | Manager,4,80000 6 | Country Manager,5,110000 7 | Region Manager,6,150000 8 | Partner,7,200000 9 | Senior Partner,8,300000 10 | C-level,9,500000 11 | CEO,10,1000000 -------------------------------------------------------------------------------- /10- Random Forest/Random Forest Regressor.py: -------------------------------------------------------------------------------- 1 | #Random Forest Regressor Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Position_Salaries.csv') 10 | X = data.iloc[:,1:2].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | ''' 16 | from sklearn.model_selection import train_test_split 17 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = .2, random_state = 0) 18 | ''' 19 | 20 | ''' 21 | # Features Scaling 22 | from sklearn.preprocessing import StandardScaler 23 | sc_X = StandardScaler() 24 | sc_y = StandardScaler() 25 | 26 | X = sc_X.fit_transform(X) 27 | y = np.ravel(sc_y.fit_transform(y.reshape(-1,1))) 28 | ''' 29 | 30 | # Fitting The Random Forest Regressor model with the Dataset: 31 | from sklearn.ensemble import RandomForestRegressor 32 | regressor = RandomForestRegressor(n_estimators = 277,criterion="mse", random_state = 0) 33 | regressor.fit(X,y) 34 | 35 | 36 | # Prediction a new value 37 | y_pred = regressor.predict([[6.5]]) 38 | print(y_pred) 39 | 40 | 41 | # Visulaization of the Random Forest Regressor 42 | 43 | X_grid = np.arange(min(X), max(X), 0.1) 44 | X_grid = X_grid.reshape(len(X_grid),1) 45 | plt.scatter(X,y) 46 | plt.plot(X_grid,regressor.predict(X_grid), color = 'orange') 47 | plt.title('Truth or bluff (Random Forest Regressor)') 48 | plt.xlabel('Position Level') 49 | plt.ylabel('Salary') 50 | plt.show() 51 | 52 | 53 | -------------------------------------------------------------------------------- /11- Logistic_Regression/Classifer_template.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | 28 | 29 | # Fitting the classifier model to training dataset: 30 | 31 | 32 | 33 | 34 | 35 | # Predection Process: 36 | y_pred = 37 | 38 | 39 | 40 | # Confusion Matrix: 41 | from sklearn.metrics import confusion_matrix 42 | cm = confusion_matrix(y_test, y_pred) 43 | 44 | # Visulaization the training set results 45 | from matplotlib.colors import ListedColormap 46 | X_set, y_set = X_train , y_train 47 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 48 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 49 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 50 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 51 | plt.xlim(x1.min(), x1.max()) 52 | plt.ylim(x2.min(), x2.max()) 53 | 54 | for i,j in enumerate(np.unique(y_set)): 55 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 56 | c = ListedColormap(('red','green')) (i), label = j) 57 | plt.title('Classifier (Training set)') 58 | plt.xlabel('Age') 59 | plt.ylabel('Estimated Salary') 60 | plt.legend() 61 | plt.show() 62 | 63 | 64 | # Visulaization the training set results 65 | from matplotlib.colors import ListedColormap 66 | X_set, y_set = X_test , y_test 67 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 68 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 69 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 70 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 71 | plt.xlim(x1.min(), x1.max()) 72 | plt.ylim(x2.min(), x2.max()) 73 | 74 | for i,j in enumerate(np.unique(y_set)): 75 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 76 | c = ListedColormap(('red','green')) (i), label = j) 77 | plt.title('Classifier (Training set)') 78 | plt.xlabel('Age') 79 | plt.ylabel('Estimated Salary') 80 | plt.legend() 81 | plt.show() -------------------------------------------------------------------------------- /11- Logistic_Regression/Logistic_regression_template .py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | # Fitting the Logistic Regression model to training dataset: 27 | from sklearn.linear_model import LogisticRegression 28 | classifier = LogisticRegression(random_state = 0) 29 | classifier.fit(X_train, y_train) 30 | 31 | # Predection Process: 32 | y_pred = classifier.predict(X_test) 33 | 34 | # Confusion Matrix: 35 | from sklearn.metrics import confusion_matrix 36 | cm = confusion_matrix(y_test, y_pred) 37 | 38 | # Visulaization the training set results 39 | from matplotlib.colors import ListedColormap 40 | X_set, y_set = X_train , y_train 41 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 42 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 43 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 44 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 45 | plt.xlim(x1.min(), x1.max()) 46 | plt.ylim(x2.min(), x2.max()) 47 | 48 | for i,j in enumerate(np.unique(y_set)): 49 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 50 | c = ListedColormap(('red','green')) (i), label = j) 51 | plt.title('Classifier (Training set)') 52 | plt.xlabel('Age') 53 | plt.ylabel('Estimated Salary') 54 | plt.legend() 55 | plt.show() 56 | 57 | 58 | # Visulaization the training set results 59 | from matplotlib.colors import ListedColormap 60 | X_set, y_set = X_test , y_test 61 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 62 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 63 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 64 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 65 | plt.xlim(x1.min(), x1.max()) 66 | plt.ylim(x2.min(), x2.max()) 67 | 68 | for i,j in enumerate(np.unique(y_set)): 69 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 70 | c = ListedColormap(('red','green')) (i), label = j) 71 | plt.title('Classifier (Training set)') 72 | plt.xlabel('Age') 73 | plt.ylabel('Estimated Salary') 74 | plt.legend() 75 | plt.show() 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /11- Logistic_Regression/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000,0 216 | 15622478,Male,47,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /12- K_Nearest_Neighbors/KNN_template.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | 28 | 29 | # Fitting the Classifer model to training dataset: 30 | from sklearn.neighbors import KNeighborsClassifier 31 | # 'minkowski' = p2 [ Eculidean Distance ] 32 | classifier = KNeighborsClassifier(n_neighbors = 5 , metric = 'minkowski', p = 2) 33 | classifier.fit(X_train, y_train) 34 | 35 | # Predection Process: 36 | y_pred = classifier.predict(X_test) 37 | 38 | 39 | # Confusion Matrix: 40 | from sklearn.metrics import confusion_matrix 41 | cm = confusion_matrix(y_test, y_pred) 42 | 43 | # Visulaization the training set results 44 | from matplotlib.colors import ListedColormap 45 | X_set, y_set = X_train , y_train 46 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 47 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 48 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 49 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 50 | plt.xlim(x1.min(), x1.max()) 51 | plt.ylim(x2.min(), x2.max()) 52 | 53 | for i,j in enumerate(np.unique(y_set)): 54 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 55 | c = ListedColormap(('red','green')) (i), label = j) 56 | plt.title('KNN (Training set)') 57 | plt.xlabel('Age') 58 | plt.ylabel('Estimated Salary') 59 | plt.legend() 60 | plt.show() 61 | 62 | 63 | # Visulaization the training set results 64 | from matplotlib.colors import ListedColormap 65 | X_set, y_set = X_test , y_test 66 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 67 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 68 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 69 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 70 | plt.xlim(x1.min(), x1.max()) 71 | plt.ylim(x2.min(), x2.max()) 72 | 73 | for i,j in enumerate(np.unique(y_set)): 74 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 75 | c = ListedColormap(('red','green')) (i), label = j) 76 | plt.title('KNN (Training set)') 77 | plt.xlabel('Age') 78 | plt.ylabel('Estimated Salary') 79 | plt.legend() 80 | plt.show() -------------------------------------------------------------------------------- /12- K_Nearest_Neighbors/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000,0 216 | 15622478,Male,47,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /13- SVM/SVM_template.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | 28 | 29 | # Fitting the SVM model to training dataset: 30 | from sklearn.svm import SVC 31 | # Kernel = 'linear' or 'rbf' (more acurate) 32 | classifier = SVC(kernel='rbf', random_state = 0) 33 | classifier.fit(X_train, y_train) 34 | 35 | 36 | 37 | 38 | # Predection Process: 39 | y_pred = classifier.predict(X_test) 40 | 41 | 42 | 43 | # Confusion Matrix: 44 | from sklearn.metrics import confusion_matrix 45 | cm = confusion_matrix(y_test, y_pred) 46 | 47 | # Visulaization the training set results 48 | from matplotlib.colors import ListedColormap 49 | X_set, y_set = X_train , y_train 50 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 51 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 52 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 53 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 54 | plt.xlim(x1.min(), x1.max()) 55 | plt.ylim(x2.min(), x2.max()) 56 | 57 | for i,j in enumerate(np.unique(y_set)): 58 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 59 | c = ListedColormap(('red','green')) (i), label = j) 60 | plt.title('SVM (Training set)') 61 | plt.xlabel('Age') 62 | plt.ylabel('Estimated Salary') 63 | plt.legend() 64 | plt.show() 65 | 66 | 67 | # Visulaization the training set results 68 | from matplotlib.colors import ListedColormap 69 | X_set, y_set = X_test , y_test 70 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 71 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 72 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 73 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 74 | plt.xlim(x1.min(), x1.max()) 75 | plt.ylim(x2.min(), x2.max()) 76 | 77 | for i,j in enumerate(np.unique(y_set)): 78 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 79 | c = ListedColormap(('red','green')) (i), label = j) 80 | plt.title('SVM (Test set)') 81 | plt.xlabel('Age') 82 | plt.ylabel('Estimated Salary') 83 | plt.legend() 84 | plt.show() -------------------------------------------------------------------------------- /13- SVM/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000,0 216 | 15622478,Male,47,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /14- Naive_Bayes/NB.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | 28 | 29 | # Fitting the SVM model to training dataset: 30 | from sklearn.naive_bayes import GaussianNB 31 | classifier = GaussianNB() 32 | classifier.fit(X_train,y_train) 33 | 34 | 35 | # Predection Process: 36 | y_pred = classifier.predict(X_test) 37 | 38 | 39 | 40 | # Confusion Matrix: 41 | from sklearn.metrics import confusion_matrix 42 | cm = confusion_matrix(y_test, y_pred) 43 | 44 | # Visulaization the training set results 45 | from matplotlib.colors import ListedColormap 46 | X_set, y_set = X_train , y_train 47 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 48 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 49 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 50 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 51 | plt.xlim(x1.min(), x1.max()) 52 | plt.ylim(x2.min(), x2.max()) 53 | 54 | for i,j in enumerate(np.unique(y_set)): 55 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 56 | c = ListedColormap(('red','green')) (i), label = j) 57 | plt.title('Navie Bayes (Training set)') 58 | plt.xlabel('Age') 59 | plt.ylabel('Estimated Salary') 60 | plt.legend() 61 | plt.show() 62 | 63 | 64 | # Visulaization the training set results 65 | from matplotlib.colors import ListedColormap 66 | X_set, y_set = X_test , y_test 67 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 68 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 69 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 70 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 71 | plt.xlim(x1.min(), x1.max()) 72 | plt.ylim(x2.min(), x2.max()) 73 | 74 | for i,j in enumerate(np.unique(y_set)): 75 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 76 | c = ListedColormap(('blue','orange')) (i), label = j) 77 | plt.title('Navie Bayes (Training set)') 78 | plt.xlabel('Age') 79 | plt.ylabel('Estimated Salary') 80 | plt.legend() 81 | plt.show() -------------------------------------------------------------------------------- /14- Naive_Bayes/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000,0 216 | 15622478,Male,47,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /15- Decision_Tree_Classification/Decision_Tree_Classification.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | 28 | 29 | # Fitting the Decision Tree Classification model to training dataset: 30 | from sklearn.tree import DecisionTreeClassifier 31 | classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0) 32 | classifier.fit(X_train, y_train) 33 | 34 | 35 | # Predection Process: 36 | y_pred = classifier.predict(X_test) 37 | 38 | 39 | 40 | # Confusion Matrix: 41 | from sklearn.metrics import confusion_matrix 42 | cm = confusion_matrix(y_test, y_pred) 43 | 44 | # Visulaization the training set results 45 | from matplotlib.colors import ListedColormap 46 | X_set, y_set = X_train , y_train 47 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 48 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 49 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 50 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 51 | plt.xlim(x1.min(), x1.max()) 52 | plt.ylim(x2.min(), x2.max()) 53 | 54 | for i,j in enumerate(np.unique(y_set)): 55 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 56 | c = ListedColormap(('red','green')) (i), label = j) 57 | plt.title('Decision Tree Classification (Training set)') 58 | plt.xlabel('Age') 59 | plt.ylabel('Estimated Salary') 60 | plt.legend() 61 | plt.show() 62 | 63 | 64 | # Visulaization the training set results 65 | from matplotlib.colors import ListedColormap 66 | X_set, y_set = X_test , y_test 67 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 68 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 69 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 70 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 71 | plt.xlim(x1.min(), x1.max()) 72 | plt.ylim(x2.min(), x2.max()) 73 | 74 | for i,j in enumerate(np.unique(y_set)): 75 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 76 | c = ListedColormap(('red','green')) (i), label = j) 77 | plt.title('Decision Tree Classification (Test set)') 78 | plt.xlabel('Age') 79 | plt.ylabel('Estimated Salary') 80 | plt.legend() 81 | plt.show() -------------------------------------------------------------------------------- /16- Random_Forest_Classification/random_forest_classification.R: -------------------------------------------------------------------------------- 1 | # Random Forest Classification 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Social_Network_Ads.csv') 5 | dataset = dataset[3:5] 6 | 7 | # Encoding the target feature as factor 8 | dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1)) 9 | 10 | # Splitting the dataset into the Training set and Test set 11 | # install.packages('caTools') 12 | library(caTools) 13 | set.seed(123) 14 | split = sample.split(dataset$Purchased, SplitRatio = 0.75) 15 | training_set = subset(dataset, split == TRUE) 16 | test_set = subset(dataset, split == FALSE) 17 | 18 | # Feature Scaling 19 | training_set[-3] = scale(training_set[-3]) 20 | test_set[-3] = scale(test_set[-3]) 21 | 22 | # Fitting Random Forest Classification to the Training set 23 | # install.packages('randomForest') 24 | library(randomForest) 25 | set.seed(123) 26 | classifier = randomForest(x = training_set[-3], 27 | y = training_set$Purchased, 28 | ntree = 500) 29 | 30 | # Predicting the Test set results 31 | y_pred = predict(classifier, newdata = test_set[-3]) 32 | 33 | # Making the Confusion Matrix 34 | cm = table(test_set[, 3], y_pred) 35 | 36 | # Visualising the Training set results 37 | library(ElemStatLearn) 38 | set = training_set 39 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 40 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 41 | grid_set = expand.grid(X1, X2) 42 | colnames(grid_set) = c('Age', 'EstimatedSalary') 43 | y_grid = predict(classifier, grid_set) 44 | plot(set[, -3], 45 | main = 'Random Forest Classification (Training set)', 46 | xlab = 'Age', ylab = 'Estimated Salary', 47 | xlim = range(X1), ylim = range(X2)) 48 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 49 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 50 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 51 | 52 | # Visualising the Test set results 53 | library(ElemStatLearn) 54 | set = test_set 55 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 56 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 57 | grid_set = expand.grid(X1, X2) 58 | colnames(grid_set) = c('Age', 'EstimatedSalary') 59 | y_grid = predict(classifier, grid_set) 60 | plot(set[, -3], main = 'Random Forest Classification (Test set)', 61 | xlab = 'Age', ylab = 'Estimated Salary', 62 | xlim = range(X1), ylim = range(X2)) 63 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 64 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 65 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 66 | 67 | # Choosing the number of trees 68 | plot(classifier) -------------------------------------------------------------------------------- /16- Random_Forest_Classification/random_forest_classification.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | 28 | 29 | # Fitting the Decision Tree Classification model to training dataset: 30 | from sklearn.ensemble import RandomForestClassifier 31 | classifier = RandomForestClassifier(n_estimators = 10 ,criterion = 'entropy',random_state = 0 ) 32 | classifier.fit(X_train, y_train) 33 | 34 | 35 | 36 | # Predection Process: 37 | y_pred = classifier.predict(X_test) 38 | 39 | 40 | 41 | # Confusion Matrix: 42 | from sklearn.metrics import confusion_matrix 43 | cm = confusion_matrix(y_test, y_pred) 44 | 45 | # Visulaization the training set results 46 | from matplotlib.colors import ListedColormap 47 | X_set, y_set = X_train , y_train 48 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 49 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 50 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 51 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 52 | plt.xlim(x1.min(), x1.max()) 53 | plt.ylim(x2.min(), x2.max()) 54 | 55 | for i,j in enumerate(np.unique(y_set)): 56 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 57 | c = ListedColormap(('red','green')) (i), label = j) 58 | plt.title('Decision Tree Classification (Training set)') 59 | plt.xlabel('Age') 60 | plt.ylabel('Estimated Salary') 61 | plt.legend() 62 | plt.show() 63 | 64 | 65 | # Visulaization the training set results 66 | from matplotlib.colors import ListedColormap 67 | X_set, y_set = X_test , y_test 68 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 69 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 70 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 71 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 72 | plt.xlim(x1.min(), x1.max()) 73 | plt.ylim(x2.min(), x2.max()) 74 | 75 | for i,j in enumerate(np.unique(y_set)): 76 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 77 | c = ListedColormap(('red','green')) (i), label = j) 78 | plt.title('Decision Tree Classification (Test set)') 79 | plt.xlabel('Age') 80 | plt.ylabel('Estimated Salary') 81 | plt.legend() 82 | plt.show() -------------------------------------------------------------------------------- /17- K_Means/K_means.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Mall_Customers.csv') 10 | X = data.iloc[:,[3,4]].values 11 | #y = data.iloc[:,-1].values 12 | 13 | 14 | # Finding the dendrogram to find the optimal number of clusters 15 | import scipy.cluster.hierarchy as sch 16 | dendrogram = sch.dendrogram(sch.linkage(X, method = 'ward')) 17 | 18 | # Visulaization the dendrogram method 19 | plt.title('dendrogram') 20 | plt.xlabel('Customers') 21 | plt.ylabel('Eculidean Distance') 22 | plt.show() 23 | 24 | # Using the the Hierarchical Clustering by AgglomerativeClustering 25 | from sklearn.cluster import AgglomerativeClustering 26 | hc = AgglomerativeClustering(n_clusters = 5 , affinity = 'euclidean', linkage = 'ward') 27 | y_pred = hc.fit_predict(X) 28 | 29 | # Clusters Visulizations 30 | plt.scatter(X[y_pred == 0,0],X[y_pred == 0,1], s = 100 , c = 'red', label = 'Careful' ) 31 | plt.scatter(X[y_pred == 1,0],X[y_pred == 1,1], s = 100 , c = 'blue', label = 'Standard' ) 32 | plt.scatter(X[y_pred == 2,0],X[y_pred == 2,1], s = 100 , c = 'green', label = 'Target' ) 33 | plt.scatter(X[y_pred == 3,0],X[y_pred == 3,1], s = 100 , c = 'orange', label = 'Careless' ) 34 | plt.scatter(X[y_pred == 4,0],X[y_pred == 4,1], s = 100 , c = 'yellow', label = 'Sensible' ) 35 | plt.title('Hierarchical Clustering: ') 36 | plt.xlabel('Anual Income (k$)') 37 | plt.ylabel('Spending Score (1-100)') 38 | plt.legend() 39 | plt.show() 40 | -------------------------------------------------------------------------------- /17- K_Means/Mall_Customers.csv: -------------------------------------------------------------------------------- 1 | CustomerID,Genre,Age,Annual Income (k$),Spending Score (1-100) 2 | 0001,Male,19,15,39 3 | 0002,Male,21,15,81 4 | 0003,Female,20,16,6 5 | 0004,Female,23,16,77 6 | 0005,Female,31,17,40 7 | 0006,Female,22,17,76 8 | 0007,Female,35,18,6 9 | 0008,Female,23,18,94 10 | 0009,Male,64,19,3 11 | 0010,Female,30,19,72 12 | 0011,Male,67,19,14 13 | 0012,Female,35,19,99 14 | 0013,Female,58,20,15 15 | 0014,Female,24,20,77 16 | 0015,Male,37,20,13 17 | 0016,Male,22,20,79 18 | 0017,Female,35,21,35 19 | 0018,Male,20,21,66 20 | 0019,Male,52,23,29 21 | 0020,Female,35,23,98 22 | 0021,Male,35,24,35 23 | 0022,Male,25,24,73 24 | 0023,Female,46,25,5 25 | 0024,Male,31,25,73 26 | 0025,Female,54,28,14 27 | 0026,Male,29,28,82 28 | 0027,Female,45,28,32 29 | 0028,Male,35,28,61 30 | 0029,Female,40,29,31 31 | 0030,Female,23,29,87 32 | 0031,Male,60,30,4 33 | 0032,Female,21,30,73 34 | 0033,Male,53,33,4 35 | 0034,Male,18,33,92 36 | 0035,Female,49,33,14 37 | 0036,Female,21,33,81 38 | 0037,Female,42,34,17 39 | 0038,Female,30,34,73 40 | 0039,Female,36,37,26 41 | 0040,Female,20,37,75 42 | 0041,Female,65,38,35 43 | 0042,Male,24,38,92 44 | 0043,Male,48,39,36 45 | 0044,Female,31,39,61 46 | 0045,Female,49,39,28 47 | 0046,Female,24,39,65 48 | 0047,Female,50,40,55 49 | 0048,Female,27,40,47 50 | 0049,Female,29,40,42 51 | 0050,Female,31,40,42 52 | 0051,Female,49,42,52 53 | 0052,Male,33,42,60 54 | 0053,Female,31,43,54 55 | 0054,Male,59,43,60 56 | 0055,Female,50,43,45 57 | 0056,Male,47,43,41 58 | 0057,Female,51,44,50 59 | 0058,Male,69,44,46 60 | 0059,Female,27,46,51 61 | 0060,Male,53,46,46 62 | 0061,Male,70,46,56 63 | 0062,Male,19,46,55 64 | 0063,Female,67,47,52 65 | 0064,Female,54,47,59 66 | 0065,Male,63,48,51 67 | 0066,Male,18,48,59 68 | 0067,Female,43,48,50 69 | 0068,Female,68,48,48 70 | 0069,Male,19,48,59 71 | 0070,Female,32,48,47 72 | 0071,Male,70,49,55 73 | 0072,Female,47,49,42 74 | 0073,Female,60,50,49 75 | 0074,Female,60,50,56 76 | 0075,Male,59,54,47 77 | 0076,Male,26,54,54 78 | 0077,Female,45,54,53 79 | 0078,Male,40,54,48 80 | 0079,Female,23,54,52 81 | 0080,Female,49,54,42 82 | 0081,Male,57,54,51 83 | 0082,Male,38,54,55 84 | 0083,Male,67,54,41 85 | 0084,Female,46,54,44 86 | 0085,Female,21,54,57 87 | 0086,Male,48,54,46 88 | 0087,Female,55,57,58 89 | 0088,Female,22,57,55 90 | 0089,Female,34,58,60 91 | 0090,Female,50,58,46 92 | 0091,Female,68,59,55 93 | 0092,Male,18,59,41 94 | 0093,Male,48,60,49 95 | 0094,Female,40,60,40 96 | 0095,Female,32,60,42 97 | 0096,Male,24,60,52 98 | 0097,Female,47,60,47 99 | 0098,Female,27,60,50 100 | 0099,Male,48,61,42 101 | 0100,Male,20,61,49 102 | 0101,Female,23,62,41 103 | 0102,Female,49,62,48 104 | 0103,Male,67,62,59 105 | 0104,Male,26,62,55 106 | 0105,Male,49,62,56 107 | 0106,Female,21,62,42 108 | 0107,Female,66,63,50 109 | 0108,Male,54,63,46 110 | 0109,Male,68,63,43 111 | 0110,Male,66,63,48 112 | 0111,Male,65,63,52 113 | 0112,Female,19,63,54 114 | 0113,Female,38,64,42 115 | 0114,Male,19,64,46 116 | 0115,Female,18,65,48 117 | 0116,Female,19,65,50 118 | 0117,Female,63,65,43 119 | 0118,Female,49,65,59 120 | 0119,Female,51,67,43 121 | 0120,Female,50,67,57 122 | 0121,Male,27,67,56 123 | 0122,Female,38,67,40 124 | 0123,Female,40,69,58 125 | 0124,Male,39,69,91 126 | 0125,Female,23,70,29 127 | 0126,Female,31,70,77 128 | 0127,Male,43,71,35 129 | 0128,Male,40,71,95 130 | 0129,Male,59,71,11 131 | 0130,Male,38,71,75 132 | 0131,Male,47,71,9 133 | 0132,Male,39,71,75 134 | 0133,Female,25,72,34 135 | 0134,Female,31,72,71 136 | 0135,Male,20,73,5 137 | 0136,Female,29,73,88 138 | 0137,Female,44,73,7 139 | 0138,Male,32,73,73 140 | 0139,Male,19,74,10 141 | 0140,Female,35,74,72 142 | 0141,Female,57,75,5 143 | 0142,Male,32,75,93 144 | 0143,Female,28,76,40 145 | 0144,Female,32,76,87 146 | 0145,Male,25,77,12 147 | 0146,Male,28,77,97 148 | 0147,Male,48,77,36 149 | 0148,Female,32,77,74 150 | 0149,Female,34,78,22 151 | 0150,Male,34,78,90 152 | 0151,Male,43,78,17 153 | 0152,Male,39,78,88 154 | 0153,Female,44,78,20 155 | 0154,Female,38,78,76 156 | 0155,Female,47,78,16 157 | 0156,Female,27,78,89 158 | 0157,Male,37,78,1 159 | 0158,Female,30,78,78 160 | 0159,Male,34,78,1 161 | 0160,Female,30,78,73 162 | 0161,Female,56,79,35 163 | 0162,Female,29,79,83 164 | 0163,Male,19,81,5 165 | 0164,Female,31,81,93 166 | 0165,Male,50,85,26 167 | 0166,Female,36,85,75 168 | 0167,Male,42,86,20 169 | 0168,Female,33,86,95 170 | 0169,Female,36,87,27 171 | 0170,Male,32,87,63 172 | 0171,Male,40,87,13 173 | 0172,Male,28,87,75 174 | 0173,Male,36,87,10 175 | 0174,Male,36,87,92 176 | 0175,Female,52,88,13 177 | 0176,Female,30,88,86 178 | 0177,Male,58,88,15 179 | 0178,Male,27,88,69 180 | 0179,Male,59,93,14 181 | 0180,Male,35,93,90 182 | 0181,Female,37,97,32 183 | 0182,Female,32,97,86 184 | 0183,Male,46,98,15 185 | 0184,Female,29,98,88 186 | 0185,Female,41,99,39 187 | 0186,Male,30,99,97 188 | 0187,Female,54,101,24 189 | 0188,Male,28,101,68 190 | 0189,Female,41,103,17 191 | 0190,Female,36,103,85 192 | 0191,Female,34,103,23 193 | 0192,Female,32,103,69 194 | 0193,Male,33,113,8 195 | 0194,Female,38,113,91 196 | 0195,Female,47,120,16 197 | 0196,Female,35,120,79 198 | 0197,Female,45,126,28 199 | 0198,Male,32,126,74 200 | 0199,Male,32,137,18 201 | 0200,Male,30,137,83 -------------------------------------------------------------------------------- /18- Hierarchical_Clustering/K_means.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template: 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Mall_Customers.csv') 10 | X = data.iloc[:,[3,4]].values 11 | #y = data.iloc[:,-1].values 12 | 13 | 14 | # Using the elbow method to find the optimal nunmber of clusters 15 | from sklearn.cluster import KMeans 16 | wcss = [] 17 | for i in range(1,11): 18 | kmeans = KMeans(n_clusters = i, init='k-means++', random_state = 42 ) 19 | kmeans.fit(X) 20 | wcss.append(kmeans.inertia_) 21 | 22 | plt.plot(range(1,11),wcss) 23 | plt.title('The Elbow Method') 24 | plt.xlabel('Number of Clusters') 25 | plt.ylabel('WCSS') 26 | plt.show() 27 | 28 | 29 | 30 | 31 | ''' 32 | # Splitting the dataset into training set and test set : 33 | from sklearn.model_selection import train_test_split 34 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 35 | 36 | # Features Scaling 37 | from sklearn.preprocessing import StandardScaler 38 | sc_X = StandardScaler() 39 | X_train = sc_X.fit_transform(X_train) 40 | X_test = sc_X.fit_transform(X_test) 41 | #sc_y = StandardScaler() 42 | #y_train = sc_y.fit_transform(y_train) 43 | ''' 44 | 45 | 46 | 47 | # Fitting the Decision Tree Classification model to training dataset: 48 | from sklearn.tree import DecisionTreeClassifier 49 | classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0) 50 | classifier.fit(X_train, y_train) 51 | 52 | 53 | -------------------------------------------------------------------------------- /18- Hierarchical_Clustering/Mall_Customers.csv: -------------------------------------------------------------------------------- 1 | CustomerID,Genre,Age,Annual Income (k$),Spending Score (1-100) 2 | 0001,Male,19,15,39 3 | 0002,Male,21,15,81 4 | 0003,Female,20,16,6 5 | 0004,Female,23,16,77 6 | 0005,Female,31,17,40 7 | 0006,Female,22,17,76 8 | 0007,Female,35,18,6 9 | 0008,Female,23,18,94 10 | 0009,Male,64,19,3 11 | 0010,Female,30,19,72 12 | 0011,Male,67,19,14 13 | 0012,Female,35,19,99 14 | 0013,Female,58,20,15 15 | 0014,Female,24,20,77 16 | 0015,Male,37,20,13 17 | 0016,Male,22,20,79 18 | 0017,Female,35,21,35 19 | 0018,Male,20,21,66 20 | 0019,Male,52,23,29 21 | 0020,Female,35,23,98 22 | 0021,Male,35,24,35 23 | 0022,Male,25,24,73 24 | 0023,Female,46,25,5 25 | 0024,Male,31,25,73 26 | 0025,Female,54,28,14 27 | 0026,Male,29,28,82 28 | 0027,Female,45,28,32 29 | 0028,Male,35,28,61 30 | 0029,Female,40,29,31 31 | 0030,Female,23,29,87 32 | 0031,Male,60,30,4 33 | 0032,Female,21,30,73 34 | 0033,Male,53,33,4 35 | 0034,Male,18,33,92 36 | 0035,Female,49,33,14 37 | 0036,Female,21,33,81 38 | 0037,Female,42,34,17 39 | 0038,Female,30,34,73 40 | 0039,Female,36,37,26 41 | 0040,Female,20,37,75 42 | 0041,Female,65,38,35 43 | 0042,Male,24,38,92 44 | 0043,Male,48,39,36 45 | 0044,Female,31,39,61 46 | 0045,Female,49,39,28 47 | 0046,Female,24,39,65 48 | 0047,Female,50,40,55 49 | 0048,Female,27,40,47 50 | 0049,Female,29,40,42 51 | 0050,Female,31,40,42 52 | 0051,Female,49,42,52 53 | 0052,Male,33,42,60 54 | 0053,Female,31,43,54 55 | 0054,Male,59,43,60 56 | 0055,Female,50,43,45 57 | 0056,Male,47,43,41 58 | 0057,Female,51,44,50 59 | 0058,Male,69,44,46 60 | 0059,Female,27,46,51 61 | 0060,Male,53,46,46 62 | 0061,Male,70,46,56 63 | 0062,Male,19,46,55 64 | 0063,Female,67,47,52 65 | 0064,Female,54,47,59 66 | 0065,Male,63,48,51 67 | 0066,Male,18,48,59 68 | 0067,Female,43,48,50 69 | 0068,Female,68,48,48 70 | 0069,Male,19,48,59 71 | 0070,Female,32,48,47 72 | 0071,Male,70,49,55 73 | 0072,Female,47,49,42 74 | 0073,Female,60,50,49 75 | 0074,Female,60,50,56 76 | 0075,Male,59,54,47 77 | 0076,Male,26,54,54 78 | 0077,Female,45,54,53 79 | 0078,Male,40,54,48 80 | 0079,Female,23,54,52 81 | 0080,Female,49,54,42 82 | 0081,Male,57,54,51 83 | 0082,Male,38,54,55 84 | 0083,Male,67,54,41 85 | 0084,Female,46,54,44 86 | 0085,Female,21,54,57 87 | 0086,Male,48,54,46 88 | 0087,Female,55,57,58 89 | 0088,Female,22,57,55 90 | 0089,Female,34,58,60 91 | 0090,Female,50,58,46 92 | 0091,Female,68,59,55 93 | 0092,Male,18,59,41 94 | 0093,Male,48,60,49 95 | 0094,Female,40,60,40 96 | 0095,Female,32,60,42 97 | 0096,Male,24,60,52 98 | 0097,Female,47,60,47 99 | 0098,Female,27,60,50 100 | 0099,Male,48,61,42 101 | 0100,Male,20,61,49 102 | 0101,Female,23,62,41 103 | 0102,Female,49,62,48 104 | 0103,Male,67,62,59 105 | 0104,Male,26,62,55 106 | 0105,Male,49,62,56 107 | 0106,Female,21,62,42 108 | 0107,Female,66,63,50 109 | 0108,Male,54,63,46 110 | 0109,Male,68,63,43 111 | 0110,Male,66,63,48 112 | 0111,Male,65,63,52 113 | 0112,Female,19,63,54 114 | 0113,Female,38,64,42 115 | 0114,Male,19,64,46 116 | 0115,Female,18,65,48 117 | 0116,Female,19,65,50 118 | 0117,Female,63,65,43 119 | 0118,Female,49,65,59 120 | 0119,Female,51,67,43 121 | 0120,Female,50,67,57 122 | 0121,Male,27,67,56 123 | 0122,Female,38,67,40 124 | 0123,Female,40,69,58 125 | 0124,Male,39,69,91 126 | 0125,Female,23,70,29 127 | 0126,Female,31,70,77 128 | 0127,Male,43,71,35 129 | 0128,Male,40,71,95 130 | 0129,Male,59,71,11 131 | 0130,Male,38,71,75 132 | 0131,Male,47,71,9 133 | 0132,Male,39,71,75 134 | 0133,Female,25,72,34 135 | 0134,Female,31,72,71 136 | 0135,Male,20,73,5 137 | 0136,Female,29,73,88 138 | 0137,Female,44,73,7 139 | 0138,Male,32,73,73 140 | 0139,Male,19,74,10 141 | 0140,Female,35,74,72 142 | 0141,Female,57,75,5 143 | 0142,Male,32,75,93 144 | 0143,Female,28,76,40 145 | 0144,Female,32,76,87 146 | 0145,Male,25,77,12 147 | 0146,Male,28,77,97 148 | 0147,Male,48,77,36 149 | 0148,Female,32,77,74 150 | 0149,Female,34,78,22 151 | 0150,Male,34,78,90 152 | 0151,Male,43,78,17 153 | 0152,Male,39,78,88 154 | 0153,Female,44,78,20 155 | 0154,Female,38,78,76 156 | 0155,Female,47,78,16 157 | 0156,Female,27,78,89 158 | 0157,Male,37,78,1 159 | 0158,Female,30,78,78 160 | 0159,Male,34,78,1 161 | 0160,Female,30,78,73 162 | 0161,Female,56,79,35 163 | 0162,Female,29,79,83 164 | 0163,Male,19,81,5 165 | 0164,Female,31,81,93 166 | 0165,Male,50,85,26 167 | 0166,Female,36,85,75 168 | 0167,Male,42,86,20 169 | 0168,Female,33,86,95 170 | 0169,Female,36,87,27 171 | 0170,Male,32,87,63 172 | 0171,Male,40,87,13 173 | 0172,Male,28,87,75 174 | 0173,Male,36,87,10 175 | 0174,Male,36,87,92 176 | 0175,Female,52,88,13 177 | 0176,Female,30,88,86 178 | 0177,Male,58,88,15 179 | 0178,Male,27,88,69 180 | 0179,Male,59,93,14 181 | 0180,Male,35,93,90 182 | 0181,Female,37,97,32 183 | 0182,Female,32,97,86 184 | 0183,Male,46,98,15 185 | 0184,Female,29,98,88 186 | 0185,Female,41,99,39 187 | 0186,Male,30,99,97 188 | 0187,Female,54,101,24 189 | 0188,Male,28,101,68 190 | 0189,Female,41,103,17 191 | 0190,Female,36,103,85 192 | 0191,Female,34,103,23 193 | 0192,Female,32,103,69 194 | 0193,Male,33,113,8 195 | 0194,Female,38,113,91 196 | 0195,Female,47,120,16 197 | 0196,Female,35,120,79 198 | 0197,Female,45,126,28 199 | 0198,Male,32,126,74 200 | 0199,Male,32,137,18 201 | 0200,Male,30,137,83 -------------------------------------------------------------------------------- /19- Apriori_Python/Apriori.py: -------------------------------------------------------------------------------- 1 | # Apriori Algorthim 2 | ''' 3 | ------------------------------------------------------- 4 | The data set is collected for a convenience store in which the products are stored 5 | in columns, and rows represent the customers or visitors of this store in which 6 | every row represents a customer who bought some of these items or nor of them through 7 | a full week. so our mission here to work on an association rule to find any corelation 8 | or association between these products, for the purpose of enhancing our bussines. 9 | for example do customers are often buy Chips with Coke? 10 | ------------------------------------------------------ 11 | 12 | ''' 13 | 14 | # Importing the required libraries 15 | import numpy as np 16 | import matplotlib.pyplot as plt 17 | import pandas as pd 18 | 19 | # Importing the dataset 20 | dataset = pd.read_csv('Market_Basket_Optimisation.csv', header = None) 21 | 22 | transactions = [] 23 | for i in range(1,7501): 24 | transactions.append([str(dataset.values[i,j]) for j in range (0,20)]) 25 | 26 | ''' 27 | The min_support : 3 Products are sold in 7 days through all transactions:(3*7/7500 = 0.0028 or 0.003) 28 | The min_confidence: often we use 20% 29 | min_left: 3 30 | min_length: among the dataset you want to find a corellation between at least 2 products ! 31 | Explination: the customer will buy an item will buy the associated item with a percentage of 20% 32 | ''' 33 | # Importing the apriori algorthim and assign the rules for the algorthim 34 | from apyori import apriori 35 | rules = apriori(transactions, min_support = 0.003 , min_confidence = 0.2 , min_left = 3 , min_length =2 ) 36 | 37 | # Visuliazing the results 38 | results = list(rules) 39 | results_list = [] 40 | 41 | for i in range (0, len(results)): 42 | results_list.append('Rule:\t' + str(results[i][0]) + '\nSUPPORT:\t' + str(results[i][1])) -------------------------------------------------------------------------------- /19- Apriori_Python/__pycache__/apyori.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/19- Apriori_Python/__pycache__/apyori.cpython-38.pyc -------------------------------------------------------------------------------- /19- Apriori_Python/apyori-1.1.2.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/19- Apriori_Python/apyori-1.1.2.tar.gz -------------------------------------------------------------------------------- /20- Upper Confidence Bound/UCB.py: -------------------------------------------------------------------------------- 1 | # Upper Confidence Bound 2 | 3 | # Importing the library 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | import math 8 | 9 | # Importing the dataset 10 | dataset = pd.read_csv('Ads_CTR_Optimisation.csv') 11 | 12 | # Implemnting UCB 13 | N = 10000 14 | d = 10 15 | ads_selected = [] 16 | number_of_selection = [0]*d 17 | sums_of_rewards = [0]*d 18 | total_reward = 0 19 | 20 | for n in range(0,N): 21 | ad = 0 22 | max_upper_bound = 0 23 | for i in range(0,d): 24 | if (number_of_selection[i] > 0): 25 | average_reward = sums_of_rewards[i] / number_of_selection[i] 26 | delti_i = math.sqrt(3/2 * math.log(n+1)/number_of_selection[i]) 27 | upper_bound = average_reward + delti_i 28 | else: 29 | upper_bound = 1e400 30 | if upper_bound > max_upper_bound: 31 | max_upper_bound = upper_bound 32 | ad = i 33 | ads_selected.append(ad) 34 | number_of_selection[ad] = number_of_selection[ad] + 1 35 | rewards = dataset.values[n, ad] 36 | sums_of_rewards[ad] = sums_of_rewards[ad] + rewards 37 | total_reward += rewards 38 | 39 | # Visulaizing the results 40 | plt.hist(ads_selected) 41 | plt.title('Histogram of ads selections') 42 | plt.xlabel('Ads') 43 | plt.ylabel('Number of times each ad was selected') 44 | plt.show() -------------------------------------------------------------------------------- /20- Upper Confidence Bound/random_selection.py: -------------------------------------------------------------------------------- 1 | # Upper Confidence Bound 2 | 3 | # Importing the library 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | 9 | # Importing the dataset 10 | dataset = pd.read_csv('Ads_CTR_Optimisation.csv') 11 | 12 | # Implelementing Random Selection 13 | import random 14 | N = 10000 15 | d = 10 16 | ads_selected = [] 17 | total_reward = 0 18 | for n in range(0,N): 19 | ad = random.randrange(d) 20 | ads_selected.append(ad) 21 | reward = dataset.values[n,ad] 22 | total_reward = total_reward + reward 23 | 24 | # Visulaizing the results 25 | plt.hist(ads_selected) 26 | plt.title('Histogram of ads selections') 27 | plt.xlabel('Ads') 28 | plt.ylabel('Number of times each ad was selected') 29 | plt.show() -------------------------------------------------------------------------------- /21-Thompson_Sampling/thompson_sampling.py: -------------------------------------------------------------------------------- 1 | 2 | # Thompson Sampling 3 | 4 | # Importing the libraries 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | import pandas as pd 8 | 9 | # Importing the dataset 10 | dataset = pd.read_csv('Ads_CTR_Optimisation.csv') 11 | 12 | # Implementing Thompson Sampling 13 | import random 14 | N = 10000 15 | d = 10 16 | ads_selected = [] 17 | numbers_of_rewards_1 = [0] * d 18 | numbers_of_rewards_0 = [0] * d 19 | total_reward = 0 20 | for n in range(0, N): 21 | ad = 0 22 | max_random = 0 23 | for i in range(0, d): 24 | random_beta = random.betavariate(numbers_of_rewards_1[i] + 1, numbers_of_rewards_0[i] + 1) 25 | if random_beta > max_random: 26 | max_random = random_beta 27 | ad = i 28 | ads_selected.append(ad) 29 | reward = dataset.values[n, ad] 30 | if reward == 1: 31 | numbers_of_rewards_1[ad] = numbers_of_rewards_1[ad] + 1 32 | else: 33 | numbers_of_rewards_0[ad] = numbers_of_rewards_0[ad] + 1 34 | total_reward = total_reward + reward 35 | 36 | # Visualising the results - Histogram 37 | plt.hist(ads_selected) 38 | plt.title('Histogram of ads selections') 39 | plt.xlabel('Ads') 40 | plt.ylabel('Number of times each ad was selected') 41 | plt.show() 42 | 43 | 44 | -------------------------------------------------------------------------------- /22- Natural_Language_Processing/NLP.py: -------------------------------------------------------------------------------- 1 | # Natural Language Processing 2 | 3 | # Importing the libraries 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | dataset = pd.read_csv('Restaurant_Reviews.tsv', delimiter = '\t', quoting = 3) 10 | 11 | # Cleaning the text 12 | import re 13 | import nltk 14 | nltk.download('stopwords') 15 | from nltk.corpus import stopwords 16 | from nltk.stem.porter import PorterStemmer 17 | 18 | cropus = [] 19 | for i in range(0,1000): 20 | # remove any spechial character and replace it by spance 21 | review = re.sub('[^a-zA-Z]',' ',dataset['Review'][i]) 22 | # convert all uppercase letters to lowercase letters 23 | review = review.lower() 24 | # spliting the words in a list 25 | review = review.split() 26 | # get root of words such as loves or loving converted to love 27 | ps = PorterStemmer() 28 | 29 | # we keep the most importat words and we remove unnecessary words such as [this, the ,and .. ] 30 | # List Comprehensions procedure: 31 | review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))] 32 | # combine all words in one string 33 | review = ' ' .join(review) 34 | cropus.append(review) 35 | 36 | # Creating the bag of words 37 | from sklearn.feature_extraction.text import CountVectorizer 38 | cv = CountVectorizer(max_features = 1500) 39 | X = cv.fit_transform(cropus).toarray() 40 | y = dataset.iloc[:,1] 41 | 42 | # Splitting the dataset into training set and test set : 43 | from sklearn.model_selection import train_test_split 44 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 45 | 46 | 47 | # Fitting the Decision Tree Classification model to training dataset: 48 | from sklearn.ensemble import RandomForestClassifier 49 | classifier = RandomForestClassifier(n_estimators = 10 ,criterion = 'entropy',random_state = 0 ) 50 | classifier.fit(X_train, y_train) 51 | 52 | # predecting the test set results 53 | y_pred = classifier.predict(X_test) 54 | 55 | # Creating the confusion matrix 56 | from sklearn.metrics import confusion_matrix 57 | cm = confusion_matrix(y_test, y_pred) 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /22- Natural_Language_Processing/natural_language_processing_Colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "natural_language_processing_Colab.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "code", 18 | "metadata": { 19 | "id": "AZ2WadBmnm5H", 20 | "colab_type": "code", 21 | "colab": {} 22 | }, 23 | "source": [ 24 | "#import data (test CSV)\n", 25 | "from google.colab import drive\n", 26 | "drive.mount('/content/drive')" 27 | ], 28 | "execution_count": 0, 29 | "outputs": [] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "metadata": { 34 | "id": "a_dVGD5sn2k2", 35 | "colab_type": "code", 36 | "colab": {} 37 | }, 38 | "source": [ 39 | " #cd (change directory) to the file/folder location" 40 | ], 41 | "execution_count": 0, 42 | "outputs": [] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "metadata": { 47 | "id": "Ae2iFe3Rn2iO", 48 | "colab_type": "code", 49 | "outputId": "09e6fd79-3343-43e4-cc53-8b4a5b3f8937", 50 | "colab": { 51 | "base_uri": "https://localhost:8080/", 52 | "height": 51 53 | } 54 | }, 55 | "source": [ 56 | "# Natural Language Processing\n", 57 | "\n", 58 | "# Importing the libraries\n", 59 | "import numpy as np\n", 60 | "import matplotlib.pyplot as plt\n", 61 | "import pandas as pd\n", 62 | "\n", 63 | "# Importing the dataset\n", 64 | "dataset = pd.read_csv('Restaurant_Reviews.tsv', delimiter = '\\t', quoting = 3)\n", 65 | "\n", 66 | "# Cleaning the texts\n", 67 | "import re\n", 68 | "import nltk\n", 69 | "nltk.download('stopwords')\n", 70 | "from nltk.corpus import stopwords\n", 71 | "from nltk.stem.porter import PorterStemmer\n", 72 | "corpus = []\n", 73 | "for i in range(0, 1000):\n", 74 | " review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i])\n", 75 | " review = review.lower()\n", 76 | " review = review.split()\n", 77 | " ps = PorterStemmer()\n", 78 | " review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))]\n", 79 | " review = ' '.join(review)\n", 80 | " corpus.append(review)\n", 81 | "\n", 82 | "# Creating the Bag of Words model\n", 83 | "from sklearn.feature_extraction.text import CountVectorizer\n", 84 | "cv = CountVectorizer(max_features = 1500)\n", 85 | "X = cv.fit_transform(corpus).toarray()\n", 86 | "y = dataset.iloc[:, 1].values\n", 87 | "\n", 88 | "# Splitting the dataset into the Training set and Test set\n", 89 | "from sklearn.model_selection import train_test_split\n", 90 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0)\n", 91 | "\n", 92 | "# Fitting Naive Bayes to the Training set\n", 93 | "from sklearn.naive_bayes import GaussianNB\n", 94 | "classifier = GaussianNB()\n", 95 | "classifier.fit(X_train, y_train)\n", 96 | "\n", 97 | "# Predicting the Test set results\n", 98 | "y_pred = classifier.predict(X_test)\n", 99 | "\n", 100 | "# Making the Confusion Matrix\n", 101 | "from sklearn.metrics import confusion_matrix\n", 102 | "cm = confusion_matrix(y_test, y_pred)" 103 | ], 104 | "execution_count": 3, 105 | "outputs": [ 106 | { 107 | "output_type": "stream", 108 | "text": [ 109 | "[nltk_data] Downloading package stopwords to /root/nltk_data...\n", 110 | "[nltk_data] Unzipping corpora/stopwords.zip.\n" 111 | ], 112 | "name": "stdout" 113 | } 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "metadata": { 119 | "id": "tPXrnm0Dn2ek", 120 | "colab_type": "code", 121 | "colab": { 122 | "base_uri": "https://localhost:8080/", 123 | "height": 51 124 | }, 125 | "outputId": "4659f0bc-c662-4c71-cead-3d073bd6c3ab" 126 | }, 127 | "source": [ 128 | "print (cm)" 129 | ], 130 | "execution_count": 4, 131 | "outputs": [ 132 | { 133 | "output_type": "stream", 134 | "text": [ 135 | "[[55 42]\n", 136 | " [12 91]]\n" 137 | ], 138 | "name": "stdout" 139 | } 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "metadata": { 145 | "id": "W6My8YVOpFYl", 146 | "colab_type": "code", 147 | "colab": {} 148 | }, 149 | "source": [ 150 | "" 151 | ], 152 | "execution_count": 0, 153 | "outputs": [] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "metadata": { 158 | "id": "J6epjyw1pFgc", 159 | "colab_type": "code", 160 | "colab": {} 161 | }, 162 | "source": [ 163 | "" 164 | ], 165 | "execution_count": 0, 166 | "outputs": [] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "metadata": { 171 | "id": "spYXA5FApFpd", 172 | "colab_type": "code", 173 | "colab": {} 174 | }, 175 | "source": [ 176 | "" 177 | ], 178 | "execution_count": 0, 179 | "outputs": [] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "metadata": { 184 | "id": "0guxKKH0pFnv", 185 | "colab_type": "code", 186 | "colab": {} 187 | }, 188 | "source": [ 189 | "" 190 | ], 191 | "execution_count": 0, 192 | "outputs": [] 193 | } 194 | ] 195 | } -------------------------------------------------------------------------------- /23- Artificial_Neural_Networks/ANN.py: -------------------------------------------------------------------------------- 1 | # Artificial Neural Network 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Churn_Modelling.csv') 10 | X = data.iloc[:,3:13].values 11 | y = data.iloc[:,13].values 12 | 13 | # Encoding categorical data from Labels into continious 0 1: 14 | from sklearn.preprocessing import LabelEncoder , OneHotEncoder 15 | from sklearn.compose import ColumnTransformer 16 | 17 | # Encoding categorical data in 'Country' Column to continious 0 1: 18 | # The new method doesn't require to use LabelEncoder and you can make it by two lines 19 | ct_X = ColumnTransformer([('0', OneHotEncoder(), [1])], remainder = 'passthrough') 20 | X = ct_X.fit_transform(X) 21 | 22 | # Encoding categorical data in 'Gender' Column to continious 0 1: 23 | LabelEncoder_X = LabelEncoder() 24 | X [:,4] = LabelEncoder_X.fit_transform(X[:,4]) 25 | 26 | # Remove one of 3 dummy variables for the country 27 | X = X[:,1:] 28 | 29 | # Splitting the dataset into training set and test set : 30 | from sklearn.model_selection import train_test_split 31 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 32 | 33 | # Features Scaling 34 | from sklearn.preprocessing import StandardScaler 35 | sc_X = StandardScaler() 36 | X_train = sc_X.fit_transform(X_train) 37 | X_test = sc_X.fit_transform(X_test) 38 | #sc_y = StandardScaler() 39 | #y_train = sc_y.fit_transform(y_train) 40 | 41 | # Importing Tensorflow + Keras 42 | from tensorflow.keras.models import Sequential 43 | from tensorflow.keras.layers import Dense 44 | 45 | # Inintialization the ANN 46 | classifier = Sequential() 47 | 48 | # Adding the input layer and the first hidden layer 49 | # Output = units = 11 + 1 / 2 , kernel_initializer = weights random uniform distribution , activation = relu ('rectifier') 50 | classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11)) 51 | 52 | # Adding the input layer and the first hidden layer 53 | classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu',)) 54 | 55 | # Adding the output layer 56 | classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) 57 | 58 | # Compiling the ANN 59 | classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'] ) 60 | 61 | 62 | #Fitting the ANN to the training set 63 | classifier.fit(X_train, y_train, batch_size = 10 , epochs = 100) 64 | 65 | # Predicting the Test set results 66 | y_pred = classifier.predict(X_test) 67 | y_pred = (y_pred > 0.5) 68 | 69 | # Making the Confusion Matrix 70 | from sklearn.metrics import confusion_matrix 71 | cm = confusion_matrix(y_test, y_pred) 72 | 73 | 74 | -------------------------------------------------------------------------------- /23- Artificial_Neural_Networks/Stochastic_Gradient_Descent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/23- Artificial_Neural_Networks/Stochastic_Gradient_Descent.png -------------------------------------------------------------------------------- /23- Artificial_Neural_Networks/ann_Colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "ann_Colab.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "code", 18 | "metadata": { 19 | "id": "AZ2WadBmnm5H", 20 | "colab_type": "code", 21 | "colab": {} 22 | }, 23 | "source": [ 24 | "#import data (test CSV)\n", 25 | "from google.colab import drive\n", 26 | "drive.mount('/content/drive')" 27 | ], 28 | "execution_count": 0, 29 | "outputs": [] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "metadata": { 34 | "id": "a_dVGD5sn2k2", 35 | "colab_type": "code", 36 | "colab": {} 37 | }, 38 | "source": [ 39 | " #cd (change directory) to the file/folder location" 40 | ], 41 | "execution_count": 0, 42 | "outputs": [] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "metadata": { 47 | "id": "4LskbY47sPeX", 48 | "colab_type": "code", 49 | "colab": {} 50 | }, 51 | "source": [ 52 | "!pip install tensorflow==1.14" 53 | ], 54 | "execution_count": 0, 55 | "outputs": [] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "metadata": { 60 | "id": "Ae2iFe3Rn2iO", 61 | "colab_type": "code", 62 | "colab": {} 63 | }, 64 | "source": [ 65 | "\n", 66 | "# Artificial Neural Network\n", 67 | "\n", 68 | "# Installing Keras\n", 69 | "# Enter the following command in a terminal (or anaconda prompt for Windows users): conda install -c conda-forge keras\n", 70 | "\n", 71 | "# Part 1 - Data Preprocessing\n", 72 | "\n", 73 | "# Importing the libraries\n", 74 | "import numpy as np\n", 75 | "import matplotlib.pyplot as plt\n", 76 | "import pandas as pd\n", 77 | "\n", 78 | "# Importing the dataset\n", 79 | "dataset = pd.read_csv('Churn_Modelling.csv')\n", 80 | "X = dataset.iloc[:, 3:13].values\n", 81 | "y = dataset.iloc[:, 13].values\n", 82 | "\n", 83 | "# Encoding categorical data\n", 84 | "\n", 85 | "from sklearn.compose import ColumnTransformer\n", 86 | "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n", 87 | "\n", 88 | "labelencoder_X_1 = LabelEncoder()\n", 89 | "X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])\n", 90 | "labelencoder_X_2 = LabelEncoder()\n", 91 | "X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])\n", 92 | "ct = ColumnTransformer([('encoder', OneHotEncoder(), [1])], remainder='passthrough')\n", 93 | "X = np.array(ct.fit_transform(X), dtype=np.float)\n", 94 | "X = X[:, 1:]\n", 95 | "\n", 96 | "# Splitting the dataset into the Training set and Test set\n", 97 | "from sklearn.model_selection import train_test_split\n", 98 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)\n", 99 | "\n", 100 | "# Feature Scaling\n", 101 | "from sklearn.preprocessing import StandardScaler\n", 102 | "sc = StandardScaler()\n", 103 | "X_train = sc.fit_transform(X_train)\n", 104 | "X_test = sc.transform(X_test)\n", 105 | "\n", 106 | "# Part 2 - Now let's make the ANN!\n", 107 | "\n", 108 | "# Importing the Keras libraries and packages\n", 109 | "import keras\n", 110 | "from keras.models import Sequential\n", 111 | "from keras.layers import Dense\n", 112 | "\n", 113 | "# Initialising the ANN\n", 114 | "classifier = Sequential()\n", 115 | "\n", 116 | "# Adding the input layer and the first hidden layer\n", 117 | "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11))\n", 118 | "\n", 119 | "# Adding the second hidden layer\n", 120 | "classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu'))\n", 121 | "\n", 122 | "# Adding the output layer\n", 123 | "classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid'))\n", 124 | "\n", 125 | "# Compiling the ANN\n", 126 | "classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n", 127 | "\n", 128 | "# Fitting the ANN to the Training set\n", 129 | "classifier.fit(X_train, y_train, batch_size = 10, epochs = 100)\n", 130 | "\n", 131 | "# Part 3 - Making the predictions and evaluating the model\n", 132 | "\n", 133 | "# Predicting the Test set results\n", 134 | "y_pred = classifier.predict(X_test)\n", 135 | "y_pred = (y_pred > 0.5)\n", 136 | "\n", 137 | "# Making the Confusion Matrix\n", 138 | "from sklearn.metrics import confusion_matrix\n", 139 | "cm = confusion_matrix(y_test, y_pred)" 140 | ], 141 | "execution_count": 0, 142 | "outputs": [] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "metadata": { 147 | "id": "tPXrnm0Dn2ek", 148 | "colab_type": "code", 149 | "colab": {} 150 | }, 151 | "source": [ 152 | "" 153 | ], 154 | "execution_count": 0, 155 | "outputs": [] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "metadata": { 160 | "id": "W6My8YVOpFYl", 161 | "colab_type": "code", 162 | "colab": {} 163 | }, 164 | "source": [ 165 | "" 166 | ], 167 | "execution_count": 0, 168 | "outputs": [] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "metadata": { 173 | "id": "J6epjyw1pFgc", 174 | "colab_type": "code", 175 | "colab": {} 176 | }, 177 | "source": [ 178 | "" 179 | ], 180 | "execution_count": 0, 181 | "outputs": [] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "metadata": { 186 | "id": "spYXA5FApFpd", 187 | "colab_type": "code", 188 | "colab": {} 189 | }, 190 | "source": [ 191 | "" 192 | ], 193 | "execution_count": 0, 194 | "outputs": [] 195 | }, 196 | { 197 | "cell_type": "code", 198 | "metadata": { 199 | "id": "0guxKKH0pFnv", 200 | "colab_type": "code", 201 | "colab": {} 202 | }, 203 | "source": [ 204 | "" 205 | ], 206 | "execution_count": 0, 207 | "outputs": [] 208 | } 209 | ] 210 | } -------------------------------------------------------------------------------- /24- Convolutional_Neural_Networks/CNN.py: -------------------------------------------------------------------------------- 1 | # Convolutional Neural Network. 2 | 3 | # Installing the required libraries 4 | # Theano, Tensorflow, Keras 5 | from tensorflow.keras.models import Sequential 6 | from tensorflow.keras.layers import Conv2D 7 | from tensorflow.keras.layers import MaxPooling2D 8 | from tensorflow.keras.layers import Flatten 9 | from tensorflow.keras.layers import Dense 10 | 11 | # Sequential 12 | classifier = Sequential() 13 | 14 | # Step1: Convolution 15 | # n_filters(feature maps) = 32, kernel_size: rows = 3, cols = 3 16 | # input image shape 64x64 RGB 17 | classifier.add(Conv2D(32, kernel_size = (3,3), input_shape = (64, 64, 3), activation = 'relu')) 18 | 19 | # Step2: Pooling 20 | classifier.add(MaxPooling2D(pool_size = (2,2))) 21 | 22 | # Adding a second convolutional layer 23 | classifier.add(Conv2D(32, kernel_size = (3,3), activation = 'relu')) 24 | classifier.add(MaxPooling2D(pool_size = (2,2))) 25 | 26 | # Step3: Flatten 27 | classifier.add(Flatten()) 28 | 29 | # Step4: Full Connection 30 | classifier.add(Dense(units = 128, activation = 'relu')) 31 | classifier.add(Dense(units = 1, activation = 'sigmoid')) 32 | 33 | # Compile the CNN 34 | classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) 35 | 36 | 37 | # Part 2 Fitting the CNN to the images 38 | from tensorflow.keras.preprocessing.image import ImageDataGenerator 39 | train_datagen = ImageDataGenerator( 40 | rescale=1./255, 41 | shear_range=0.2, 42 | zoom_range=0.2, 43 | horizontal_flip=True) 44 | test_datagen = ImageDataGenerator(rescale=1./255) 45 | 46 | training_set = train_datagen.flow_from_directory( 47 | 'dataset/training_set', 48 | target_size=(64, 64), 49 | batch_size=32, 50 | class_mode='binary') 51 | test_set = test_datagen.flow_from_directory( 52 | 'dataset/test_set', 53 | target_size=(64, 64), 54 | batch_size=32, 55 | class_mode='binary') 56 | classifier.fit( 57 | training_set, 58 | steps_per_epoch=250, # no.unique images in training set / batch size 59 | epochs=35, 60 | validation_data= test_set, 61 | validation_steps=2000) 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /24- Convolutional_Neural_Networks/cnn_Colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "cnn_Colab.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "code", 18 | "metadata": { 19 | "id": "AZ2WadBmnm5H", 20 | "colab_type": "code", 21 | "colab": {} 22 | }, 23 | "source": [ 24 | "#import data (test CSV)\n", 25 | "from google.colab import drive\n", 26 | "drive.mount('/content/drive')" 27 | ], 28 | "execution_count": 0, 29 | "outputs": [] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "metadata": { 34 | "id": "a_dVGD5sn2k2", 35 | "colab_type": "code", 36 | "colab": {} 37 | }, 38 | "source": [ 39 | " #cd (change directory) to the file/folder location" 40 | ], 41 | "execution_count": 0, 42 | "outputs": [] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "metadata": { 47 | "id": "4LskbY47sPeX", 48 | "colab_type": "code", 49 | "colab": {} 50 | }, 51 | "source": [ 52 | "!pip install tensorflow==1.14" 53 | ], 54 | "execution_count": 0, 55 | "outputs": [] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "metadata": { 60 | "id": "Ae2iFe3Rn2iO", 61 | "colab_type": "code", 62 | "colab": {} 63 | }, 64 | "source": [ 65 | "# Convolutional Neural Network\n", 66 | "\n", 67 | "# Installing Keras\n", 68 | "# Enter the following command in a terminal (or anaconda prompt for Windows users): conda install -c conda-forge keras\n", 69 | "\n", 70 | "# Part 1 - Building the CNN\n", 71 | "\n", 72 | "# Importing the Keras libraries and packages\n", 73 | "from keras.models import Sequential\n", 74 | "from keras.layers import Conv2D\n", 75 | "from keras.layers import MaxPooling2D\n", 76 | "from keras.layers import Flatten\n", 77 | "from keras.layers import Dense\n", 78 | "\n", 79 | "# Initialising the CNN\n", 80 | "classifier = Sequential()\n", 81 | "\n", 82 | "# Step 1 - Convolution\n", 83 | "classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))\n", 84 | "\n", 85 | "# Step 2 - Pooling\n", 86 | "classifier.add(MaxPooling2D(pool_size = (2, 2)))\n", 87 | "\n", 88 | "# Adding a second convolutional layer\n", 89 | "classifier.add(Conv2D(32, (3, 3), activation = 'relu'))\n", 90 | "classifier.add(MaxPooling2D(pool_size = (2, 2)))\n", 91 | "\n", 92 | "# Step 3 - Flattening\n", 93 | "classifier.add(Flatten())\n", 94 | "\n", 95 | "# Step 4 - Full connection\n", 96 | "classifier.add(Dense(units = 128, activation = 'relu'))\n", 97 | "classifier.add(Dense(units = 1, activation = 'sigmoid'))\n", 98 | "\n", 99 | "# Compiling the CNN\n", 100 | "classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n", 101 | "\n", 102 | "# Part 2 - Fitting the CNN to the images\n", 103 | "\n", 104 | "from keras.preprocessing.image import ImageDataGenerator\n", 105 | "\n", 106 | "train_datagen = ImageDataGenerator(rescale = 1./255,\n", 107 | " shear_range = 0.2,\n", 108 | " zoom_range = 0.2,\n", 109 | " horizontal_flip = True)\n", 110 | "\n", 111 | "test_datagen = ImageDataGenerator(rescale = 1./255)\n", 112 | "\n", 113 | "training_set = train_datagen.flow_from_directory('dataset/training_set',\n", 114 | " target_size = (64, 64),\n", 115 | " batch_size = 32,\n", 116 | " class_mode = 'binary')\n", 117 | "\n", 118 | "test_set = test_datagen.flow_from_directory('dataset/test_set',\n", 119 | " target_size = (64, 64),\n", 120 | " batch_size = 32,\n", 121 | " class_mode = 'binary')\n", 122 | "\n", 123 | "classifier.fit_generator(training_set,\n", 124 | " steps_per_epoch = 8000,\n", 125 | " epochs = 25,\n", 126 | " validation_data = test_set,\n", 127 | " validation_steps = 2000)" 128 | ], 129 | "execution_count": 0, 130 | "outputs": [] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "metadata": { 135 | "id": "tPXrnm0Dn2ek", 136 | "colab_type": "code", 137 | "colab": {} 138 | }, 139 | "source": [ 140 | "" 141 | ], 142 | "execution_count": 0, 143 | "outputs": [] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "metadata": { 148 | "id": "W6My8YVOpFYl", 149 | "colab_type": "code", 150 | "colab": {} 151 | }, 152 | "source": [ 153 | "" 154 | ], 155 | "execution_count": 0, 156 | "outputs": [] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "metadata": { 161 | "id": "J6epjyw1pFgc", 162 | "colab_type": "code", 163 | "colab": {} 164 | }, 165 | "source": [ 166 | "" 167 | ], 168 | "execution_count": 0, 169 | "outputs": [] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "metadata": { 174 | "id": "spYXA5FApFpd", 175 | "colab_type": "code", 176 | "colab": {} 177 | }, 178 | "source": [ 179 | "" 180 | ], 181 | "execution_count": 0, 182 | "outputs": [] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "metadata": { 187 | "id": "0guxKKH0pFnv", 188 | "colab_type": "code", 189 | "colab": {} 190 | }, 191 | "source": [ 192 | "" 193 | ], 194 | "execution_count": 0, 195 | "outputs": [] 196 | } 197 | ] 198 | } -------------------------------------------------------------------------------- /25- PCA/Juices.csv: -------------------------------------------------------------------------------- 1 | Strawberries,Apple ,Mango,Grapes,Kiwi,Carrot,Green coconut ,Guava,Limes,Oranges ,Pineapple,Raspberries ,Water melon ,Customer_Segment 2 | 14.23,1.71,2.43,15.6,127,2.8,3.06,0.28,2.29,5.64,1.04,3.92,1065,1 3 | 13.2,1.78,2.14,11.2,100,2.65,2.76,0.26,1.28,4.38,1.05,3.4,1050,1 4 | 13.16,2.36,2.67,18.6,101,2.8,3.24,0.3,2.81,5.68,1.03,3.17,1185,1 5 | 14.37,1.95,2.5,16.8,113,3.85,3.49,0.24,2.18,7.8,0.86,3.45,1480,1 6 | 13.24,2.59,2.87,21,118,2.8,2.69,0.39,1.82,4.32,1.04,2.93,735,1 7 | 14.2,1.76,2.45,15.2,112,3.27,3.39,0.34,1.97,6.75,1.05,2.85,1450,1 8 | 14.39,1.87,2.45,14.6,96,2.5,2.52,0.3,1.98,5.25,1.02,3.58,1290,1 9 | 14.06,2.15,2.61,17.6,121,2.6,2.51,0.31,1.25,5.05,1.06,3.58,1295,1 10 | 14.83,1.64,2.17,14,97,2.8,2.98,0.29,1.98,5.2,1.08,2.85,1045,1 11 | 13.86,1.35,2.27,16,98,2.98,3.15,0.22,1.85,7.22,1.01,3.55,1045,1 12 | 14.1,2.16,2.3,18,105,2.95,3.32,0.22,2.38,5.75,1.25,3.17,1510,1 13 | 14.12,1.48,2.32,16.8,95,2.2,2.43,0.26,1.57,5,1.17,2.82,1280,1 14 | 13.75,1.73,2.41,16,89,2.6,2.76,0.29,1.81,5.6,1.15,2.9,1320,1 15 | 14.75,1.73,2.39,11.4,91,3.1,3.69,0.43,2.81,5.4,1.25,2.73,1150,1 16 | 14.38,1.87,2.38,12,102,3.3,3.64,0.29,2.96,7.5,1.2,3,1547,1 17 | 13.63,1.81,2.7,17.2,112,2.85,2.91,0.3,1.46,7.3,1.28,2.88,1310,1 18 | 14.3,1.92,2.72,20,120,2.8,3.14,0.33,1.97,6.2,1.07,2.65,1280,1 19 | 13.83,1.57,2.62,20,115,2.95,3.4,0.4,1.72,6.6,1.13,2.57,1130,1 20 | 14.19,1.59,2.48,16.5,108,3.3,3.93,0.32,1.86,8.7,1.23,2.82,1680,1 21 | 13.64,3.1,2.56,15.2,116,2.7,3.03,0.17,1.66,5.1,0.96,3.36,845,1 22 | 14.06,1.63,2.28,16,126,3,3.17,0.24,2.1,5.65,1.09,3.71,780,1 23 | 12.93,3.8,2.65,18.6,102,2.41,2.41,0.25,1.98,4.5,1.03,3.52,770,1 24 | 13.71,1.86,2.36,16.6,101,2.61,2.88,0.27,1.69,3.8,1.11,4,1035,1 25 | 12.85,1.6,2.52,17.8,95,2.48,2.37,0.26,1.46,3.93,1.09,3.63,1015,1 26 | 13.5,1.81,2.61,20,96,2.53,2.61,0.28,1.66,3.52,1.12,3.82,845,1 27 | 13.05,2.05,3.22,25,124,2.63,2.68,0.47,1.92,3.58,1.13,3.2,830,1 28 | 13.39,1.77,2.62,16.1,93,2.85,2.94,0.34,1.45,4.8,0.92,3.22,1195,1 29 | 13.3,1.72,2.14,17,94,2.4,2.19,0.27,1.35,3.95,1.02,2.77,1285,1 30 | 13.87,1.9,2.8,19.4,107,2.95,2.97,0.37,1.76,4.5,1.25,3.4,915,1 31 | 14.02,1.68,2.21,16,96,2.65,2.33,0.26,1.98,4.7,1.04,3.59,1035,1 32 | 13.73,1.5,2.7,22.5,101,3,3.25,0.29,2.38,5.7,1.19,2.71,1285,1 33 | 13.58,1.66,2.36,19.1,106,2.86,3.19,0.22,1.95,6.9,1.09,2.88,1515,1 34 | 13.68,1.83,2.36,17.2,104,2.42,2.69,0.42,1.97,3.84,1.23,2.87,990,1 35 | 13.76,1.53,2.7,19.5,132,2.95,2.74,0.5,1.35,5.4,1.25,3,1235,1 36 | 13.51,1.8,2.65,19,110,2.35,2.53,0.29,1.54,4.2,1.1,2.87,1095,1 37 | 13.48,1.81,2.41,20.5,100,2.7,2.98,0.26,1.86,5.1,1.04,3.47,920,1 38 | 13.28,1.64,2.84,15.5,110,2.6,2.68,0.34,1.36,4.6,1.09,2.78,880,1 39 | 13.05,1.65,2.55,18,98,2.45,2.43,0.29,1.44,4.25,1.12,2.51,1105,1 40 | 13.07,1.5,2.1,15.5,98,2.4,2.64,0.28,1.37,3.7,1.18,2.69,1020,1 41 | 14.22,3.99,2.51,13.2,128,3,3.04,0.2,2.08,5.1,0.89,3.53,760,1 42 | 13.56,1.71,2.31,16.2,117,3.15,3.29,0.34,2.34,6.13,0.95,3.38,795,1 43 | 13.41,3.84,2.12,18.8,90,2.45,2.68,0.27,1.48,4.28,0.91,3,1035,1 44 | 13.88,1.89,2.59,15,101,3.25,3.56,0.17,1.7,5.43,0.88,3.56,1095,1 45 | 13.24,3.98,2.29,17.5,103,2.64,2.63,0.32,1.66,4.36,0.82,3,680,1 46 | 13.05,1.77,2.1,17,107,3,3,0.28,2.03,5.04,0.88,3.35,885,1 47 | 14.21,4.04,2.44,18.9,111,2.85,2.65,0.3,1.25,5.24,0.87,3.33,1080,1 48 | 14.38,3.59,2.28,16,102,3.25,3.17,0.27,2.19,4.9,1.04,3.44,1065,1 49 | 13.9,1.68,2.12,16,101,3.1,3.39,0.21,2.14,6.1,0.91,3.33,985,1 50 | 14.1,2.02,2.4,18.8,103,2.75,2.92,0.32,2.38,6.2,1.07,2.75,1060,1 51 | 13.94,1.73,2.27,17.4,108,2.88,3.54,0.32,2.08,8.9,1.12,3.1,1260,1 52 | 13.05,1.73,2.04,12.4,92,2.72,3.27,0.17,2.91,7.2,1.12,2.91,1150,1 53 | 13.83,1.65,2.6,17.2,94,2.45,2.99,0.22,2.29,5.6,1.24,3.37,1265,1 54 | 13.82,1.75,2.42,14,111,3.88,3.74,0.32,1.87,7.05,1.01,3.26,1190,1 55 | 13.77,1.9,2.68,17.1,115,3,2.79,0.39,1.68,6.3,1.13,2.93,1375,1 56 | 13.74,1.67,2.25,16.4,118,2.6,2.9,0.21,1.62,5.85,0.92,3.2,1060,1 57 | 13.56,1.73,2.46,20.5,116,2.96,2.78,0.2,2.45,6.25,0.98,3.03,1120,1 58 | 14.22,1.7,2.3,16.3,118,3.2,3,0.26,2.03,6.38,0.94,3.31,970,1 59 | 13.29,1.97,2.68,16.8,102,3,3.23,0.31,1.66,6,1.07,2.84,1270,1 60 | 13.72,1.43,2.5,16.7,108,3.4,3.67,0.19,2.04,6.8,0.89,2.87,1285,1 61 | 12.37,0.94,1.36,10.6,88,1.98,0.57,0.28,0.42,1.95,1.05,1.82,520,2 62 | 12.33,1.1,2.28,16,101,2.05,1.09,0.63,0.41,3.27,1.25,1.67,680,2 63 | 12.64,1.36,2.02,16.8,100,2.02,1.41,0.53,0.62,5.75,0.98,1.59,450,2 64 | 13.67,1.25,1.92,18,94,2.1,1.79,0.32,0.73,3.8,1.23,2.46,630,2 65 | 12.37,1.13,2.16,19,87,3.5,3.1,0.19,1.87,4.45,1.22,2.87,420,2 66 | 12.17,1.45,2.53,19,104,1.89,1.75,0.45,1.03,2.95,1.45,2.23,355,2 67 | 12.37,1.21,2.56,18.1,98,2.42,2.65,0.37,2.08,4.6,1.19,2.3,678,2 68 | 13.11,1.01,1.7,15,78,2.98,3.18,0.26,2.28,5.3,1.12,3.18,502,2 69 | 12.37,1.17,1.92,19.6,78,2.11,2,0.27,1.04,4.68,1.12,3.48,510,2 70 | 13.34,0.94,2.36,17,110,2.53,1.3,0.55,0.42,3.17,1.02,1.93,750,2 71 | 12.21,1.19,1.75,16.8,151,1.85,1.28,0.14,2.5,2.85,1.28,3.07,718,2 72 | 12.29,1.61,2.21,20.4,103,1.1,1.02,0.37,1.46,3.05,0.906,1.82,870,2 73 | 13.86,1.51,2.67,25,86,2.95,2.86,0.21,1.87,3.38,1.36,3.16,410,2 74 | 13.49,1.66,2.24,24,87,1.88,1.84,0.27,1.03,3.74,0.98,2.78,472,2 75 | 12.99,1.67,2.6,30,139,3.3,2.89,0.21,1.96,3.35,1.31,3.5,985,2 76 | 11.96,1.09,2.3,21,101,3.38,2.14,0.13,1.65,3.21,0.99,3.13,886,2 77 | 11.66,1.88,1.92,16,97,1.61,1.57,0.34,1.15,3.8,1.23,2.14,428,2 78 | 13.03,0.9,1.71,16,86,1.95,2.03,0.24,1.46,4.6,1.19,2.48,392,2 79 | 11.84,2.89,2.23,18,112,1.72,1.32,0.43,0.95,2.65,0.96,2.52,500,2 80 | 12.33,0.99,1.95,14.8,136,1.9,1.85,0.35,2.76,3.4,1.06,2.31,750,2 81 | 12.7,3.87,2.4,23,101,2.83,2.55,0.43,1.95,2.57,1.19,3.13,463,2 82 | 12,0.92,2,19,86,2.42,2.26,0.3,1.43,2.5,1.38,3.12,278,2 83 | 12.72,1.81,2.2,18.8,86,2.2,2.53,0.26,1.77,3.9,1.16,3.14,714,2 84 | 12.08,1.13,2.51,24,78,2,1.58,0.4,1.4,2.2,1.31,2.72,630,2 85 | 13.05,3.86,2.32,22.5,85,1.65,1.59,0.61,1.62,4.8,0.84,2.01,515,2 86 | 11.84,0.89,2.58,18,94,2.2,2.21,0.22,2.35,3.05,0.79,3.08,520,2 87 | 12.67,0.98,2.24,18,99,2.2,1.94,0.3,1.46,2.62,1.23,3.16,450,2 88 | 12.16,1.61,2.31,22.8,90,1.78,1.69,0.43,1.56,2.45,1.33,2.26,495,2 89 | 11.65,1.67,2.62,26,88,1.92,1.61,0.4,1.34,2.6,1.36,3.21,562,2 90 | 11.64,2.06,2.46,21.6,84,1.95,1.69,0.48,1.35,2.8,1,2.75,680,2 91 | 12.08,1.33,2.3,23.6,70,2.2,1.59,0.42,1.38,1.74,1.07,3.21,625,2 92 | 12.08,1.83,2.32,18.5,81,1.6,1.5,0.52,1.64,2.4,1.08,2.27,480,2 93 | 12,1.51,2.42,22,86,1.45,1.25,0.5,1.63,3.6,1.05,2.65,450,2 94 | 12.69,1.53,2.26,20.7,80,1.38,1.46,0.58,1.62,3.05,0.96,2.06,495,2 95 | 12.29,2.83,2.22,18,88,2.45,2.25,0.25,1.99,2.15,1.15,3.3,290,2 96 | 11.62,1.99,2.28,18,98,3.02,2.26,0.17,1.35,3.25,1.16,2.96,345,2 97 | 12.47,1.52,2.2,19,162,2.5,2.27,0.32,3.28,2.6,1.16,2.63,937,2 98 | 11.81,2.12,2.74,21.5,134,1.6,0.99,0.14,1.56,2.5,0.95,2.26,625,2 99 | 12.29,1.41,1.98,16,85,2.55,2.5,0.29,1.77,2.9,1.23,2.74,428,2 100 | 12.37,1.07,2.1,18.5,88,3.52,3.75,0.24,1.95,4.5,1.04,2.77,660,2 101 | 12.29,3.17,2.21,18,88,2.85,2.99,0.45,2.81,2.3,1.42,2.83,406,2 102 | 12.08,2.08,1.7,17.5,97,2.23,2.17,0.26,1.4,3.3,1.27,2.96,710,2 103 | 12.6,1.34,1.9,18.5,88,1.45,1.36,0.29,1.35,2.45,1.04,2.77,562,2 104 | 12.34,2.45,2.46,21,98,2.56,2.11,0.34,1.31,2.8,0.8,3.38,438,2 105 | 11.82,1.72,1.88,19.5,86,2.5,1.64,0.37,1.42,2.06,0.94,2.44,415,2 106 | 12.51,1.73,1.98,20.5,85,2.2,1.92,0.32,1.48,2.94,1.04,3.57,672,2 107 | 12.42,2.55,2.27,22,90,1.68,1.84,0.66,1.42,2.7,0.86,3.3,315,2 108 | 12.25,1.73,2.12,19,80,1.65,2.03,0.37,1.63,3.4,1,3.17,510,2 109 | 12.72,1.75,2.28,22.5,84,1.38,1.76,0.48,1.63,3.3,0.88,2.42,488,2 110 | 12.22,1.29,1.94,19,92,2.36,2.04,0.39,2.08,2.7,0.86,3.02,312,2 111 | 11.61,1.35,2.7,20,94,2.74,2.92,0.29,2.49,2.65,0.96,3.26,680,2 112 | 11.46,3.74,1.82,19.5,107,3.18,2.58,0.24,3.58,2.9,0.75,2.81,562,2 113 | 12.52,2.43,2.17,21,88,2.55,2.27,0.26,1.22,2,0.9,2.78,325,2 114 | 11.76,2.68,2.92,20,103,1.75,2.03,0.6,1.05,3.8,1.23,2.5,607,2 115 | 11.41,0.74,2.5,21,88,2.48,2.01,0.42,1.44,3.08,1.1,2.31,434,2 116 | 12.08,1.39,2.5,22.5,84,2.56,2.29,0.43,1.04,2.9,0.93,3.19,385,2 117 | 11.03,1.51,2.2,21.5,85,2.46,2.17,0.52,2.01,1.9,1.71,2.87,407,2 118 | 11.82,1.47,1.99,20.8,86,1.98,1.6,0.3,1.53,1.95,0.95,3.33,495,2 119 | 12.42,1.61,2.19,22.5,108,2,2.09,0.34,1.61,2.06,1.06,2.96,345,2 120 | 12.77,3.43,1.98,16,80,1.63,1.25,0.43,0.83,3.4,0.7,2.12,372,2 121 | 12,3.43,2,19,87,2,1.64,0.37,1.87,1.28,0.93,3.05,564,2 122 | 11.45,2.4,2.42,20,96,2.9,2.79,0.32,1.83,3.25,0.8,3.39,625,2 123 | 11.56,2.05,3.23,28.5,119,3.18,5.08,0.47,1.87,6,0.93,3.69,465,2 124 | 12.42,4.43,2.73,26.5,102,2.2,2.13,0.43,1.71,2.08,0.92,3.12,365,2 125 | 13.05,5.8,2.13,21.5,86,2.62,2.65,0.3,2.01,2.6,0.73,3.1,380,2 126 | 11.87,4.31,2.39,21,82,2.86,3.03,0.21,2.91,2.8,0.75,3.64,380,2 127 | 12.07,2.16,2.17,21,85,2.6,2.65,0.37,1.35,2.76,0.86,3.28,378,2 128 | 12.43,1.53,2.29,21.5,86,2.74,3.15,0.39,1.77,3.94,0.69,2.84,352,2 129 | 11.79,2.13,2.78,28.5,92,2.13,2.24,0.58,1.76,3,0.97,2.44,466,2 130 | 12.37,1.63,2.3,24.5,88,2.22,2.45,0.4,1.9,2.12,0.89,2.78,342,2 131 | 12.04,4.3,2.38,22,80,2.1,1.75,0.42,1.35,2.6,0.79,2.57,580,2 132 | 12.86,1.35,2.32,18,122,1.51,1.25,0.21,0.94,4.1,0.76,1.29,630,3 133 | 12.88,2.99,2.4,20,104,1.3,1.22,0.24,0.83,5.4,0.74,1.42,530,3 134 | 12.81,2.31,2.4,24,98,1.15,1.09,0.27,0.83,5.7,0.66,1.36,560,3 135 | 12.7,3.55,2.36,21.5,106,1.7,1.2,0.17,0.84,5,0.78,1.29,600,3 136 | 12.51,1.24,2.25,17.5,85,2,0.58,0.6,1.25,5.45,0.75,1.51,650,3 137 | 12.6,2.46,2.2,18.5,94,1.62,0.66,0.63,0.94,7.1,0.73,1.58,695,3 138 | 12.25,4.72,2.54,21,89,1.38,0.47,0.53,0.8,3.85,0.75,1.27,720,3 139 | 12.53,5.51,2.64,25,96,1.79,0.6,0.63,1.1,5,0.82,1.69,515,3 140 | 13.49,3.59,2.19,19.5,88,1.62,0.48,0.58,0.88,5.7,0.81,1.82,580,3 141 | 12.84,2.96,2.61,24,101,2.32,0.6,0.53,0.81,4.92,0.89,2.15,590,3 142 | 12.93,2.81,2.7,21,96,1.54,0.5,0.53,0.75,4.6,0.77,2.31,600,3 143 | 13.36,2.56,2.35,20,89,1.4,0.5,0.37,0.64,5.6,0.7,2.47,780,3 144 | 13.52,3.17,2.72,23.5,97,1.55,0.52,0.5,0.55,4.35,0.89,2.06,520,3 145 | 13.62,4.95,2.35,20,92,2,0.8,0.47,1.02,4.4,0.91,2.05,550,3 146 | 12.25,3.88,2.2,18.5,112,1.38,0.78,0.29,1.14,8.21,0.65,2,855,3 147 | 13.16,3.57,2.15,21,102,1.5,0.55,0.43,1.3,4,0.6,1.68,830,3 148 | 13.88,5.04,2.23,20,80,0.98,0.34,0.4,0.68,4.9,0.58,1.33,415,3 149 | 12.87,4.61,2.48,21.5,86,1.7,0.65,0.47,0.86,7.65,0.54,1.86,625,3 150 | 13.32,3.24,2.38,21.5,92,1.93,0.76,0.45,1.25,8.42,0.55,1.62,650,3 151 | 13.08,3.9,2.36,21.5,113,1.41,1.39,0.34,1.14,9.4,0.57,1.33,550,3 152 | 13.5,3.12,2.62,24,123,1.4,1.57,0.22,1.25,8.6,0.59,1.3,500,3 153 | 12.79,2.67,2.48,22,112,1.48,1.36,0.24,1.26,10.8,0.48,1.47,480,3 154 | 13.11,1.9,2.75,25.5,116,2.2,1.28,0.26,1.56,7.1,0.61,1.33,425,3 155 | 13.23,3.3,2.28,18.5,98,1.8,0.83,0.61,1.87,10.52,0.56,1.51,675,3 156 | 12.58,1.29,2.1,20,103,1.48,0.58,0.53,1.4,7.6,0.58,1.55,640,3 157 | 13.17,5.19,2.32,22,93,1.74,0.63,0.61,1.55,7.9,0.6,1.48,725,3 158 | 13.84,4.12,2.38,19.5,89,1.8,0.83,0.48,1.56,9.01,0.57,1.64,480,3 159 | 12.45,3.03,2.64,27,97,1.9,0.58,0.63,1.14,7.5,0.67,1.73,880,3 160 | 14.34,1.68,2.7,25,98,2.8,1.31,0.53,2.7,13,0.57,1.96,660,3 161 | 13.48,1.67,2.64,22.5,89,2.6,1.1,0.52,2.29,11.75,0.57,1.78,620,3 162 | 12.36,3.83,2.38,21,88,2.3,0.92,0.5,1.04,7.65,0.56,1.58,520,3 163 | 13.69,3.26,2.54,20,107,1.83,0.56,0.5,0.8,5.88,0.96,1.82,680,3 164 | 12.85,3.27,2.58,22,106,1.65,0.6,0.6,0.96,5.58,0.87,2.11,570,3 165 | 12.96,3.45,2.35,18.5,106,1.39,0.7,0.4,0.94,5.28,0.68,1.75,675,3 166 | 13.78,2.76,2.3,22,90,1.35,0.68,0.41,1.03,9.58,0.7,1.68,615,3 167 | 13.73,4.36,2.26,22.5,88,1.28,0.47,0.52,1.15,6.62,0.78,1.75,520,3 168 | 13.45,3.7,2.6,23,111,1.7,0.92,0.43,1.46,10.68,0.85,1.56,695,3 169 | 12.82,3.37,2.3,19.5,88,1.48,0.66,0.4,0.97,10.26,0.72,1.75,685,3 170 | 13.58,2.58,2.69,24.5,105,1.55,0.84,0.39,1.54,8.66,0.74,1.8,750,3 171 | 13.4,4.6,2.86,25,112,1.98,0.96,0.27,1.11,8.5,0.67,1.92,630,3 172 | 12.2,3.03,2.32,19,96,1.25,0.49,0.4,0.73,5.5,0.66,1.83,510,3 173 | 12.77,2.39,2.28,19.5,86,1.39,0.51,0.48,0.64,9.899999,0.57,1.63,470,3 174 | 14.16,2.51,2.48,20,91,1.68,0.7,0.44,1.24,9.7,0.62,1.71,660,3 175 | 13.71,5.65,2.45,20.5,95,1.68,0.61,0.52,1.06,7.7,0.64,1.74,740,3 176 | 13.4,3.91,2.48,23,102,1.8,0.75,0.43,1.41,7.3,0.7,1.56,750,3 177 | 13.27,4.28,2.26,20,120,1.59,0.69,0.43,1.35,10.2,0.59,1.56,835,3 178 | 13.17,2.59,2.37,20,120,1.65,0.68,0.53,1.46,9.3,0.6,1.62,840,3 179 | 14.13,4.1,2.74,24.5,96,2.05,0.76,0.56,1.35,9.2,0.61,1.6,560,3 180 | -------------------------------------------------------------------------------- /25- PCA/PCA.py: -------------------------------------------------------------------------------- 1 | # PCA 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Juices.csv') 10 | X = data.iloc[:,0:13].values 11 | y = data.iloc[:,13].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | # Applying PCA 28 | from sklearn.decomposition import PCA 29 | pca = PCA(n_components = 2 ) 30 | X_train = pca.fit_transform(X_train) 31 | X_test = pca.transform(X_test) 32 | explained_variance = pca.explained_variance_ratio_ 33 | 34 | # Fitting the Logistic Regression model to training dataset: 35 | from sklearn.linear_model import LogisticRegression 36 | classifier = LogisticRegression(random_state = 0) 37 | classifier.fit(X_train, y_train) 38 | 39 | # Predection Process: 40 | y_pred = classifier.predict(X_test) 41 | 42 | # Confusion Matrix: 43 | from sklearn.metrics import confusion_matrix 44 | cm = confusion_matrix(y_test, y_pred) 45 | 46 | # Visulaization the training set results 47 | from matplotlib.colors import ListedColormap 48 | X_set, y_set = X_train , y_train 49 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 50 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 51 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 52 | alpha = 0.75 , cmap = ListedColormap(('red', 'green','blue'))) 53 | plt.xlim(x1.min(), x1.max()) 54 | plt.ylim(x2.min(), x2.max()) 55 | 56 | for i,j in enumerate(np.unique(y_set)): 57 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 58 | c = ListedColormap(('red','green','blue')) (i), label = j) 59 | plt.title('Classifier (Training set)') 60 | plt.xlabel('PCA 1') 61 | plt.ylabel('PCA 2') 62 | plt.legend() 63 | plt.show() 64 | 65 | 66 | # Visulaization the training set results 67 | from matplotlib.colors import ListedColormap 68 | X_set, y_set = X_test , y_test 69 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 70 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 71 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 72 | alpha = 0.75 , cmap = ListedColormap(('red', 'green','blue'))) 73 | plt.xlim(x1.min(), x1.max()) 74 | plt.ylim(x2.min(), x2.max()) 75 | 76 | for i,j in enumerate(np.unique(y_set)): 77 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 78 | c = ListedColormap(('red','green','blue')) (i), label = j) 79 | plt.title('Classifier (Training set)') 80 | plt.xlabel('PCA 1') 81 | plt.ylabel('PCA 2') 82 | plt.legend() 83 | plt.show() 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /26- LDA/Juices.csv: -------------------------------------------------------------------------------- 1 | Strawberries,Apple ,Mango,Grapes,Kiwi,Carrot,Green coconut ,Guava,Limes,Oranges ,Pineapple,Raspberries ,Water melon ,Customer_Segment 2 | 14.23,1.71,2.43,15.6,127,2.8,3.06,0.28,2.29,5.64,1.04,3.92,1065,1 3 | 13.2,1.78,2.14,11.2,100,2.65,2.76,0.26,1.28,4.38,1.05,3.4,1050,1 4 | 13.16,2.36,2.67,18.6,101,2.8,3.24,0.3,2.81,5.68,1.03,3.17,1185,1 5 | 14.37,1.95,2.5,16.8,113,3.85,3.49,0.24,2.18,7.8,0.86,3.45,1480,1 6 | 13.24,2.59,2.87,21,118,2.8,2.69,0.39,1.82,4.32,1.04,2.93,735,1 7 | 14.2,1.76,2.45,15.2,112,3.27,3.39,0.34,1.97,6.75,1.05,2.85,1450,1 8 | 14.39,1.87,2.45,14.6,96,2.5,2.52,0.3,1.98,5.25,1.02,3.58,1290,1 9 | 14.06,2.15,2.61,17.6,121,2.6,2.51,0.31,1.25,5.05,1.06,3.58,1295,1 10 | 14.83,1.64,2.17,14,97,2.8,2.98,0.29,1.98,5.2,1.08,2.85,1045,1 11 | 13.86,1.35,2.27,16,98,2.98,3.15,0.22,1.85,7.22,1.01,3.55,1045,1 12 | 14.1,2.16,2.3,18,105,2.95,3.32,0.22,2.38,5.75,1.25,3.17,1510,1 13 | 14.12,1.48,2.32,16.8,95,2.2,2.43,0.26,1.57,5,1.17,2.82,1280,1 14 | 13.75,1.73,2.41,16,89,2.6,2.76,0.29,1.81,5.6,1.15,2.9,1320,1 15 | 14.75,1.73,2.39,11.4,91,3.1,3.69,0.43,2.81,5.4,1.25,2.73,1150,1 16 | 14.38,1.87,2.38,12,102,3.3,3.64,0.29,2.96,7.5,1.2,3,1547,1 17 | 13.63,1.81,2.7,17.2,112,2.85,2.91,0.3,1.46,7.3,1.28,2.88,1310,1 18 | 14.3,1.92,2.72,20,120,2.8,3.14,0.33,1.97,6.2,1.07,2.65,1280,1 19 | 13.83,1.57,2.62,20,115,2.95,3.4,0.4,1.72,6.6,1.13,2.57,1130,1 20 | 14.19,1.59,2.48,16.5,108,3.3,3.93,0.32,1.86,8.7,1.23,2.82,1680,1 21 | 13.64,3.1,2.56,15.2,116,2.7,3.03,0.17,1.66,5.1,0.96,3.36,845,1 22 | 14.06,1.63,2.28,16,126,3,3.17,0.24,2.1,5.65,1.09,3.71,780,1 23 | 12.93,3.8,2.65,18.6,102,2.41,2.41,0.25,1.98,4.5,1.03,3.52,770,1 24 | 13.71,1.86,2.36,16.6,101,2.61,2.88,0.27,1.69,3.8,1.11,4,1035,1 25 | 12.85,1.6,2.52,17.8,95,2.48,2.37,0.26,1.46,3.93,1.09,3.63,1015,1 26 | 13.5,1.81,2.61,20,96,2.53,2.61,0.28,1.66,3.52,1.12,3.82,845,1 27 | 13.05,2.05,3.22,25,124,2.63,2.68,0.47,1.92,3.58,1.13,3.2,830,1 28 | 13.39,1.77,2.62,16.1,93,2.85,2.94,0.34,1.45,4.8,0.92,3.22,1195,1 29 | 13.3,1.72,2.14,17,94,2.4,2.19,0.27,1.35,3.95,1.02,2.77,1285,1 30 | 13.87,1.9,2.8,19.4,107,2.95,2.97,0.37,1.76,4.5,1.25,3.4,915,1 31 | 14.02,1.68,2.21,16,96,2.65,2.33,0.26,1.98,4.7,1.04,3.59,1035,1 32 | 13.73,1.5,2.7,22.5,101,3,3.25,0.29,2.38,5.7,1.19,2.71,1285,1 33 | 13.58,1.66,2.36,19.1,106,2.86,3.19,0.22,1.95,6.9,1.09,2.88,1515,1 34 | 13.68,1.83,2.36,17.2,104,2.42,2.69,0.42,1.97,3.84,1.23,2.87,990,1 35 | 13.76,1.53,2.7,19.5,132,2.95,2.74,0.5,1.35,5.4,1.25,3,1235,1 36 | 13.51,1.8,2.65,19,110,2.35,2.53,0.29,1.54,4.2,1.1,2.87,1095,1 37 | 13.48,1.81,2.41,20.5,100,2.7,2.98,0.26,1.86,5.1,1.04,3.47,920,1 38 | 13.28,1.64,2.84,15.5,110,2.6,2.68,0.34,1.36,4.6,1.09,2.78,880,1 39 | 13.05,1.65,2.55,18,98,2.45,2.43,0.29,1.44,4.25,1.12,2.51,1105,1 40 | 13.07,1.5,2.1,15.5,98,2.4,2.64,0.28,1.37,3.7,1.18,2.69,1020,1 41 | 14.22,3.99,2.51,13.2,128,3,3.04,0.2,2.08,5.1,0.89,3.53,760,1 42 | 13.56,1.71,2.31,16.2,117,3.15,3.29,0.34,2.34,6.13,0.95,3.38,795,1 43 | 13.41,3.84,2.12,18.8,90,2.45,2.68,0.27,1.48,4.28,0.91,3,1035,1 44 | 13.88,1.89,2.59,15,101,3.25,3.56,0.17,1.7,5.43,0.88,3.56,1095,1 45 | 13.24,3.98,2.29,17.5,103,2.64,2.63,0.32,1.66,4.36,0.82,3,680,1 46 | 13.05,1.77,2.1,17,107,3,3,0.28,2.03,5.04,0.88,3.35,885,1 47 | 14.21,4.04,2.44,18.9,111,2.85,2.65,0.3,1.25,5.24,0.87,3.33,1080,1 48 | 14.38,3.59,2.28,16,102,3.25,3.17,0.27,2.19,4.9,1.04,3.44,1065,1 49 | 13.9,1.68,2.12,16,101,3.1,3.39,0.21,2.14,6.1,0.91,3.33,985,1 50 | 14.1,2.02,2.4,18.8,103,2.75,2.92,0.32,2.38,6.2,1.07,2.75,1060,1 51 | 13.94,1.73,2.27,17.4,108,2.88,3.54,0.32,2.08,8.9,1.12,3.1,1260,1 52 | 13.05,1.73,2.04,12.4,92,2.72,3.27,0.17,2.91,7.2,1.12,2.91,1150,1 53 | 13.83,1.65,2.6,17.2,94,2.45,2.99,0.22,2.29,5.6,1.24,3.37,1265,1 54 | 13.82,1.75,2.42,14,111,3.88,3.74,0.32,1.87,7.05,1.01,3.26,1190,1 55 | 13.77,1.9,2.68,17.1,115,3,2.79,0.39,1.68,6.3,1.13,2.93,1375,1 56 | 13.74,1.67,2.25,16.4,118,2.6,2.9,0.21,1.62,5.85,0.92,3.2,1060,1 57 | 13.56,1.73,2.46,20.5,116,2.96,2.78,0.2,2.45,6.25,0.98,3.03,1120,1 58 | 14.22,1.7,2.3,16.3,118,3.2,3,0.26,2.03,6.38,0.94,3.31,970,1 59 | 13.29,1.97,2.68,16.8,102,3,3.23,0.31,1.66,6,1.07,2.84,1270,1 60 | 13.72,1.43,2.5,16.7,108,3.4,3.67,0.19,2.04,6.8,0.89,2.87,1285,1 61 | 12.37,0.94,1.36,10.6,88,1.98,0.57,0.28,0.42,1.95,1.05,1.82,520,2 62 | 12.33,1.1,2.28,16,101,2.05,1.09,0.63,0.41,3.27,1.25,1.67,680,2 63 | 12.64,1.36,2.02,16.8,100,2.02,1.41,0.53,0.62,5.75,0.98,1.59,450,2 64 | 13.67,1.25,1.92,18,94,2.1,1.79,0.32,0.73,3.8,1.23,2.46,630,2 65 | 12.37,1.13,2.16,19,87,3.5,3.1,0.19,1.87,4.45,1.22,2.87,420,2 66 | 12.17,1.45,2.53,19,104,1.89,1.75,0.45,1.03,2.95,1.45,2.23,355,2 67 | 12.37,1.21,2.56,18.1,98,2.42,2.65,0.37,2.08,4.6,1.19,2.3,678,2 68 | 13.11,1.01,1.7,15,78,2.98,3.18,0.26,2.28,5.3,1.12,3.18,502,2 69 | 12.37,1.17,1.92,19.6,78,2.11,2,0.27,1.04,4.68,1.12,3.48,510,2 70 | 13.34,0.94,2.36,17,110,2.53,1.3,0.55,0.42,3.17,1.02,1.93,750,2 71 | 12.21,1.19,1.75,16.8,151,1.85,1.28,0.14,2.5,2.85,1.28,3.07,718,2 72 | 12.29,1.61,2.21,20.4,103,1.1,1.02,0.37,1.46,3.05,0.906,1.82,870,2 73 | 13.86,1.51,2.67,25,86,2.95,2.86,0.21,1.87,3.38,1.36,3.16,410,2 74 | 13.49,1.66,2.24,24,87,1.88,1.84,0.27,1.03,3.74,0.98,2.78,472,2 75 | 12.99,1.67,2.6,30,139,3.3,2.89,0.21,1.96,3.35,1.31,3.5,985,2 76 | 11.96,1.09,2.3,21,101,3.38,2.14,0.13,1.65,3.21,0.99,3.13,886,2 77 | 11.66,1.88,1.92,16,97,1.61,1.57,0.34,1.15,3.8,1.23,2.14,428,2 78 | 13.03,0.9,1.71,16,86,1.95,2.03,0.24,1.46,4.6,1.19,2.48,392,2 79 | 11.84,2.89,2.23,18,112,1.72,1.32,0.43,0.95,2.65,0.96,2.52,500,2 80 | 12.33,0.99,1.95,14.8,136,1.9,1.85,0.35,2.76,3.4,1.06,2.31,750,2 81 | 12.7,3.87,2.4,23,101,2.83,2.55,0.43,1.95,2.57,1.19,3.13,463,2 82 | 12,0.92,2,19,86,2.42,2.26,0.3,1.43,2.5,1.38,3.12,278,2 83 | 12.72,1.81,2.2,18.8,86,2.2,2.53,0.26,1.77,3.9,1.16,3.14,714,2 84 | 12.08,1.13,2.51,24,78,2,1.58,0.4,1.4,2.2,1.31,2.72,630,2 85 | 13.05,3.86,2.32,22.5,85,1.65,1.59,0.61,1.62,4.8,0.84,2.01,515,2 86 | 11.84,0.89,2.58,18,94,2.2,2.21,0.22,2.35,3.05,0.79,3.08,520,2 87 | 12.67,0.98,2.24,18,99,2.2,1.94,0.3,1.46,2.62,1.23,3.16,450,2 88 | 12.16,1.61,2.31,22.8,90,1.78,1.69,0.43,1.56,2.45,1.33,2.26,495,2 89 | 11.65,1.67,2.62,26,88,1.92,1.61,0.4,1.34,2.6,1.36,3.21,562,2 90 | 11.64,2.06,2.46,21.6,84,1.95,1.69,0.48,1.35,2.8,1,2.75,680,2 91 | 12.08,1.33,2.3,23.6,70,2.2,1.59,0.42,1.38,1.74,1.07,3.21,625,2 92 | 12.08,1.83,2.32,18.5,81,1.6,1.5,0.52,1.64,2.4,1.08,2.27,480,2 93 | 12,1.51,2.42,22,86,1.45,1.25,0.5,1.63,3.6,1.05,2.65,450,2 94 | 12.69,1.53,2.26,20.7,80,1.38,1.46,0.58,1.62,3.05,0.96,2.06,495,2 95 | 12.29,2.83,2.22,18,88,2.45,2.25,0.25,1.99,2.15,1.15,3.3,290,2 96 | 11.62,1.99,2.28,18,98,3.02,2.26,0.17,1.35,3.25,1.16,2.96,345,2 97 | 12.47,1.52,2.2,19,162,2.5,2.27,0.32,3.28,2.6,1.16,2.63,937,2 98 | 11.81,2.12,2.74,21.5,134,1.6,0.99,0.14,1.56,2.5,0.95,2.26,625,2 99 | 12.29,1.41,1.98,16,85,2.55,2.5,0.29,1.77,2.9,1.23,2.74,428,2 100 | 12.37,1.07,2.1,18.5,88,3.52,3.75,0.24,1.95,4.5,1.04,2.77,660,2 101 | 12.29,3.17,2.21,18,88,2.85,2.99,0.45,2.81,2.3,1.42,2.83,406,2 102 | 12.08,2.08,1.7,17.5,97,2.23,2.17,0.26,1.4,3.3,1.27,2.96,710,2 103 | 12.6,1.34,1.9,18.5,88,1.45,1.36,0.29,1.35,2.45,1.04,2.77,562,2 104 | 12.34,2.45,2.46,21,98,2.56,2.11,0.34,1.31,2.8,0.8,3.38,438,2 105 | 11.82,1.72,1.88,19.5,86,2.5,1.64,0.37,1.42,2.06,0.94,2.44,415,2 106 | 12.51,1.73,1.98,20.5,85,2.2,1.92,0.32,1.48,2.94,1.04,3.57,672,2 107 | 12.42,2.55,2.27,22,90,1.68,1.84,0.66,1.42,2.7,0.86,3.3,315,2 108 | 12.25,1.73,2.12,19,80,1.65,2.03,0.37,1.63,3.4,1,3.17,510,2 109 | 12.72,1.75,2.28,22.5,84,1.38,1.76,0.48,1.63,3.3,0.88,2.42,488,2 110 | 12.22,1.29,1.94,19,92,2.36,2.04,0.39,2.08,2.7,0.86,3.02,312,2 111 | 11.61,1.35,2.7,20,94,2.74,2.92,0.29,2.49,2.65,0.96,3.26,680,2 112 | 11.46,3.74,1.82,19.5,107,3.18,2.58,0.24,3.58,2.9,0.75,2.81,562,2 113 | 12.52,2.43,2.17,21,88,2.55,2.27,0.26,1.22,2,0.9,2.78,325,2 114 | 11.76,2.68,2.92,20,103,1.75,2.03,0.6,1.05,3.8,1.23,2.5,607,2 115 | 11.41,0.74,2.5,21,88,2.48,2.01,0.42,1.44,3.08,1.1,2.31,434,2 116 | 12.08,1.39,2.5,22.5,84,2.56,2.29,0.43,1.04,2.9,0.93,3.19,385,2 117 | 11.03,1.51,2.2,21.5,85,2.46,2.17,0.52,2.01,1.9,1.71,2.87,407,2 118 | 11.82,1.47,1.99,20.8,86,1.98,1.6,0.3,1.53,1.95,0.95,3.33,495,2 119 | 12.42,1.61,2.19,22.5,108,2,2.09,0.34,1.61,2.06,1.06,2.96,345,2 120 | 12.77,3.43,1.98,16,80,1.63,1.25,0.43,0.83,3.4,0.7,2.12,372,2 121 | 12,3.43,2,19,87,2,1.64,0.37,1.87,1.28,0.93,3.05,564,2 122 | 11.45,2.4,2.42,20,96,2.9,2.79,0.32,1.83,3.25,0.8,3.39,625,2 123 | 11.56,2.05,3.23,28.5,119,3.18,5.08,0.47,1.87,6,0.93,3.69,465,2 124 | 12.42,4.43,2.73,26.5,102,2.2,2.13,0.43,1.71,2.08,0.92,3.12,365,2 125 | 13.05,5.8,2.13,21.5,86,2.62,2.65,0.3,2.01,2.6,0.73,3.1,380,2 126 | 11.87,4.31,2.39,21,82,2.86,3.03,0.21,2.91,2.8,0.75,3.64,380,2 127 | 12.07,2.16,2.17,21,85,2.6,2.65,0.37,1.35,2.76,0.86,3.28,378,2 128 | 12.43,1.53,2.29,21.5,86,2.74,3.15,0.39,1.77,3.94,0.69,2.84,352,2 129 | 11.79,2.13,2.78,28.5,92,2.13,2.24,0.58,1.76,3,0.97,2.44,466,2 130 | 12.37,1.63,2.3,24.5,88,2.22,2.45,0.4,1.9,2.12,0.89,2.78,342,2 131 | 12.04,4.3,2.38,22,80,2.1,1.75,0.42,1.35,2.6,0.79,2.57,580,2 132 | 12.86,1.35,2.32,18,122,1.51,1.25,0.21,0.94,4.1,0.76,1.29,630,3 133 | 12.88,2.99,2.4,20,104,1.3,1.22,0.24,0.83,5.4,0.74,1.42,530,3 134 | 12.81,2.31,2.4,24,98,1.15,1.09,0.27,0.83,5.7,0.66,1.36,560,3 135 | 12.7,3.55,2.36,21.5,106,1.7,1.2,0.17,0.84,5,0.78,1.29,600,3 136 | 12.51,1.24,2.25,17.5,85,2,0.58,0.6,1.25,5.45,0.75,1.51,650,3 137 | 12.6,2.46,2.2,18.5,94,1.62,0.66,0.63,0.94,7.1,0.73,1.58,695,3 138 | 12.25,4.72,2.54,21,89,1.38,0.47,0.53,0.8,3.85,0.75,1.27,720,3 139 | 12.53,5.51,2.64,25,96,1.79,0.6,0.63,1.1,5,0.82,1.69,515,3 140 | 13.49,3.59,2.19,19.5,88,1.62,0.48,0.58,0.88,5.7,0.81,1.82,580,3 141 | 12.84,2.96,2.61,24,101,2.32,0.6,0.53,0.81,4.92,0.89,2.15,590,3 142 | 12.93,2.81,2.7,21,96,1.54,0.5,0.53,0.75,4.6,0.77,2.31,600,3 143 | 13.36,2.56,2.35,20,89,1.4,0.5,0.37,0.64,5.6,0.7,2.47,780,3 144 | 13.52,3.17,2.72,23.5,97,1.55,0.52,0.5,0.55,4.35,0.89,2.06,520,3 145 | 13.62,4.95,2.35,20,92,2,0.8,0.47,1.02,4.4,0.91,2.05,550,3 146 | 12.25,3.88,2.2,18.5,112,1.38,0.78,0.29,1.14,8.21,0.65,2,855,3 147 | 13.16,3.57,2.15,21,102,1.5,0.55,0.43,1.3,4,0.6,1.68,830,3 148 | 13.88,5.04,2.23,20,80,0.98,0.34,0.4,0.68,4.9,0.58,1.33,415,3 149 | 12.87,4.61,2.48,21.5,86,1.7,0.65,0.47,0.86,7.65,0.54,1.86,625,3 150 | 13.32,3.24,2.38,21.5,92,1.93,0.76,0.45,1.25,8.42,0.55,1.62,650,3 151 | 13.08,3.9,2.36,21.5,113,1.41,1.39,0.34,1.14,9.4,0.57,1.33,550,3 152 | 13.5,3.12,2.62,24,123,1.4,1.57,0.22,1.25,8.6,0.59,1.3,500,3 153 | 12.79,2.67,2.48,22,112,1.48,1.36,0.24,1.26,10.8,0.48,1.47,480,3 154 | 13.11,1.9,2.75,25.5,116,2.2,1.28,0.26,1.56,7.1,0.61,1.33,425,3 155 | 13.23,3.3,2.28,18.5,98,1.8,0.83,0.61,1.87,10.52,0.56,1.51,675,3 156 | 12.58,1.29,2.1,20,103,1.48,0.58,0.53,1.4,7.6,0.58,1.55,640,3 157 | 13.17,5.19,2.32,22,93,1.74,0.63,0.61,1.55,7.9,0.6,1.48,725,3 158 | 13.84,4.12,2.38,19.5,89,1.8,0.83,0.48,1.56,9.01,0.57,1.64,480,3 159 | 12.45,3.03,2.64,27,97,1.9,0.58,0.63,1.14,7.5,0.67,1.73,880,3 160 | 14.34,1.68,2.7,25,98,2.8,1.31,0.53,2.7,13,0.57,1.96,660,3 161 | 13.48,1.67,2.64,22.5,89,2.6,1.1,0.52,2.29,11.75,0.57,1.78,620,3 162 | 12.36,3.83,2.38,21,88,2.3,0.92,0.5,1.04,7.65,0.56,1.58,520,3 163 | 13.69,3.26,2.54,20,107,1.83,0.56,0.5,0.8,5.88,0.96,1.82,680,3 164 | 12.85,3.27,2.58,22,106,1.65,0.6,0.6,0.96,5.58,0.87,2.11,570,3 165 | 12.96,3.45,2.35,18.5,106,1.39,0.7,0.4,0.94,5.28,0.68,1.75,675,3 166 | 13.78,2.76,2.3,22,90,1.35,0.68,0.41,1.03,9.58,0.7,1.68,615,3 167 | 13.73,4.36,2.26,22.5,88,1.28,0.47,0.52,1.15,6.62,0.78,1.75,520,3 168 | 13.45,3.7,2.6,23,111,1.7,0.92,0.43,1.46,10.68,0.85,1.56,695,3 169 | 12.82,3.37,2.3,19.5,88,1.48,0.66,0.4,0.97,10.26,0.72,1.75,685,3 170 | 13.58,2.58,2.69,24.5,105,1.55,0.84,0.39,1.54,8.66,0.74,1.8,750,3 171 | 13.4,4.6,2.86,25,112,1.98,0.96,0.27,1.11,8.5,0.67,1.92,630,3 172 | 12.2,3.03,2.32,19,96,1.25,0.49,0.4,0.73,5.5,0.66,1.83,510,3 173 | 12.77,2.39,2.28,19.5,86,1.39,0.51,0.48,0.64,9.899999,0.57,1.63,470,3 174 | 14.16,2.51,2.48,20,91,1.68,0.7,0.44,1.24,9.7,0.62,1.71,660,3 175 | 13.71,5.65,2.45,20.5,95,1.68,0.61,0.52,1.06,7.7,0.64,1.74,740,3 176 | 13.4,3.91,2.48,23,102,1.8,0.75,0.43,1.41,7.3,0.7,1.56,750,3 177 | 13.27,4.28,2.26,20,120,1.59,0.69,0.43,1.35,10.2,0.59,1.56,835,3 178 | 13.17,2.59,2.37,20,120,1.65,0.68,0.53,1.46,9.3,0.6,1.62,840,3 179 | 14.13,4.1,2.74,24.5,96,2.05,0.76,0.56,1.35,9.2,0.61,1.6,560,3 180 | -------------------------------------------------------------------------------- /26- LDA/LDA.py: -------------------------------------------------------------------------------- 1 | # LDA 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Juices.csv') 10 | X = data.iloc[:,0:13].values 11 | y = data.iloc[:,13].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | 27 | # Applying LDA 28 | from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA 29 | lda = LDA(n_components = 2 ) 30 | X_train = lda.fit_transform(X_train,y_train) 31 | X_test = lda.transform(X_test) 32 | 33 | 34 | # Fitting the Logistic Regression model to training dataset: 35 | from sklearn.linear_model import LogisticRegression 36 | classifier = LogisticRegression(random_state = 0) 37 | classifier.fit(X_train, y_train) 38 | 39 | # Predection Process: 40 | y_pred = classifier.predict(X_test) 41 | 42 | # Confusion Matrix: 43 | from sklearn.metrics import confusion_matrix 44 | cm = confusion_matrix(y_test, y_pred) 45 | 46 | # Visulaization the training set results 47 | from matplotlib.colors import ListedColormap 48 | X_set, y_set = X_train , y_train 49 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 50 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 51 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 52 | alpha = 0.75 , cmap = ListedColormap(('red', 'green','blue'))) 53 | plt.xlim(x1.min(), x1.max()) 54 | plt.ylim(x2.min(), x2.max()) 55 | 56 | for i,j in enumerate(np.unique(y_set)): 57 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 58 | c = ListedColormap(('red','green','blue')) (i), label = j) 59 | plt.title('Classifier (Training set)') 60 | plt.xlabel('LDA 1') 61 | plt.ylabel('LDA 2') 62 | plt.legend() 63 | plt.show() 64 | 65 | 66 | # Visulaization the training set results 67 | from matplotlib.colors import ListedColormap 68 | X_set, y_set = X_test , y_test 69 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 70 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 71 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 72 | alpha = 0.75 , cmap = ListedColormap(('red', 'green','blue'))) 73 | plt.xlim(x1.min(), x1.max()) 74 | plt.ylim(x2.min(), x2.max()) 75 | 76 | for i,j in enumerate(np.unique(y_set)): 77 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 78 | c = ListedColormap(('red','green','blue')) (i), label = j) 79 | plt.title('Classifier (Training set)') 80 | plt.xlabel('LDA 1') 81 | plt.ylabel('LDA 2') 82 | plt.legend() 83 | plt.show() 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /27- Kernel_PCA/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000.0,0 216 | 15622478,Male,47.0,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /27- Kernel_PCA/kernel_pca.py: -------------------------------------------------------------------------------- 1 | # Kernel PCA 2 | 3 | # Importing the libraries: 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | data = pd.read_csv('Social_Network_Ads.csv') 10 | X = data.iloc[:,2:4].values 11 | y = data.iloc[:,-1].values 12 | 13 | 14 | # Splitting the dataset into training set and test set : 15 | from sklearn.model_selection import train_test_split 16 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.25, random_state = 0) 17 | 18 | # Features Scaling 19 | from sklearn.preprocessing import StandardScaler 20 | sc_X = StandardScaler() 21 | X_train = sc_X.fit_transform(X_train) 22 | X_test = sc_X.fit_transform(X_test) 23 | #sc_y = StandardScaler() 24 | #y_train = sc_y.fit_transform(y_train) 25 | 26 | # Applying KPCA 27 | from sklearn.decomposition import KernelPCA 28 | kpca = KernelPCA(n_components = 2, kernel="rbf") 29 | X_train = kpca.fit_transform(X_train,y_train) 30 | x_test = kpca.transform (X_test) 31 | 32 | # Fitting the Logistic Regression model to training dataset: 33 | from sklearn.linear_model import LogisticRegression 34 | classifier = LogisticRegression(random_state = 0) 35 | classifier.fit(X_train, y_train) 36 | 37 | # Predection Process: 38 | y_pred = classifier.predict(X_test) 39 | 40 | # Confusion Matrix: 41 | from sklearn.metrics import confusion_matrix 42 | cm = confusion_matrix(y_test, y_pred) 43 | 44 | # Visulaization the training set results 45 | from matplotlib.colors import ListedColormap 46 | X_set, y_set = X_train , y_train 47 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 48 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 49 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 50 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 51 | plt.xlim(x1.min(), x1.max()) 52 | plt.ylim(x2.min(), x2.max()) 53 | 54 | for i,j in enumerate(np.unique(y_set)): 55 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 56 | c = ListedColormap(('blue','orange')) (i), label = j) 57 | plt.title('Classifier (Training set)') 58 | plt.xlabel('Age') 59 | plt.ylabel('Estimated Salary') 60 | plt.legend() 61 | plt.show() 62 | 63 | 64 | # Visulaization the training set results 65 | from matplotlib.colors import ListedColormap 66 | X_set, y_set = X_test , y_test 67 | x1, x2 = np.meshgrid(np.arange(start = X_set[:,0].min() - 1 , stop = X_set[:,0].max() + 1 , step = 0.01), 68 | np.arange(start = X_set[:,1].min() - 1 , stop = X_set[:,1].max() + 1 , step = 0.01)) 69 | plt.contourf(x1, x2, classifier.predict(np.array([x1.ravel(),x2.ravel()]).T).reshape(x1.shape), 70 | alpha = 0.75 , cmap = ListedColormap(('red', 'green'))) 71 | plt.xlim(x1.min(), x1.max()) 72 | plt.ylim(x2.min(), x2.max()) 73 | 74 | for i,j in enumerate(np.unique(y_set)): 75 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j , 1], 76 | c = ListedColormap(('blue','orange')) (i), label = j) 77 | plt.title('Classifier (Training set)') 78 | plt.xlabel('Age') 79 | plt.ylabel('Estimated Salary') 80 | plt.legend() 81 | plt.show() 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /28- Model_Selection/Grid_search.py: -------------------------------------------------------------------------------- 1 | # Grid Search 2 | 3 | # Importing the libraries 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | dataset = pd.read_csv('Social_Network_Ads.csv') 10 | X = dataset.iloc[:, [2, 3]].values 11 | y = dataset.iloc[:, 4].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | from sklearn.model_selection import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0) 16 | 17 | # Feature Scaling 18 | from sklearn.preprocessing import StandardScaler 19 | sc = StandardScaler() 20 | X_train = sc.fit_transform(X_train) 21 | X_test = sc.transform(X_test) 22 | 23 | # Fitting Kernel SVM to the Training set 24 | from sklearn.svm import SVC 25 | classifier = SVC(kernel = 'rbf', random_state = 0) 26 | classifier.fit(X_train, y_train) 27 | 28 | # Predicting the Test set results 29 | y_pred = classifier.predict(X_test) 30 | 31 | # Making the Confusion Matrix 32 | from sklearn.metrics import confusion_matrix 33 | cm = confusion_matrix(y_test, y_pred) 34 | 35 | # Applying k-Fold Cross Validation 36 | from sklearn.model_selection import cross_val_score 37 | accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10) 38 | accuracies.mean() 39 | accuracies.std() 40 | 41 | # Applying Grid Search to find the best model and the best parameters 42 | from sklearn.model_selection import GridSearchCV 43 | parameters = [{'C': [1, 10, 100, 1000], 'kernel': ['linear']}, 44 | {'C': [1, 10, 100, 1000], 'kernel': ['rbf'], 'gamma': [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]}] 45 | grid_search = GridSearchCV(estimator = classifier, 46 | param_grid = parameters, 47 | scoring = 'accuracy', 48 | cv = 10, 49 | n_jobs = -1) 50 | grid_search = grid_search.fit(X_train, y_train) 51 | best_accuracy = grid_search.best_score_ 52 | best_parameters = grid_search.best_params_ 53 | 54 | # Visualising the Training set results 55 | from matplotlib.colors import ListedColormap 56 | X_set, y_set = X_train, y_train 57 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 58 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 59 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 60 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 61 | plt.xlim(X1.min(), X1.max()) 62 | plt.ylim(X2.min(), X2.max()) 63 | for i, j in enumerate(np.unique(y_set)): 64 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 65 | c = ListedColormap(('red', 'green'))(i), label = j) 66 | plt.title('Kernel SVM (Training set)') 67 | plt.xlabel('Age') 68 | plt.ylabel('Estimated Salary') 69 | plt.legend() 70 | plt.show() 71 | 72 | # Visualising the Test set results 73 | from matplotlib.colors import ListedColormap 74 | X_set, y_set = X_test, y_test 75 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 76 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 77 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 78 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 79 | plt.xlim(X1.min(), X1.max()) 80 | plt.ylim(X2.min(), X2.max()) 81 | for i, j in enumerate(np.unique(y_set)): 82 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 83 | c = ListedColormap(('red', 'green'))(i), label = j) 84 | plt.title('Kernel SVM (Test set)') 85 | plt.xlabel('Age') 86 | plt.ylabel('Estimated Salary') 87 | plt.legend() 88 | plt.show() -------------------------------------------------------------------------------- /28- Model_Selection/K_fold_cross.py: -------------------------------------------------------------------------------- 1 | # k-Fold Cross Validation 2 | 3 | # Importing the libraries 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Importing the dataset 9 | dataset = pd.read_csv('Social_Network_Ads.csv') 10 | X = dataset.iloc[:, [2, 3]].values 11 | y = dataset.iloc[:, 4].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | from sklearn.model_selection import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0) 16 | 17 | # Feature Scaling 18 | from sklearn.preprocessing import StandardScaler 19 | sc = StandardScaler() 20 | X_train = sc.fit_transform(X_train) 21 | X_test = sc.transform(X_test) 22 | 23 | # Fitting Kernel SVM to the Training set 24 | from sklearn.svm import SVC 25 | classifier = SVC(kernel = 'rbf', random_state = 0) 26 | classifier.fit(X_train, y_train) 27 | 28 | # Predicting the Test set results 29 | y_pred = classifier.predict(X_test) 30 | 31 | # Making the Confusion Matrix 32 | from sklearn.metrics import confusion_matrix 33 | cm = confusion_matrix(y_test, y_pred) 34 | 35 | # Applying k-Fold Cross Validation 36 | from sklearn.model_selection import cross_val_score 37 | accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10) 38 | accuracies.mean() 39 | accuracies.std() 40 | 41 | # Visualising the Training set results 42 | from matplotlib.colors import ListedColormap 43 | X_set, y_set = X_train, y_train 44 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 45 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 46 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 47 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 48 | plt.xlim(X1.min(), X1.max()) 49 | plt.ylim(X2.min(), X2.max()) 50 | for i, j in enumerate(np.unique(y_set)): 51 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 52 | c = ListedColormap(('red', 'green'))(i), label = j) 53 | plt.title('Kernel SVM (Training set)') 54 | plt.xlabel('Age') 55 | plt.ylabel('Estimated Salary') 56 | plt.legend() 57 | plt.show() 58 | 59 | # Visualising the Test set results 60 | from matplotlib.colors import ListedColormap 61 | X_set, y_set = X_test, y_test 62 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 63 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 64 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 65 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 66 | plt.xlim(X1.min(), X1.max()) 67 | plt.ylim(X2.min(), X2.max()) 68 | for i, j in enumerate(np.unique(y_set)): 69 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 70 | c = ListedColormap(('red', 'green'))(i), label = j) 71 | plt.title('Kernel SVM (Test set)') 72 | plt.xlabel('Age') 73 | plt.ylabel('Estimated Salary') 74 | plt.legend() 75 | plt.show() -------------------------------------------------------------------------------- /29- Kernel_SVM/Social_Network_Ads.csv: -------------------------------------------------------------------------------- 1 | User ID,Gender,Age,EstimatedSalary,Purchased 2 | 15624510,Male,19,19000,0 3 | 15810944,Male,35,20000,0 4 | 15668575,Female,26,43000,0 5 | 15603246,Female,27,57000,0 6 | 15804002,Male,19,76000,0 7 | 15728773,Male,27,58000,0 8 | 15598044,Female,27,84000,0 9 | 15694829,Female,32,150000,1 10 | 15600575,Male,25,33000,0 11 | 15727311,Female,35,65000,0 12 | 15570769,Female,26,80000,0 13 | 15606274,Female,26,52000,0 14 | 15746139,Male,20,86000,0 15 | 15704987,Male,32,18000,0 16 | 15628972,Male,18,82000,0 17 | 15697686,Male,29,80000,0 18 | 15733883,Male,47,25000,1 19 | 15617482,Male,45,26000,1 20 | 15704583,Male,46,28000,1 21 | 15621083,Female,48,29000,1 22 | 15649487,Male,45,22000,1 23 | 15736760,Female,47,49000,1 24 | 15714658,Male,48,41000,1 25 | 15599081,Female,45,22000,1 26 | 15705113,Male,46,23000,1 27 | 15631159,Male,47,20000,1 28 | 15792818,Male,49,28000,1 29 | 15633531,Female,47,30000,1 30 | 15744529,Male,29,43000,0 31 | 15669656,Male,31,18000,0 32 | 15581198,Male,31,74000,0 33 | 15729054,Female,27,137000,1 34 | 15573452,Female,21,16000,0 35 | 15776733,Female,28,44000,0 36 | 15724858,Male,27,90000,0 37 | 15713144,Male,35,27000,0 38 | 15690188,Female,33,28000,0 39 | 15689425,Male,30,49000,0 40 | 15671766,Female,26,72000,0 41 | 15782806,Female,27,31000,0 42 | 15764419,Female,27,17000,0 43 | 15591915,Female,33,51000,0 44 | 15772798,Male,35,108000,0 45 | 15792008,Male,30,15000,0 46 | 15715541,Female,28,84000,0 47 | 15639277,Male,23,20000,0 48 | 15798850,Male,25,79000,0 49 | 15776348,Female,27,54000,0 50 | 15727696,Male,30,135000,1 51 | 15793813,Female,31,89000,0 52 | 15694395,Female,24,32000,0 53 | 15764195,Female,18,44000,0 54 | 15744919,Female,29,83000,0 55 | 15671655,Female,35,23000,0 56 | 15654901,Female,27,58000,0 57 | 15649136,Female,24,55000,0 58 | 15775562,Female,23,48000,0 59 | 15807481,Male,28,79000,0 60 | 15642885,Male,22,18000,0 61 | 15789109,Female,32,117000,0 62 | 15814004,Male,27,20000,0 63 | 15673619,Male,25,87000,0 64 | 15595135,Female,23,66000,0 65 | 15583681,Male,32,120000,1 66 | 15605000,Female,59,83000,0 67 | 15718071,Male,24,58000,0 68 | 15679760,Male,24,19000,0 69 | 15654574,Female,23,82000,0 70 | 15577178,Female,22,63000,0 71 | 15595324,Female,31,68000,0 72 | 15756932,Male,25,80000,0 73 | 15726358,Female,24,27000,0 74 | 15595228,Female,20,23000,0 75 | 15782530,Female,33,113000,0 76 | 15592877,Male,32,18000,0 77 | 15651983,Male,34,112000,1 78 | 15746737,Male,18,52000,0 79 | 15774179,Female,22,27000,0 80 | 15667265,Female,28,87000,0 81 | 15655123,Female,26,17000,0 82 | 15595917,Male,30,80000,0 83 | 15668385,Male,39,42000,0 84 | 15709476,Male,20,49000,0 85 | 15711218,Male,35,88000,0 86 | 15798659,Female,30,62000,0 87 | 15663939,Female,31,118000,1 88 | 15694946,Male,24,55000,0 89 | 15631912,Female,28,85000,0 90 | 15768816,Male,26,81000,0 91 | 15682268,Male,35,50000,0 92 | 15684801,Male,22,81000,0 93 | 15636428,Female,30,116000,0 94 | 15809823,Male,26,15000,0 95 | 15699284,Female,29,28000,0 96 | 15786993,Female,29,83000,0 97 | 15709441,Female,35,44000,0 98 | 15710257,Female,35,25000,0 99 | 15582492,Male,28,123000,1 100 | 15575694,Male,35,73000,0 101 | 15756820,Female,28,37000,0 102 | 15766289,Male,27,88000,0 103 | 15593014,Male,28,59000,0 104 | 15584545,Female,32,86000,0 105 | 15675949,Female,33,149000,1 106 | 15672091,Female,19,21000,0 107 | 15801658,Male,21,72000,0 108 | 15706185,Female,26,35000,0 109 | 15789863,Male,27,89000,0 110 | 15720943,Male,26,86000,0 111 | 15697997,Female,38,80000,0 112 | 15665416,Female,39,71000,0 113 | 15660200,Female,37,71000,0 114 | 15619653,Male,38,61000,0 115 | 15773447,Male,37,55000,0 116 | 15739160,Male,42,80000,0 117 | 15689237,Male,40,57000,0 118 | 15679297,Male,35,75000,0 119 | 15591433,Male,36,52000,0 120 | 15642725,Male,40,59000,0 121 | 15701962,Male,41,59000,0 122 | 15811613,Female,36,75000,0 123 | 15741049,Male,37,72000,0 124 | 15724423,Female,40,75000,0 125 | 15574305,Male,35,53000,0 126 | 15678168,Female,41,51000,0 127 | 15697020,Female,39,61000,0 128 | 15610801,Male,42,65000,0 129 | 15745232,Male,26,32000,0 130 | 15722758,Male,30,17000,0 131 | 15792102,Female,26,84000,0 132 | 15675185,Male,31,58000,0 133 | 15801247,Male,33,31000,0 134 | 15725660,Male,30,87000,0 135 | 15638963,Female,21,68000,0 136 | 15800061,Female,28,55000,0 137 | 15578006,Male,23,63000,0 138 | 15668504,Female,20,82000,0 139 | 15687491,Male,30,107000,1 140 | 15610403,Female,28,59000,0 141 | 15741094,Male,19,25000,0 142 | 15807909,Male,19,85000,0 143 | 15666141,Female,18,68000,0 144 | 15617134,Male,35,59000,0 145 | 15783029,Male,30,89000,0 146 | 15622833,Female,34,25000,0 147 | 15746422,Female,24,89000,0 148 | 15750839,Female,27,96000,1 149 | 15749130,Female,41,30000,0 150 | 15779862,Male,29,61000,0 151 | 15767871,Male,20,74000,0 152 | 15679651,Female,26,15000,0 153 | 15576219,Male,41,45000,0 154 | 15699247,Male,31,76000,0 155 | 15619087,Female,36,50000,0 156 | 15605327,Male,40,47000,0 157 | 15610140,Female,31,15000,0 158 | 15791174,Male,46,59000,0 159 | 15602373,Male,29,75000,0 160 | 15762605,Male,26,30000,0 161 | 15598840,Female,32,135000,1 162 | 15744279,Male,32,100000,1 163 | 15670619,Male,25,90000,0 164 | 15599533,Female,37,33000,0 165 | 15757837,Male,35,38000,0 166 | 15697574,Female,33,69000,0 167 | 15578738,Female,18,86000,0 168 | 15762228,Female,22,55000,0 169 | 15614827,Female,35,71000,0 170 | 15789815,Male,29,148000,1 171 | 15579781,Female,29,47000,0 172 | 15587013,Male,21,88000,0 173 | 15570932,Male,34,115000,0 174 | 15794661,Female,26,118000,0 175 | 15581654,Female,34,43000,0 176 | 15644296,Female,34,72000,0 177 | 15614420,Female,23,28000,0 178 | 15609653,Female,35,47000,0 179 | 15594577,Male,25,22000,0 180 | 15584114,Male,24,23000,0 181 | 15673367,Female,31,34000,0 182 | 15685576,Male,26,16000,0 183 | 15774727,Female,31,71000,0 184 | 15694288,Female,32,117000,1 185 | 15603319,Male,33,43000,0 186 | 15759066,Female,33,60000,0 187 | 15814816,Male,31,66000,0 188 | 15724402,Female,20,82000,0 189 | 15571059,Female,33,41000,0 190 | 15674206,Male,35,72000,0 191 | 15715160,Male,28,32000,0 192 | 15730448,Male,24,84000,0 193 | 15662067,Female,19,26000,0 194 | 15779581,Male,29,43000,0 195 | 15662901,Male,19,70000,0 196 | 15689751,Male,28,89000,0 197 | 15667742,Male,34,43000,0 198 | 15738448,Female,30,79000,0 199 | 15680243,Female,20,36000,0 200 | 15745083,Male,26,80000,0 201 | 15708228,Male,35,22000,0 202 | 15628523,Male,35,39000,0 203 | 15708196,Male,49,74000,0 204 | 15735549,Female,39,134000,1 205 | 15809347,Female,41,71000,0 206 | 15660866,Female,58,101000,1 207 | 15766609,Female,47,47000,0 208 | 15654230,Female,55,130000,1 209 | 15794566,Female,52,114000,0 210 | 15800890,Female,40,142000,1 211 | 15697424,Female,46,22000,0 212 | 15724536,Female,48,96000,1 213 | 15735878,Male,52,150000,1 214 | 15707596,Female,59,42000,0 215 | 15657163,Male,35,58000,0 216 | 15622478,Male,47,43000,0 217 | 15779529,Female,60,108000,1 218 | 15636023,Male,49,65000,0 219 | 15582066,Male,40,78000,0 220 | 15666675,Female,46,96000,0 221 | 15732987,Male,59,143000,1 222 | 15789432,Female,41,80000,0 223 | 15663161,Male,35,91000,1 224 | 15694879,Male,37,144000,1 225 | 15593715,Male,60,102000,1 226 | 15575002,Female,35,60000,0 227 | 15622171,Male,37,53000,0 228 | 15795224,Female,36,126000,1 229 | 15685346,Male,56,133000,1 230 | 15691808,Female,40,72000,0 231 | 15721007,Female,42,80000,1 232 | 15794253,Female,35,147000,1 233 | 15694453,Male,39,42000,0 234 | 15813113,Male,40,107000,1 235 | 15614187,Male,49,86000,1 236 | 15619407,Female,38,112000,0 237 | 15646227,Male,46,79000,1 238 | 15660541,Male,40,57000,0 239 | 15753874,Female,37,80000,0 240 | 15617877,Female,46,82000,0 241 | 15772073,Female,53,143000,1 242 | 15701537,Male,42,149000,1 243 | 15736228,Male,38,59000,0 244 | 15780572,Female,50,88000,1 245 | 15769596,Female,56,104000,1 246 | 15586996,Female,41,72000,0 247 | 15722061,Female,51,146000,1 248 | 15638003,Female,35,50000,0 249 | 15775590,Female,57,122000,1 250 | 15730688,Male,41,52000,0 251 | 15753102,Female,35,97000,1 252 | 15810075,Female,44,39000,0 253 | 15723373,Male,37,52000,0 254 | 15795298,Female,48,134000,1 255 | 15584320,Female,37,146000,1 256 | 15724161,Female,50,44000,0 257 | 15750056,Female,52,90000,1 258 | 15609637,Female,41,72000,0 259 | 15794493,Male,40,57000,0 260 | 15569641,Female,58,95000,1 261 | 15815236,Female,45,131000,1 262 | 15811177,Female,35,77000,0 263 | 15680587,Male,36,144000,1 264 | 15672821,Female,55,125000,1 265 | 15767681,Female,35,72000,0 266 | 15600379,Male,48,90000,1 267 | 15801336,Female,42,108000,1 268 | 15721592,Male,40,75000,0 269 | 15581282,Male,37,74000,0 270 | 15746203,Female,47,144000,1 271 | 15583137,Male,40,61000,0 272 | 15680752,Female,43,133000,0 273 | 15688172,Female,59,76000,1 274 | 15791373,Male,60,42000,1 275 | 15589449,Male,39,106000,1 276 | 15692819,Female,57,26000,1 277 | 15727467,Male,57,74000,1 278 | 15734312,Male,38,71000,0 279 | 15764604,Male,49,88000,1 280 | 15613014,Female,52,38000,1 281 | 15759684,Female,50,36000,1 282 | 15609669,Female,59,88000,1 283 | 15685536,Male,35,61000,0 284 | 15750447,Male,37,70000,1 285 | 15663249,Female,52,21000,1 286 | 15638646,Male,48,141000,0 287 | 15734161,Female,37,93000,1 288 | 15631070,Female,37,62000,0 289 | 15761950,Female,48,138000,1 290 | 15649668,Male,41,79000,0 291 | 15713912,Female,37,78000,1 292 | 15586757,Male,39,134000,1 293 | 15596522,Male,49,89000,1 294 | 15625395,Male,55,39000,1 295 | 15760570,Male,37,77000,0 296 | 15566689,Female,35,57000,0 297 | 15725794,Female,36,63000,0 298 | 15673539,Male,42,73000,1 299 | 15705298,Female,43,112000,1 300 | 15675791,Male,45,79000,0 301 | 15747043,Male,46,117000,1 302 | 15736397,Female,58,38000,1 303 | 15678201,Male,48,74000,1 304 | 15720745,Female,37,137000,1 305 | 15637593,Male,37,79000,1 306 | 15598070,Female,40,60000,0 307 | 15787550,Male,42,54000,0 308 | 15603942,Female,51,134000,0 309 | 15733973,Female,47,113000,1 310 | 15596761,Male,36,125000,1 311 | 15652400,Female,38,50000,0 312 | 15717893,Female,42,70000,0 313 | 15622585,Male,39,96000,1 314 | 15733964,Female,38,50000,0 315 | 15753861,Female,49,141000,1 316 | 15747097,Female,39,79000,0 317 | 15594762,Female,39,75000,1 318 | 15667417,Female,54,104000,1 319 | 15684861,Male,35,55000,0 320 | 15742204,Male,45,32000,1 321 | 15623502,Male,36,60000,0 322 | 15774872,Female,52,138000,1 323 | 15611191,Female,53,82000,1 324 | 15674331,Male,41,52000,0 325 | 15619465,Female,48,30000,1 326 | 15575247,Female,48,131000,1 327 | 15695679,Female,41,60000,0 328 | 15713463,Male,41,72000,0 329 | 15785170,Female,42,75000,0 330 | 15796351,Male,36,118000,1 331 | 15639576,Female,47,107000,1 332 | 15693264,Male,38,51000,0 333 | 15589715,Female,48,119000,1 334 | 15769902,Male,42,65000,0 335 | 15587177,Male,40,65000,0 336 | 15814553,Male,57,60000,1 337 | 15601550,Female,36,54000,0 338 | 15664907,Male,58,144000,1 339 | 15612465,Male,35,79000,0 340 | 15810800,Female,38,55000,0 341 | 15665760,Male,39,122000,1 342 | 15588080,Female,53,104000,1 343 | 15776844,Male,35,75000,0 344 | 15717560,Female,38,65000,0 345 | 15629739,Female,47,51000,1 346 | 15729908,Male,47,105000,1 347 | 15716781,Female,41,63000,0 348 | 15646936,Male,53,72000,1 349 | 15768151,Female,54,108000,1 350 | 15579212,Male,39,77000,0 351 | 15721835,Male,38,61000,0 352 | 15800515,Female,38,113000,1 353 | 15591279,Male,37,75000,0 354 | 15587419,Female,42,90000,1 355 | 15750335,Female,37,57000,0 356 | 15699619,Male,36,99000,1 357 | 15606472,Male,60,34000,1 358 | 15778368,Male,54,70000,1 359 | 15671387,Female,41,72000,0 360 | 15573926,Male,40,71000,1 361 | 15709183,Male,42,54000,0 362 | 15577514,Male,43,129000,1 363 | 15778830,Female,53,34000,1 364 | 15768072,Female,47,50000,1 365 | 15768293,Female,42,79000,0 366 | 15654456,Male,42,104000,1 367 | 15807525,Female,59,29000,1 368 | 15574372,Female,58,47000,1 369 | 15671249,Male,46,88000,1 370 | 15779744,Male,38,71000,0 371 | 15624755,Female,54,26000,1 372 | 15611430,Female,60,46000,1 373 | 15774744,Male,60,83000,1 374 | 15629885,Female,39,73000,0 375 | 15708791,Male,59,130000,1 376 | 15793890,Female,37,80000,0 377 | 15646091,Female,46,32000,1 378 | 15596984,Female,46,74000,0 379 | 15800215,Female,42,53000,0 380 | 15577806,Male,41,87000,1 381 | 15749381,Female,58,23000,1 382 | 15683758,Male,42,64000,0 383 | 15670615,Male,48,33000,1 384 | 15715622,Female,44,139000,1 385 | 15707634,Male,49,28000,1 386 | 15806901,Female,57,33000,1 387 | 15775335,Male,56,60000,1 388 | 15724150,Female,49,39000,1 389 | 15627220,Male,39,71000,0 390 | 15672330,Male,47,34000,1 391 | 15668521,Female,48,35000,1 392 | 15807837,Male,48,33000,1 393 | 15592570,Male,47,23000,1 394 | 15748589,Female,45,45000,1 395 | 15635893,Male,60,42000,1 396 | 15757632,Female,39,59000,0 397 | 15691863,Female,46,41000,1 398 | 15706071,Male,51,23000,1 399 | 15654296,Female,50,20000,1 400 | 15755018,Male,36,33000,0 401 | 15594041,Female,49,36000,1 -------------------------------------------------------------------------------- /30- XGBoost/XGBoost.py: -------------------------------------------------------------------------------- 1 | # Importing the libraries 2 | import numpy as np 3 | import matplotlib.pyplot as plt 4 | import pandas as pd 5 | 6 | # Importing the dataset 7 | dataset = pd.read_csv('Churn_Modelling.csv') 8 | X = dataset.iloc[:, 3:13].values 9 | y = dataset.iloc[:, 13].values 10 | 11 | # Encoding categorical data from Labels into continious 0 1: 12 | from sklearn.preprocessing import LabelEncoder , OneHotEncoder 13 | from sklearn.compose import ColumnTransformer 14 | 15 | 16 | # Encoding categorical data in 'Country' Column to continious 0 1: 17 | # The new method doesn't require to use LabelEncoder and you can make it by two lines 18 | ct_X = ColumnTransformer([('0', OneHotEncoder(), [1])], remainder = 'passthrough') 19 | X = ct_X.fit_transform(X) 20 | 21 | # Encoding categorical data in 'Gender' Column to continious 0 1: 22 | LabelEncoder_X = LabelEncoder() 23 | X [:,4] = LabelEncoder_X.fit_transform(X[:,4]) 24 | 25 | # Remove one of 3 dummy variables for the country 26 | X = np.array(transform.fit_transform(X), dtype = np.float64) 27 | X = X[:,1:] 28 | 29 | # Splitting the dataset into training set and test set : 30 | from sklearn.model_selection import train_test_split 31 | X_train, X_test, y_train, y_test = train_test_split(X,y , test_size = 0.2, random_state = 0) 32 | 33 | 34 | 35 | # Fitting XGBoost version 0.90 to the Training set 36 | from xgboost import XGBClassifier 37 | classifier = XGBClassifier() 38 | classifier.fit(X_train, y_train) 39 | 40 | # Predicting the Test set results 41 | y_pred = classifier.predict(X_test) 42 | 43 | # Making the Confusion Matrix 44 | 45 | from sklearn.metrics import confusion_matrix 46 | cm = confusion_matrix(y_test, y_pred) 47 | 48 | # Applying k-Fold Cross Validation 49 | from sklearn.model_selection import cross_val_score 50 | accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10) 51 | accuracies_mean = accuracies.mean() 52 | accuracies_std = accuracies.std() 53 | -------------------------------------------------------------------------------- /30- XGBoost/XGBoost_Colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "XGBoost_Colab.ipynb", 7 | "provenance": [], 8 | "collapsed_sections": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "cell_type": "code", 18 | "metadata": { 19 | "id": "AZ2WadBmnm5H", 20 | "colab_type": "code", 21 | "colab": {} 22 | }, 23 | "source": [ 24 | "#import data (test CSV)\n", 25 | "from google.colab import drive\n", 26 | "drive.mount('/content/drive')" 27 | ], 28 | "execution_count": 0, 29 | "outputs": [] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "metadata": { 34 | "id": "a_dVGD5sn2k2", 35 | "colab_type": "code", 36 | "colab": {} 37 | }, 38 | "source": [ 39 | " #cd (change directory) to the file/folder location" 40 | ], 41 | "execution_count": 0, 42 | "outputs": [] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "metadata": { 47 | "id": "4LskbY47sPeX", 48 | "colab_type": "code", 49 | "colab": { 50 | "base_uri": "https://localhost:8080/", 51 | "height": 34 52 | }, 53 | "outputId": "e266dff3-5326-4a19-baac-0b8f99c5319f" 54 | }, 55 | "source": [ 56 | "# Importing the libraries\n", 57 | "import numpy as np\n", 58 | "import matplotlib.pyplot as plt\n", 59 | "import pandas as pd\n", 60 | "\n", 61 | "# Importing the dataset\n", 62 | "dataset = pd.read_csv('Churn_Modelling.csv')\n", 63 | "X = dataset.iloc[:, 3:13].values\n", 64 | "y = dataset.iloc[:, 13].values\n", 65 | "\n", 66 | "# Encoding categorical data\n", 67 | "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n", 68 | "from sklearn.compose import ColumnTransformer\n", 69 | "labelencoder_X_1 = LabelEncoder()\n", 70 | "X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])\n", 71 | "labelencoder_X_2 = LabelEncoder()\n", 72 | "X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])\n", 73 | "transform = ColumnTransformer([('Geography', OneHotEncoder(categories = 'auto'), [1]), \n", 74 | " ('Gender', OneHotEncoder(categories = 'auto', drop = 'first'), [2])], \n", 75 | " remainder= 'passthrough') \n", 76 | "X = np.array(transform.fit_transform(X), dtype = np.float64)\n", 77 | "X = X[:, 1:]\n", 78 | "\n", 79 | "# Splitting the dataset into the Training set and Test set\n", 80 | "from sklearn.model_selection import train_test_split\n", 81 | "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)\n", 82 | "\n", 83 | "# Fitting XGBoost to the Training set\n", 84 | "from xgboost import XGBClassifier\n", 85 | "classifier = XGBClassifier()\n", 86 | "classifier.fit(X_train, y_train)\n", 87 | "\n", 88 | "# Predicting the Test set results\n", 89 | "y_pred = classifier.predict(X_test)\n", 90 | "\n", 91 | "# Making the Confusion Matrix\n", 92 | "\n", 93 | "from sklearn.metrics import confusion_matrix\n", 94 | "cm = confusion_matrix(y_test, y_pred)\n", 95 | "\n", 96 | "# Applying k-Fold Cross Validation\n", 97 | "\n", 98 | "from sklearn.model_selection import cross_val_score\n", 99 | "accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10)\n", 100 | "accuracies.mean()\n", 101 | "accuracies.std()" 102 | ], 103 | "execution_count": 21, 104 | "outputs": [ 105 | { 106 | "output_type": "execute_result", 107 | "data": { 108 | "text/plain": [ 109 | "0.01017042280340401" 110 | ] 111 | }, 112 | "metadata": { 113 | "tags": [] 114 | }, 115 | "execution_count": 21 116 | } 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "metadata": { 122 | "id": "Ae2iFe3Rn2iO", 123 | "colab_type": "code", 124 | "colab": {} 125 | }, 126 | "source": [ 127 | "" 128 | ], 129 | "execution_count": 0, 130 | "outputs": [] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "metadata": { 135 | "id": "tPXrnm0Dn2ek", 136 | "colab_type": "code", 137 | "colab": {} 138 | }, 139 | "source": [ 140 | "" 141 | ], 142 | "execution_count": 0, 143 | "outputs": [] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "metadata": { 148 | "id": "W6My8YVOpFYl", 149 | "colab_type": "code", 150 | "colab": {} 151 | }, 152 | "source": [ 153 | "" 154 | ], 155 | "execution_count": 0, 156 | "outputs": [] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "metadata": { 161 | "id": "J6epjyw1pFgc", 162 | "colab_type": "code", 163 | "colab": {} 164 | }, 165 | "source": [ 166 | "" 167 | ], 168 | "execution_count": 0, 169 | "outputs": [] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "metadata": { 174 | "id": "spYXA5FApFpd", 175 | "colab_type": "code", 176 | "colab": {} 177 | }, 178 | "source": [ 179 | "" 180 | ], 181 | "execution_count": 0, 182 | "outputs": [] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "metadata": { 187 | "id": "0guxKKH0pFnv", 188 | "colab_type": "code", 189 | "colab": {} 190 | }, 191 | "source": [ 192 | "" 193 | ], 194 | "execution_count": 0, 195 | "outputs": [] 196 | } 197 | ] 198 | } -------------------------------------------------------------------------------- /30- XGBoost/XGBoost_installation_Test.py: -------------------------------------------------------------------------------- 1 | import os 2 | mingw_path = 'C:\\Program Files\\mingw-w64\\x86_64-5.3.0-posix-seh-rt_v4-rev0\\mingw64\\bin' 3 | 4 | os.environ['PATH'] = mingw_path + ';' + os.environ['PATH'] 5 | 6 | import xgboost as gab -------------------------------------------------------------------------------- /30- XGBoost/xgboost+installation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/30- XGBoost/xgboost+installation.pdf -------------------------------------------------------------------------------- /Machine-Learning-A-Z-Q-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AI-MOO/MachineLearningNanodegree/f43b3b0d33a05c10dec19c6cc2bbcd8f81f6bb12/Machine-Learning-A-Z-Q-A.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Nanodegree 32 Hours 2 | Machine Learning Nanodegree Course by Dr.Tamer Eid on Udemy 3 | 4 | 5 | Machine Learning Nanodegree Course Link 6 | 7 | ![uipath](https://user-images.githubusercontent.com/67054356/115958188-0a402300-a50f-11eb-908d-11a840f3515d.jpg) 8 | --------------------------------------------------------------------------------