├── .gitattributes ├── .gitignore ├── LICENSE ├── Machine Learning A-Z-hands-on Python & R in data Science.pdf ├── Machine Learning A-Z ├── .DS_Store ├── Part 0 - Welcome to Machine Learning A-Z │ ├── .DS_Store │ └── temp.py ├── Part 1 - Data Preprocessing │ ├── .DS_Store │ ├── Data.csv │ ├── NOtes.txt │ ├── categorical_data.R │ ├── categorical_data.py │ ├── data_preprocessing_template.R │ ├── data_preprocessing_template.py │ ├── missing_data.R │ └── missing_data.py ├── Part 10 - Model Selection & Boosting │ ├── Section 48 - Model Selection │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── grid_search.R │ │ ├── grid_search.py │ │ ├── k_fold_cross_validation.R │ │ └── k_fold_cross_validation.py │ └── Section 49 - XGBoost │ │ ├── .DS_Store │ │ ├── .RData │ │ ├── .Rhistory │ │ ├── Churn_Modelling.csv │ │ ├── xg_boost.R │ │ └── xg_boost.py ├── Part 2 - Regression │ ├── Regression-Pros-Cons.pdf │ ├── Regularization.pdf │ ├── Section 4 - Simple Linear Regression │ │ └── Simple_Linear_Regression │ │ │ ├── Salary_Data.csv │ │ │ ├── data_preprocessing_template.R │ │ │ ├── data_preprocessing_template.py │ │ │ ├── simple_linear_regression.R │ │ │ └── simple_linear_regression.py │ ├── Section 5 - Multiple Linear Regression │ │ ├── .DS_Store │ │ ├── 50_Startups.csv │ │ ├── BACKWARD SELECTION.txt │ │ ├── Homework_Solutions │ │ │ ├── 50_Startups.csv │ │ │ ├── data_preprocessing_template.R │ │ │ ├── data_preprocessing_template.py │ │ │ ├── multiple_linear_regression.R │ │ │ └── multiple_linear_regression.py │ │ ├── Step-by-step-Blueprints-For-Building-Models.pdf │ │ ├── data_preprocessing_template.R │ │ ├── data_preprocessing_template.py │ │ ├── multiple_linear_regression.R │ │ └── multiple_linear_regression.py │ ├── Section 6 - Polynomial Regression │ │ ├── Polynomial_Regression │ │ │ ├── .DS_Store │ │ │ ├── Position_Salaries.csv │ │ │ ├── data_preprocessing_template.R │ │ │ ├── data_preprocessing_template.py │ │ │ ├── polynomial_regression.R │ │ │ └── polynomial_regression.py │ │ └── Regression_Template │ │ │ ├── .DS_Store │ │ │ ├── regression_template.R │ │ │ └── regression_template.py │ ├── Section 7 - Support Vector Regression (SVR) │ │ ├── .RData │ │ ├── .Rhistory │ │ ├── Position_Salaries.csv │ │ ├── regression_template.R │ │ ├── regression_template.py │ │ ├── svr.R │ │ └── svr.py │ ├── Section 8 - Decision Tree Regression │ │ ├── .DS_Store │ │ ├── Position_Salaries.csv │ │ ├── decision_tree_regression.R │ │ ├── decision_tree_regression.py │ │ ├── regression_template.R │ │ └── regression_template.py │ ├── Section 9 - Random Forest Regression │ │ ├── .DS_Store │ │ ├── Position_Salaries.csv │ │ ├── random_forest_regression.R │ │ ├── random_forest_regression.py │ │ ├── regression_template.R │ │ └── regression_template.py │ ├── notes-2.txt │ └── notes.txt ├── Part 3 - Classification │ ├── Section 14 - Logistic Regression │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── logistic_regression.R │ │ └── logistic_regression.py │ ├── Section 15 - K-Nearest Neighbors (K-NN) │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── classification_template.R │ │ ├── classification_template.py │ │ ├── knn.R │ │ └── knn.py │ ├── Section 16 - Support Vector Machine (SVM) │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── classification_template.R │ │ ├── classification_template.py │ │ ├── svm.R │ │ └── svm.py │ ├── Section 17 - Kernel SVM │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── classification_template.R │ │ ├── classification_template.py │ │ ├── kernel_svm.R │ │ └── kernel_svm.py │ ├── Section 18 - Naive Bayes │ │ ├── .DS_Store │ │ ├── Rplot.pdf │ │ ├── Rplot02.pdf │ │ ├── Social_Network_Ads.csv │ │ ├── classification_template.R │ │ ├── classification_template.py │ │ ├── naive_bayes.R │ │ └── naive_bayes.py │ ├── Section 19 - Decision Tree Classification │ │ ├── .DS_Store │ │ ├── PastHires.csv │ │ ├── Social_Network_Ads.csv │ │ ├── classification_template.R │ │ ├── classification_template.py │ │ ├── decision_tree_classification-2.py │ │ ├── decision_tree_classification.R │ │ ├── decision_tree_classification.py │ │ └── traing result.png │ ├── Section 20 - Random Forest Classification │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── classification_template.R │ │ ├── classification_template.py │ │ ├── random_forest_classification.R │ │ └── random_forest_classification.py │ ├── notes-1.txt │ └── notes-2.txt ├── Part 4 - Clustering │ ├── Clustering-Pros-Cons.pdf │ ├── Section 24 - K-Means Clustering │ │ ├── .DS_Store │ │ ├── Mall_Customers.csv │ │ ├── data_preprocessing_template.R │ │ ├── data_preprocessing_template.py │ │ ├── kmeans.R │ │ └── kmeans.py │ ├── Section 25 - Hierarchical Clustering │ │ ├── .DS_Store │ │ ├── Mall_Customers.csv │ │ ├── data_preprocessing_template.R │ │ ├── data_preprocessing_template.py │ │ ├── hc.R │ │ └── hc.py │ ├── notes-1.txt │ └── notes-2.txt ├── Part 5 - Association Rule Learning │ ├── Section 28 - Apriori │ │ ├── .DS_Store │ │ ├── Apriori_Python │ │ │ ├── .DS_Store │ │ │ ├── Market_Basket_Optimisation.csv │ │ │ ├── __pycache__ │ │ │ │ └── apyori.cpython-37.pyc │ │ │ ├── apriori.py │ │ │ └── apyori.py │ │ └── Apriori_R │ │ │ ├── .DS_Store │ │ │ ├── Market_Basket_Optimisation.csv │ │ │ └── apriori.R │ └── Section 29 - Eclat │ │ ├── .DS_Store │ │ ├── Market_Basket_Optimisation.csv │ │ └── eclat.R ├── Part 6 - Reinforcement Learning │ ├── Q-learning │ │ └── q_learning.py │ ├── Section 32 - Upper Confidence Bound (UCB) │ │ ├── .DS_Store │ │ ├── Ads_CTR_Optimisation.csv │ │ ├── UCB_Algorithm_Slide.png │ │ ├── random_selection.R │ │ ├── random_selection.py │ │ ├── upper_confidence_bound.R │ │ └── upper_confidence_bound.py │ ├── Section 33 - Thompson Sampling │ │ ├── .DS_Store │ │ ├── Ads_CTR_Optimisation.csv │ │ ├── Thompson_Sampling_Slide.png │ │ ├── random_selection.R │ │ ├── random_selection.py │ │ ├── thompson_sampling.R │ │ └── thompson_sampling.py │ └── notes-1.txt ├── Part 7 - Natural Language Processing │ ├── Section 36 - Natural Language Processing │ │ ├── .DS_Store │ │ ├── Restaurant_Reviews.tsv │ │ ├── natural_language_processing.R │ │ ├── natural_language_processing.py │ │ ├── natural_language_processing_Decision_Tree.py │ │ ├── natural_language_processing_Max_entropy.py │ │ └── natural_language_processing_RANDOM_FOREST.py │ └── notes-1.txt ├── Part 8 - Deep Learning │ ├── A list of cost functions used in neural networks, alongside applications - Cross Validated.pdf │ ├── Section 39 - Artificial Neural Networks (ANN) │ │ ├── .DS_Store │ │ ├── Churn_Modelling.csv │ │ ├── Stochastic_Gradient_Descent.png │ │ ├── ann.R │ │ └── ann.py │ ├── Section 40 - Convolutional Neural Networks (CNN) │ │ ├── .DS_Store │ │ ├── .gitignore │ │ └── cnn.py │ ├── Section 41 - Recurrent Neural Network (RNN) │ │ └── keras_RNN.py │ ├── neural networks and deep learning.pdf │ └── notes-1.txt ├── Part 9 - Dimensionality Reduction │ ├── Section 43 - Principal Component Analysis (PCA) │ │ ├── .DS_Store │ │ ├── Wine.csv │ │ ├── pca.R │ │ └── pca.py │ ├── Section 44 - Linear Discriminant Analysis (LDA) │ │ ├── .DS_Store │ │ ├── Wine.csv │ │ ├── lda.R │ │ └── lda.py │ ├── Section 45 - Kernel PCA │ │ ├── .DS_Store │ │ ├── Social_Network_Ads.csv │ │ ├── kernel_pca.R │ │ └── kernel_pca.py │ └── notes-1.txt ├── Recommender System │ ├── .gitignore │ ├── item_based_collabrative_filtering.py │ └── similarmovies.py ├── Tensorflow │ ├── Keras.py │ ├── handwritting_recognition.py │ ├── house-votes-84.data.txt │ ├── house-votes-84.names.txt │ ├── keras_CNN.py │ ├── keras_RNN.py │ ├── predict_political_party.py │ └── simplest_code_TENSORFLOW.py └── keras-fire-detection │ ├── output │ ├── .DS_Store │ ├── examples │ │ ├── .DS_Store │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 16.png │ │ ├── 17.png │ │ ├── 18.png │ │ ├── 19.png │ │ ├── 2.png │ │ ├── 21.png │ │ ├── 22.png │ │ ├── 23.png │ │ ├── 24.png │ │ ├── 25.png │ │ ├── 26.png │ │ ├── 27.png │ │ ├── 28.png │ │ ├── 29.png │ │ ├── 3.png │ │ ├── 30.png │ │ ├── 31.png │ │ ├── 32.png │ │ ├── 33.png │ │ ├── 34.png │ │ ├── 35.png │ │ ├── 36.png │ │ ├── 37.png │ │ ├── 38.png │ │ ├── 4.png │ │ ├── 40.png │ │ ├── 41.png │ │ ├── 42.png │ │ ├── 43.png │ │ ├── 44.png │ │ ├── 45.png │ │ ├── 46.png │ │ ├── 47.png │ │ ├── 48.png │ │ ├── 49.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ ├── fire_detection.model │ │ ├── .gitignore │ │ └── saved_model.pb │ ├── lrfind_plot.png │ └── training_plot.png │ ├── predict_fire.py │ ├── prune.sh │ ├── pyimagesearch │ ├── .DS_Store │ ├── __init__.py │ ├── config.py │ ├── firedetectionnet.py │ └── learningratefinder.py │ └── train.py ├── Machine-Learning-A-Z-Q-A.pdf ├── README.md └── resource ├── 27129696_acc1.jpg ├── Certificate.PNG ├── Description.PNG ├── Udemy.PNG ├── kiril.jpg ├── martin.jpg └── ponteves.jpg /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ashlesh Khajbage 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Machine Learning A-Z-hands-on Python & R in data Science.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z-hands-on Python & R in data Science.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 0 - Welcome to Machine Learning A-Z/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 0 - Welcome to Machine Learning A-Z/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 0 - Welcome to Machine Learning A-Z/temp.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Spyder Editor 4 | 5 | This is a temporary script file. 6 | """ 7 | 8 | print("HEELO WORLD") -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 1 - Data Preprocessing/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/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 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/NOtes.txt: -------------------------------------------------------------------------------- 1 | A class is the model of something we want to build. For example, 2 | if we make a house construction plan that gathers the instructions 3 | on how to build a house, then this construction plan is the class. 4 | 5 | An object is an instance of the class. So if we take that same example 6 | of the house construction plan, then an object is simply a house. A house 7 | (the object) that was built by following the instructions of the construction 8 | plan (the class). 9 | And therefore there can be many objects of the same class, because we can 10 | build many houses from the construction plan. 11 | 12 | A method is a tool we can use on the object to complete a specific action. 13 | So in this same example, a tool can be to open the main door of the house if 14 | a guest is coming. A method can also be seen as a function that is applied onto 15 | the object, takes some inputs (that were defined in the class) and returns some output. -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/categorical_data.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Taking care of missing data 7 | dataset$Age = ifelse(is.na(dataset$Age), 8 | ave(dataset$Age, FUN = function(x) mean(x, na.rm = TRUE)), 9 | dataset$Age) 10 | dataset$Salary = ifelse(is.na(dataset$Salary), 11 | ave(dataset$Salary, FUN = function(x) mean(x, na.rm = TRUE)), 12 | dataset$Salary) 13 | 14 | # Encoding categorical data 15 | dataset$Country = factor(dataset$Country, 16 | levels = c('France', 'Spain', 'Germany'), 17 | labels = c(1, 2, 3)) 18 | dataset$Purchased = factor(dataset$Purchased, 19 | levels = c('No', 'Yes'), 20 | labels = c(0, 1)) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/categorical_data.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing 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[:, 3].values 12 | 13 | # Taking care of missing data 14 | from sklearn.preprocessing import Imputer 15 | imputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0) 16 | imputer = imputer.fit(X[:, 1:3]) 17 | X[:, 1:3] = imputer.transform(X[:, 1:3]) 18 | 19 | # Encoding categorical data 20 | # Encoding the Independent Variable 21 | from sklearn.preprocessing import LabelEncoder, OneHotEncoder 22 | labelencoder_X = LabelEncoder() 23 | X[:, 0] = labelencoder_X.fit_transform(X[:, 0]) 24 | onehotencoder = OneHotEncoder(categorical_features = [0]) 25 | X = onehotencoder.fit_transform(X).toarray() 26 | # Encoding the Dependent Variable 27 | labelencoder_y = LabelEncoder() 28 | y = labelencoder_y.fit_transform(y) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | #dataset = dataset[,2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | #install.packages('caTools') 9 | library(caTools) 10 | set.seed(123) 11 | split = sample.split(dataset$Purchased, SplitRatio = 0.8) 12 | training_set = subset(dataset, split == TRUE) 13 | test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | #training_set[,2:3] = scale(training_set[,2:3]) 17 | #test_set[,2:3] = scale(test_set[,2:3]) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/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 #manage and select datasets 7 | 8 | # Importing the dataset 9 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values #matrix of feature : all line , all colums except last one 11 | y = dataset.iloc[:, 3].values #depenedetnt variable /output 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.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() # not required 23 | y_train = sc_y.fit_transform(y_train)""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/missing_data.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Taking care of missing data 7 | dataset$Age = ifelse(is.na(dataset$Age), 8 | ave(dataset$Age, FUN = function(x) mean(x, na.rm = TRUE)), 9 | dataset$Age) 10 | dataset$Salary = ifelse(is.na(dataset$Salary), 11 | ave(dataset$Salary, FUN = function(x) mean(x, na.rm = TRUE)), 12 | dataset$Salary) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 1 - Data Preprocessing/missing_data.py: -------------------------------------------------------------------------------- 1 | # Data Preprocessing 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[:, 3].values 12 | 13 | # Taking care of missing data 14 | from sklearn.preprocessing import Imputer 15 | imputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0) 16 | imputer = imputer.fit(X[:,1:3]) 17 | X[:, 1:3] = imputer.transform(X[:, 1:3]) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 48 - Model Selection/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 48 - Model Selection/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/.RData -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/xg_boost.R: -------------------------------------------------------------------------------- 1 | # XGBoost 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Churn_Modelling.csv') 5 | dataset = dataset[4:14] 6 | 7 | # Encoding the categorical variables as factors 8 | dataset$Geography = as.numeric(factor(dataset$Geography, 9 | levels = c('France', 'Spain', 'Germany'), 10 | labels = c(1, 2, 3))) 11 | dataset$Gender = as.numeric(factor(dataset$Gender, 12 | levels = c('Female', 'Male'), 13 | labels = c(1, 2))) 14 | 15 | # Splitting the dataset into the Training set and Test set 16 | # install.packages('caTools') 17 | library(caTools) 18 | set.seed(123) 19 | split = sample.split(dataset$Exited, SplitRatio = 0.8) 20 | training_set = subset(dataset, split == TRUE) 21 | test_set = subset(dataset, split == FALSE) 22 | 23 | # Fitting XGBoost to the Training set 24 | # install.packages('xgboost') 25 | library(xgboost) 26 | classifier = xgboost(data = as.matrix(training_set[-11]), label = training_set$Exited, nrounds = 10) 27 | 28 | # Predicting the Test set results 29 | y_pred = predict(classifier, newdata = as.matrix(test_set[-11])) 30 | y_pred = (y_pred >= 0.5) 31 | 32 | # Making the Confusion Matrix 33 | cm = table(test_set[, 11], y_pred) 34 | 35 | # Applying k-Fold Cross Validation 36 | # install.packages('caret') 37 | library(caret) 38 | folds = createFolds(training_set$Exited, k = 10) 39 | cv = lapply(folds, function(x) { 40 | training_fold = training_set[-x, ] 41 | test_fold = training_set[x, ] 42 | classifier = xgboost(data = as.matrix(training_fold[-11]), label = training_fold$Exited, nrounds = 10) 43 | y_pred = predict(classifier, newdata = as.matrix(test_fold[-11])) 44 | y_pred = (y_pred >= 0.5) 45 | cm = table(test_fold[, 11], y_pred) 46 | accuracy = (cm[1,1] + cm[2,2]) / (cm[1,1] + cm[2,2] + cm[1,2] + cm[2,1]) 47 | return(accuracy) 48 | }) 49 | accuracy = mean(as.numeric(cv)) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/xg_boost.py: -------------------------------------------------------------------------------- 1 | # XGBoost 2 | 3 | # Installing XGBoost 4 | # Enter the following command in a terminal (or anaconda prompt for Windows users): conda install -c conda-forge xgboost 5 | 6 | # Importing the libraries 7 | import numpy as np 8 | import matplotlib.pyplot as plt 9 | import pandas as pd 10 | 11 | # Importing the dataset 12 | dataset = pd.read_csv('Churn_Modelling.csv') 13 | X = dataset.iloc[:, 3:13].values 14 | y = dataset.iloc[:, 13].values 15 | 16 | # Encoding categorical data 17 | from sklearn.preprocessing import LabelEncoder, OneHotEncoder 18 | labelencoder_X_1 = LabelEncoder() 19 | X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) 20 | labelencoder_X_2 = LabelEncoder() 21 | X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2]) 22 | onehotencoder = OneHotEncoder(categorical_features = [1]) 23 | X = onehotencoder.fit_transform(X).toarray() 24 | X = X[:, 1:] 25 | 26 | # Splitting the dataset into the Training set and Test set 27 | from sklearn.model_selection import train_test_split 28 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 29 | 30 | # Fitting XGBoost to the Training set 31 | from xgboost import XGBClassifier 32 | classifier = XGBClassifier() 33 | classifier.fit(X_train, y_train) 34 | 35 | # Predicting the Test set results 36 | y_pred = classifier.predict(X_test) 37 | 38 | # Making the Confusion Matrix 39 | from sklearn.metrics import confusion_matrix 40 | cm = confusion_matrix(y_test, y_pred) 41 | 42 | # Applying k-Fold Cross Validation 43 | from sklearn.model_selection import cross_val_score 44 | accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10) 45 | accuracies.mean() 46 | accuracies.std() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Regression-Pros-Cons.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Regression-Pros-Cons.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Regularization.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Regularization.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/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 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/Simple_Linear_Regression/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/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 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 3].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/Simple_Linear_Regression/simple_linear_regression.R: -------------------------------------------------------------------------------- 1 | # Simple Linear Regression 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Salary_Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$Salary, SplitRatio = 2/3) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) 17 | 18 | # Fitting Simple Linear Regression to the Training set 19 | regressor = lm(formula = Salary ~ YearsExperience, 20 | data = training_set) 21 | 22 | # Predicting the Test set results 23 | y_pred = predict(regressor, newdata = test_set) 24 | 25 | # Visualising the Training set results 26 | #install.packages('ggplot2') 27 | library(ggplot2) 28 | ggplot() + 29 | geom_point(aes(x = training_set$YearsExperience, y = training_set$Salary), 30 | colour = 'red') + 31 | geom_line(aes(x = training_set$YearsExperience, y = predict(regressor, newdata = training_set)), 32 | colour = 'blue') + 33 | ggtitle('Salary vs Experience (Training set)') + 34 | xlab('Years of experience') + 35 | ylab('Salary') 36 | 37 | # Visualising the Test set results 38 | library(ggplot2) 39 | ggplot() + 40 | geom_point(aes(x = test_set$YearsExperience, y = test_set$Salary), 41 | colour = 'red') + 42 | geom_line(aes(x = training_set$YearsExperience, y = predict(regressor, newdata = training_set)), 43 | colour = 'blue') + 44 | ggtitle('Salary vs Experience (Test set)') + 45 | xlab('Years of experience') + 46 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 4 - Simple Linear Regression/Simple_Linear_Regression/simple_linear_regression.py: -------------------------------------------------------------------------------- 1 | # Simple Linear Regression 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('Salary_Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 1].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 = 1/3, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" 24 | 25 | # Fitting Simple Linear Regression to the Training set 26 | from sklearn.linear_model import LinearRegression 27 | regressor = LinearRegression() 28 | regressor.fit(X_train, y_train) 29 | 30 | # Predicting the Test set results 31 | y_pred = regressor.predict(X_test) 32 | 33 | # Visualising the Training set results 34 | plt.scatter(X_train, y_train, color = 'red') 35 | plt.plot(X_train, regressor.predict(X_train), color = 'blue') 36 | plt.title('Salary vs Experience (Training set)') 37 | plt.xlabel('Years of Experience') 38 | plt.ylabel('Salary') 39 | plt.show() 40 | 41 | # Visualising the Test set results 42 | plt.scatter(X_test, y_test, color = 'red') 43 | plt.plot(X_train, regressor.predict(X_train), color = 'blue') 44 | plt.title('Salary vs Experience (Test set)') 45 | plt.xlabel('Years of Experience') 46 | plt.ylabel('Salary') 47 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/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 52 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/BACKWARD SELECTION.txt: -------------------------------------------------------------------------------- 1 | implementations of Backward Elimination in Python, please find two of them below: 2 | 3 | Backward Elimination with p-values only: 4 | 5 | import statsmodels.formula.api as sm 6 | def backwardElimination(x, sl): 7 | numVars = len(x[0]) 8 | for i in range(0, numVars): 9 | regressor_OLS = sm.OLS(y, x).fit() 10 | maxVar = max(regressor_OLS.pvalues).astype(float) 11 | if maxVar > sl: 12 | for j in range(0, numVars - i): 13 | if (regressor_OLS.pvalues[j].astype(float) == maxVar): 14 | x = np.delete(x, j, 1) 15 | regressor_OLS.summary() 16 | return x 17 | 18 | SL = 0.05 19 | X_opt = X[:, [0, 1, 2, 3, 4, 5]] 20 | X_Modeled = backwardElimination(X_opt, SL) 21 | 22 | Backward Elimination with p-values and Adjusted R Squared: 23 | 24 | import statsmodels.formula.api as sm 25 | def backwardElimination(x, SL): 26 | numVars = len(x[0]) 27 | temp = np.zeros((50,6)).astype(int) 28 | for i in range(0, numVars): 29 | regressor_OLS = sm.OLS(y, x).fit() 30 | maxVar = max(regressor_OLS.pvalues).astype(float) 31 | adjR_before = regressor_OLS.rsquared_adj.astype(float) 32 | if maxVar > SL: 33 | for j in range(0, numVars - i): 34 | if (regressor_OLS.pvalues[j].astype(float) == maxVar): 35 | temp[:,j] = x[:, j] 36 | x = np.delete(x, j, 1) 37 | tmp_regressor = sm.OLS(y, x).fit() 38 | adjR_after = tmp_regressor.rsquared_adj.astype(float) 39 | if (adjR_before >= adjR_after): 40 | x_rollback = np.hstack((x, temp[:,[0,j]])) 41 | x_rollback = np.delete(x_rollback, j, 1) 42 | print (regressor_OLS.summary()) 43 | return x_rollback 44 | else: 45 | continue 46 | regressor_OLS.summary() 47 | return x 48 | 49 | SL = 0.05 50 | X_opt = X[:, [0, 1, 2, 3, 4, 5]] 51 | X_Modeled = backwardElimination(X_opt, SL) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Homework_Solutions/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 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Homework_Solutions/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Homework_Solutions/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 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 3].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Homework_Solutions/multiple_linear_regression.R: -------------------------------------------------------------------------------- 1 | # Multiple Linear Regression 2 | 3 | # Importing the dataset 4 | dataset = read.csv('50_Startups.csv') 5 | 6 | # Encoding categorical data 7 | dataset$State = factor(dataset$State, 8 | levels = c('New York', 'California', 'Florida'), 9 | labels = c(1, 2, 3)) 10 | 11 | # Splitting the dataset into the Training set and Test set 12 | # install.packages('caTools') 13 | library(caTools) 14 | set.seed(123) 15 | split = sample.split(dataset$Profit, SplitRatio = 0.8) 16 | training_set = subset(dataset, split == TRUE) 17 | test_set = subset(dataset, split == FALSE) 18 | 19 | # Feature Scaling 20 | # training_set = scale(training_set) 21 | # test_set = scale(test_set) 22 | 23 | # Fitting Multiple Linear Regression to the Training set 24 | regressor = lm(formula = Profit ~ ., 25 | data = training_set) 26 | 27 | # Predicting the Test set results 28 | y_pred = predict(regressor, newdata = test_set) 29 | 30 | # Building the optimal model using Backward Elimination 31 | regressor = lm(formula = Profit ~ R.D.Spend + Administration + Marketing.Spend + State, 32 | data = dataset) 33 | summary(regressor) 34 | # Optional Step: Remove State2 only (as opposed to removing State directly) 35 | # regressor = lm(formula = Profit ~ R.D.Spend + Administration + Marketing.Spend + factor(State, exclude = 2), 36 | # data = dataset) 37 | # summary(regressor) 38 | regressor = lm(formula = Profit ~ R.D.Spend + Administration + Marketing.Spend, 39 | data = dataset) 40 | summary(regressor) 41 | regressor = lm(formula = Profit ~ R.D.Spend + Marketing.Spend, 42 | data = dataset) 43 | summary(regressor) 44 | regressor = lm(formula = Profit ~ R.D.Spend, 45 | data = dataset) 46 | summary(regressor) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Homework_Solutions/multiple_linear_regression.py: -------------------------------------------------------------------------------- 1 | # Multiple Linear Regression 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('50_Startups.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 4].values 12 | 13 | # Encoding categorical data 14 | from sklearn.preprocessing import LabelEncoder, OneHotEncoder 15 | labelencoder = LabelEncoder() 16 | X[:, 3] = labelencoder.fit_transform(X[:, 3]) 17 | onehotencoder = OneHotEncoder(categorical_features = [3]) 18 | X = onehotencoder.fit_transform(X).toarray() 19 | 20 | # Avoiding the Dummy Variable Trap 21 | X = X[:, 1:] 22 | 23 | # Splitting the dataset into the Training set and Test set 24 | from sklearn.model_selection import train_test_split 25 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 26 | 27 | # Feature Scaling 28 | """from sklearn.preprocessing import StandardScaler 29 | sc_X = StandardScaler() 30 | X_train = sc_X.fit_transform(X_train) 31 | X_test = sc_X.transform(X_test) 32 | sc_y = StandardScaler() 33 | y_train = sc_y.fit_transform(y_train)""" 34 | 35 | # Fitting Multiple Linear Regression to the Training set 36 | from sklearn.linear_model import LinearRegression 37 | regressor = LinearRegression() 38 | regressor.fit(X_train, y_train) 39 | 40 | # Predicting the Test set results 41 | y_pred = regressor.predict(X_test) 42 | 43 | # Building the optimal model using Backward Elimination 44 | import statsmodels.api as sm 45 | print (sm.__version__) 46 | X = np.append(arr = np.ones((50, 1)).astype(int), values = X, axis = 1) 47 | X_opt = X[:, [0, 1, 2, 3, 4, 5]] 48 | regressor_OLS = sm.OLS(endog=y, exog=X_opt).fit() 49 | regressor_OLS.summary() 50 | X_opt = X[:, [0, 1, 3, 4, 5]] 51 | regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit() 52 | regressor_OLS.summary() 53 | X_opt = X[:, [0, 3, 4, 5]] 54 | regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit() 55 | regressor_OLS.summary() 56 | X_opt = X[:, [0, 3, 5]] 57 | regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit() 58 | regressor_OLS.summary() 59 | X_opt = X[:, [0, 3]] 60 | regressor_OLS = sm.OLS(endog = y, exog = X_opt).fit() 61 | regressor_OLS.summary() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Step-by-step-Blueprints-For-Building-Models.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/Step-by-step-Blueprints-For-Building-Models.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple 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 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 3].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/multiple_linear_regression.R: -------------------------------------------------------------------------------- 1 | # Multiple Linear Regression 2 | 3 | # Importing the dataset 4 | dataset = read.csv('50_Startups.csv') 5 | 6 | # Encoding categorical data 7 | dataset$State = factor(dataset$State, 8 | levels = c('New York', 'California', 'Florida'), 9 | labels = c(1, 2, 3)) 10 | 11 | # Splitting the dataset into the Training set and Test set 12 | # install.packages('caTools') 13 | library(caTools) 14 | set.seed(123) 15 | split = sample.split(dataset$Profit, SplitRatio = 0.8) 16 | training_set = subset(dataset, split == TRUE) 17 | test_set = subset(dataset, split == FALSE) 18 | 19 | # Feature Scaling 20 | # training_set = scale(training_set) 21 | # test_set = scale(test_set) 22 | 23 | # Fitting Multiple Linear Regression to the Training set 24 | regressor = lm(formula = Profit ~ ., 25 | data = training_set) 26 | 27 | # Predicting the Test set results 28 | y_pred = predict(regressor, newdata = test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 5 - Multiple Linear Regression/multiple_linear_regression.py: -------------------------------------------------------------------------------- 1 | # Multiple Linear Regression 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('50_Startups.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 4].values 12 | 13 | # Encoding categorical data 14 | from sklearn.preprocessing import LabelEncoder, OneHotEncoder 15 | labelencoder = LabelEncoder() 16 | X[:, 3] = labelencoder.fit_transform(X[:, 3]) 17 | onehotencoder = OneHotEncoder(categorical_features = [3]) 18 | X = onehotencoder.fit_transform(X).toarray() 19 | 20 | # Avoiding the Dummy Variable Trap 21 | X = X[:, 1:] 22 | 23 | # Splitting the dataset into the Training set and Test set 24 | from sklearn.model_selection import train_test_split 25 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 26 | 27 | # Feature Scaling 28 | """from sklearn.preprocessing import StandardScaler 29 | sc_X = StandardScaler() 30 | X_train = sc_X.fit_transform(X_train) 31 | X_test = sc_X.transform(X_test) 32 | sc_y = StandardScaler() 33 | y_train = sc_y.fit_transform(y_train)""" 34 | 35 | # Fitting Multiple Linear Regression to the Training set 36 | from sklearn.linear_model import LinearRegression 37 | regressor = LinearRegression() 38 | regressor.fit(X_train, y_train) 39 | 40 | # Predicting the Test set results 41 | y_pred = regressor.predict(X_test) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Polynomial_Regression/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Polynomial_Regression/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/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 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Polynomial_Regression/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Polynomial_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 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 3].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Polynomial_Regression/polynomial_regression.py: -------------------------------------------------------------------------------- 1 | # Polynomial Regression 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('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | """from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test)""" 22 | 23 | # Fitting Linear Regression to the dataset 24 | from sklearn.linear_model import LinearRegression 25 | lin_reg = LinearRegression() 26 | lin_reg.fit(X, y) 27 | 28 | # Fitting Polynomial Regression to the dataset 29 | from sklearn.preprocessing import PolynomialFeatures 30 | poly_reg = PolynomialFeatures(degree = 4) 31 | X_poly = poly_reg.fit_transform(X) 32 | poly_reg.fit(X_poly, y) 33 | lin_reg_2 = LinearRegression() 34 | lin_reg_2.fit(X_poly, y) 35 | 36 | # Visualising the Linear Regression results 37 | plt.scatter(X, y, color = 'red') 38 | plt.plot(X, lin_reg.predict(X), color = 'blue') 39 | plt.title('Truth or Bluff (Linear Regression)') 40 | plt.xlabel('Position level') 41 | plt.ylabel('Salary') 42 | plt.show() 43 | 44 | # Visualising the Polynomial Regression results 45 | plt.scatter(X, y, color = 'red') 46 | plt.plot(X, lin_reg_2.predict(poly_reg.fit_transform(X)), color = 'blue') 47 | plt.title('Truth or Bluff (Polynomial Regression)') 48 | plt.xlabel('Position level') 49 | plt.ylabel('Salary') 50 | plt.show() 51 | 52 | # Visualising the Polynomial Regression results (for higher resolution and smoother curve) 53 | X_grid = np.arange(min(X), max(X), 0.1) 54 | X_grid = X_grid.reshape((len(X_grid), 1)) 55 | plt.scatter(X, y, color = 'red') 56 | plt.plot(X_grid, lin_reg_2.predict(poly_reg.fit_transform(X_grid)), color = 'blue') 57 | plt.title('Truth or Bluff (Polynomial Regression)') 58 | plt.xlabel('Position level') 59 | plt.ylabel('Salary') 60 | plt.show() 61 | 62 | # Predicting a new result with Linear Regression 63 | lin_reg.predict([[6.5]]) 64 | 65 | # Predicting a new result with Polynomial Regression 66 | lin_reg_2.predict(poly_reg.fit_transform([[6.5]])) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Regression_Template/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Regression_Template/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Regression_Template/regression_template.R: -------------------------------------------------------------------------------- 1 | # Regression Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting the Regression Model to the dataset 20 | # Create your regressor here 21 | 22 | # Predicting a new result 23 | y_pred = predict(regressor, data.frame(Level = 6.5)) 24 | 25 | # Visualising the Regression Model results 26 | # install.packages('ggplot2') 27 | library(ggplot2) 28 | ggplot() + 29 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 30 | colour = 'red') + 31 | geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)), 32 | colour = 'blue') + 33 | ggtitle('Truth or Bluff (Regression Model)') + 34 | xlab('Level') + 35 | ylab('Salary') 36 | 37 | # Visualising the Regression Model results (for higher resolution and smoother curve) 38 | # install.packages('ggplot2') 39 | library(ggplot2) 40 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1) 41 | ggplot() + 42 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 43 | colour = 'red') + 44 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 45 | colour = 'blue') + 46 | ggtitle('Truth or Bluff (Regression Model)') + 47 | xlab('Level') + 48 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 6 - Polynomial Regression/Regression_Template/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 | dataset = pd.read_csv('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | """from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" 24 | 25 | # Fitting the Regression Model to the dataset 26 | # Create your regressor here 27 | 28 | # Predicting a new result 29 | y_pred = regressor.predict([[6.5]]) 30 | 31 | # Visualising the Regression results 32 | plt.scatter(X, y, color = 'red') 33 | plt.plot(X, regressor.predict(X), color = 'blue') 34 | plt.title('Truth or Bluff (Regression Model)') 35 | plt.xlabel('Position level') 36 | plt.ylabel('Salary') 37 | plt.show() 38 | 39 | # Visualising the Regression results (for higher resolution and smoother curve) 40 | X_grid = np.arange(min(X), max(X), 0.1) 41 | X_grid = X_grid.reshape((len(X_grid), 1)) 42 | plt.scatter(X, y, color = 'red') 43 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 44 | plt.title('Truth or Bluff (Regression Model)') 45 | plt.xlabel('Position level') 46 | plt.ylabel('Salary') 47 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)/.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)/.RData -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 7 - 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 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)/regression_template.R: -------------------------------------------------------------------------------- 1 | # Regression Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting the Regression Model to the dataset 20 | # Create your regressor here 21 | 22 | # Predicting a new result 23 | y_pred = predict(regressor, data.frame(Level = 6.5)) 24 | 25 | # Visualising the Regression Model results 26 | # install.packages('ggplot2') 27 | library(ggplot2) 28 | ggplot() + 29 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 30 | colour = 'red') + 31 | geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)), 32 | colour = 'blue') + 33 | ggtitle('Truth or Bluff (Regression Model)') + 34 | xlab('Level') + 35 | ylab('Salary') 36 | 37 | # Visualising the Regression Model results (for higher resolution and smoother curve) 38 | # install.packages('ggplot2') 39 | library(ggplot2) 40 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1) 41 | ggplot() + 42 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 43 | colour = 'red') + 44 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 45 | colour = 'blue') + 46 | ggtitle('Truth or Bluff (Regression Model)') + 47 | xlab('Level') + 48 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (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 | dataset = pd.read_csv('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | """from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train)""" 24 | 25 | # Fitting the Regression Model to the dataset 26 | # Create your regressor here 27 | 28 | # Predicting a new result 29 | y_pred = regressor.predict(6.5) 30 | 31 | # Visualising the Regression results 32 | plt.scatter(X, y, color = 'red') 33 | plt.plot(X, regressor.predict(X), color = 'blue') 34 | plt.title('Truth or Bluff (Regression Model)') 35 | plt.xlabel('Position level') 36 | plt.ylabel('Salary') 37 | plt.show() 38 | 39 | # Visualising the Regression results (for higher resolution and smoother curve) 40 | X_grid = np.arange(min(X), max(X), 0.1) 41 | X_grid = X_grid.reshape((len(X_grid), 1)) 42 | plt.scatter(X, y, color = 'red') 43 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 44 | plt.title('Truth or Bluff (Regression Model)') 45 | plt.xlabel('Position level') 46 | plt.ylabel('Salary') 47 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)/svr.R: -------------------------------------------------------------------------------- 1 | # SVR 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting SVR to the dataset 20 | # install.packages('e1071') 21 | library(e1071) 22 | regressor = svm(formula = Salary ~ ., 23 | data = dataset, 24 | type = 'eps-regression', 25 | kernel = 'radial') 26 | 27 | # Predicting a new result 28 | y_pred = predict(regressor, data.frame(Level = 6.5)) 29 | 30 | # Visualising the SVR results 31 | # install.packages('ggplot2') 32 | library(ggplot2) 33 | ggplot() + 34 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 35 | colour = 'red') + 36 | geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)), 37 | colour = 'blue') + 38 | ggtitle('Truth or Bluff (SVR)') + 39 | xlab('Level') + 40 | ylab('Salary') 41 | 42 | # Visualising the SVR results (for higher resolution and smoother curve) 43 | # install.packages('ggplot2') 44 | library(ggplot2) 45 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1) 46 | ggplot() + 47 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 48 | colour = 'red') + 49 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 50 | colour = 'blue') + 51 | ggtitle('Truth or Bluff (SVR)') + 52 | xlab('Level') + 53 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 7 - Support Vector Regression (SVR)/svr.py: -------------------------------------------------------------------------------- 1 | # SVR 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('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].values 12 | 13 | # Splitting the dataset into the Training set and Test set 14 | """from sklearn.cross_validation import train_test_split 15 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)""" 16 | 17 | # Feature Scaling 18 | from sklearn.preprocessing import StandardScaler 19 | sc_X = StandardScaler() 20 | sc_y = StandardScaler() 21 | X = sc_X.fit_transform(X) 22 | y = np.squeeze(sc_y.fit_transform(y.reshape(-1, 1))) 23 | 24 | # Fitting SVR to the dataset 25 | from sklearn.svm import SVR 26 | regressor = SVR(kernel = 'rbf') 27 | regressor.fit(X, y) 28 | 29 | # Predicting a new result 30 | y_pred = regressor.predict([[6.5]]) 31 | y_pred = sc_y.inverse_transform(y_pred) 32 | 33 | # Visualising the SVR results 34 | plt.scatter(X, y, color = 'red') 35 | plt.plot(X, regressor.predict(X), color = 'blue') 36 | plt.title('Truth or Bluff (SVR)') 37 | plt.xlabel('Position level') 38 | plt.ylabel('Salary') 39 | plt.show() 40 | 41 | # Visualising the SVR results (for higher resolution and smoother curve) 42 | X_grid = np.arange(min(X), max(X), 0.01) # choice of 0.01 instead of 0.1 step because the data is feature scaled 43 | X_grid = X_grid.reshape((len(X_grid), 1)) 44 | plt.scatter(X, y, color = 'red') 45 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 46 | plt.title('Truth or Bluff (SVR)') 47 | plt.xlabel('Position level') 48 | plt.ylabel('Salary') 49 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 8 - Decision Tree Regression/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 8 - Decision Tree Regression/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 8 - 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 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 8 - Decision Tree Regression/decision_tree_regression.R: -------------------------------------------------------------------------------- 1 | # Decision Tree Regression 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting Decision Tree Regression to the dataset 20 | # install.packages('rpart') 21 | library(rpart) 22 | regressor = rpart(formula = Salary ~ ., 23 | data = dataset, 24 | control = rpart.control(minsplit = 1)) 25 | 26 | # Predicting a new result with Decision Tree Regression 27 | y_pred = predict(regressor, data.frame(Level = 6.5)) 28 | 29 | # Visualising the Decision Tree Regression results (higher resolution) 30 | # install.packages('ggplot2') 31 | library(ggplot2) 32 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.01) 33 | ggplot() + 34 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 35 | colour = 'red') + 36 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 37 | colour = 'blue') + 38 | ggtitle('Truth or Bluff (Decision Tree Regression)') + 39 | xlab('Level') + 40 | ylab('Salary') 41 | 42 | # Plotting the tree 43 | plot(regressor) 44 | text(regressor) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 8 - Decision Tree Regression/decision_tree_regression.py: -------------------------------------------------------------------------------- 1 | # Decision Tree Regression 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('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].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.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" 24 | 25 | # Fitting Decision Tree Regression to the dataset 26 | from sklearn.tree import DecisionTreeRegressor 27 | regressor = DecisionTreeRegressor(random_state = 0) 28 | regressor.fit(X, y) 29 | 30 | # Predicting a new result 31 | y_pred = regressor.predict([[6.5]]) 32 | 33 | # Visualising the Decision Tree Regression results (higher resolution) 34 | X_grid = np.arange(min(X), max(X), 0.01) 35 | X_grid = X_grid.reshape((len(X_grid), 1)) 36 | plt.scatter(X, y, color = 'red') 37 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 38 | plt.title('Truth or Bluff (Decision Tree Regression)') 39 | plt.xlabel('Position level') 40 | plt.ylabel('Salary') 41 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 8 - Decision Tree Regression/regression_template.R: -------------------------------------------------------------------------------- 1 | # Regression Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting the Regression Model to the dataset 20 | # Create your regressor here 21 | 22 | # Predicting a new result 23 | y_pred = predict(regressor, data.frame(Level = 6.5)) 24 | 25 | # Visualising the Regression Model results 26 | # install.packages('ggplot2') 27 | library(ggplot2) 28 | ggplot() + 29 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 30 | colour = 'red') + 31 | geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)), 32 | colour = 'blue') + 33 | ggtitle('Truth or Bluff (Regression Model)') + 34 | xlab('Level') + 35 | ylab('Salary') 36 | 37 | # Visualising the Regression Model results (for higher resolution and smoother curve) 38 | # install.packages('ggplot2') 39 | library(ggplot2) 40 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1) 41 | ggplot() + 42 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 43 | colour = 'red') + 44 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 45 | colour = 'blue') + 46 | ggtitle('Truth or Bluff (Regression Model)') + 47 | xlab('Level') + 48 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 8 - Decision Tree 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 | dataset = pd.read_csv('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].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.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" 24 | 25 | # Fitting the Regression Model to the dataset 26 | # Create your regressor here 27 | 28 | # Predicting a new result 29 | y_pred = regressor.predict(6.5) 30 | 31 | # Visualising the Regression results 32 | plt.scatter(X, y, color = 'red') 33 | plt.plot(X, regressor.predict(X), color = 'blue') 34 | plt.title('Truth or Bluff (Regression Model)') 35 | plt.xlabel('Position level') 36 | plt.ylabel('Salary') 37 | plt.show() 38 | 39 | # Visualising the Regression results (for higher resolution and smoother curve) 40 | X_grid = np.arange(min(X), max(X), 0.1) 41 | X_grid = X_grid.reshape((len(X_grid), 1)) 42 | plt.scatter(X, y, color = 'red') 43 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 44 | plt.title('Truth or Bluff (Regression Model)') 45 | plt.xlabel('Position level') 46 | plt.ylabel('Salary') 47 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest Regression/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest Regression/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest 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 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest Regression/random_forest_regression.R: -------------------------------------------------------------------------------- 1 | # Random Forest Regression 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting Random Forest Regression to the dataset 20 | # install.packages('randomForest') 21 | library(randomForest) 22 | set.seed(1234) 23 | regressor = randomForest(x = dataset[-2], 24 | y = dataset$Salary, 25 | ntree = 500) 26 | 27 | # Predicting a new result with Random Forest Regression 28 | y_pred = predict(regressor, data.frame(Level = 6.5)) 29 | 30 | # Visualising the Random Forest Regression results (higher resolution) 31 | # install.packages('ggplot2') 32 | library(ggplot2) 33 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.01) 34 | ggplot() + 35 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 36 | colour = 'red') + 37 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 38 | colour = 'blue') + 39 | ggtitle('Truth or Bluff (Random Forest Regression)') + 40 | xlab('Level') + 41 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest Regression/random_forest_regression.py: -------------------------------------------------------------------------------- 1 | # Random Forest Regression 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('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].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.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" 24 | 25 | # Fitting Random Forest Regression to the dataset 26 | from sklearn.ensemble import RandomForestRegressor 27 | regressor = RandomForestRegressor(n_estimators = 10, random_state = 0) 28 | regressor.fit(X, y) 29 | 30 | # Predicting a new result 31 | y_pred = regressor.predict([[6.5]]) 32 | 33 | # Visualising the Random Forest Regression results (higher resolution) 34 | X_grid = np.arange(min(X), max(X), 0.01) 35 | X_grid = X_grid.reshape((len(X_grid), 1)) 36 | plt.scatter(X, y, color = 'red') 37 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 38 | plt.title('Truth or Bluff (Random Forest Regression)') 39 | plt.xlabel('Position level') 40 | plt.ylabel('Salary') 41 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest Regression/regression_template.R: -------------------------------------------------------------------------------- 1 | # Regression Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Position_Salaries.csv') 5 | dataset = dataset[2:3] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$Salary, SplitRatio = 2/3) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Fitting the Regression Model to the dataset 20 | # Create your regressor here 21 | 22 | # Predicting a new result 23 | y_pred = predict(regressor, data.frame(Level = 6.5)) 24 | 25 | # Visualising the Regression Model results 26 | # install.packages('ggplot2') 27 | library(ggplot2) 28 | ggplot() + 29 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 30 | colour = 'red') + 31 | geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = dataset)), 32 | colour = 'blue') + 33 | ggtitle('Truth or Bluff (Regression Model)') + 34 | xlab('Level') + 35 | ylab('Salary') 36 | 37 | # Visualising the Regression Model results (for higher resolution and smoother curve) 38 | # install.packages('ggplot2') 39 | library(ggplot2) 40 | x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1) 41 | ggplot() + 42 | geom_point(aes(x = dataset$Level, y = dataset$Salary), 43 | colour = 'red') + 44 | geom_line(aes(x = x_grid, y = predict(regressor, newdata = data.frame(Level = x_grid))), 45 | colour = 'blue') + 46 | ggtitle('Truth or Bluff (Regression Model)') + 47 | xlab('Level') + 48 | ylab('Salary') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/Section 9 - Random Forest 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 | dataset = pd.read_csv('Position_Salaries.csv') 10 | X = dataset.iloc[:, 1:2].values 11 | y = dataset.iloc[:, 2].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.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" 24 | 25 | # Fitting the Regression Model to the dataset 26 | # Create your regressor here 27 | 28 | # Predicting a new result 29 | y_pred = regressor.predict(6.5) 30 | 31 | # Visualising the Regression results 32 | plt.scatter(X, y, color = 'red') 33 | plt.plot(X, regressor.predict(X), color = 'blue') 34 | plt.title('Truth or Bluff (Regression Model)') 35 | plt.xlabel('Position level') 36 | plt.ylabel('Salary') 37 | plt.show() 38 | 39 | # Visualising the Regression results (for higher resolution and smoother curve) 40 | X_grid = np.arange(min(X), max(X), 0.1) 41 | X_grid = X_grid.reshape((len(X_grid), 1)) 42 | plt.scatter(X, y, color = 'red') 43 | plt.plot(X_grid, regressor.predict(X_grid), color = 'blue') 44 | plt.title('Truth or Bluff (Regression Model)') 45 | plt.xlabel('Position level') 46 | plt.ylabel('Salary') 47 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/notes-2.txt: -------------------------------------------------------------------------------- 1 | 1. What are the pros and cons of each model ? 2 | 3 | Please find here a cheat-sheet that gives you all the pros and the cons 4 | of each regression model. 5 | 6 | 2. How do I know which model to choose for my problem ? 7 | 8 | First, you need to figure out whether your problem is linear or non linear. 9 | You will learn how to do that in Part 10 - Model Selection. Then: 10 | 11 | If your problem is linear, you should go for Simple Linear Regression if you 12 | only have one feature, and Multiple Linear Regression if you have several features. 13 | 14 | If your problem is non linear, you should go for Polynomial Regression, SVR, 15 | Decision Tree or Random Forest. Then which one should you choose among these four ? 16 | That you will learn in Part 10 - Model Selection. The method consists of using a very 17 | relevant technique that evaluates your models performance, called k-Fold Cross Validation, 18 | and then picking the model that shows the best results. Feel free to jump directly to 19 | Part 10 if you already want to learn how to do that. 20 | 21 | 3. How can I improve each of these models ? 22 | 23 | In Part 10 - Model Selection, you will find the second section dedicated to Parameter 24 | Tuning, that will allow you to improve the performance of your models, by tuning them. 25 | You probably already noticed that each model is composed of two types of parameters: 26 | 27 | the parameters that are learnt, for example the coefficients in Linear Regression, 28 | 29 | the hyperparameters. 30 | 31 | The hyperparameters are the parameters that are not learnt and that are fixed values 32 | inside the model equations. For example, the regularization parameter lambda or the 33 | penalty parameter C are hyperparameters. So far we used the default value of these 34 | hyperparameters, and we haven't searched for their optimal value so that your model 35 | reaches even higher performance. Finding their optimal value is exactly what Parameter 36 | Tuning is about. So for those of you already interested in improving your model 37 | performance and doing some parameter tuning, feel free to jump directly to 38 | Part 10 - Model Selection. -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 2 - Regression/notes.txt: -------------------------------------------------------------------------------- 1 | Regression models (both linear and non-linear) are used for predicting a 2 | real value, like salary for example. If your independent variable is time, 3 | then you are forecasting future values, otherwise your model is predicting 4 | present but unknown values. Regression technique vary from Linear Regression 5 | to SVR and Random Forests Regression. 6 | 7 | In this part, you will understand and learn how to implement the following 8 | Machine Learning Regression models: 9 | 10 | Simple Linear Regression 11 | Multiple Linear Regression 12 | Polynomial Regression 13 | Support Vector for Regression (SVR) 14 | Decision Tree Classification 15 | Random Forest Classification 16 | 17 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 14 - Logistic Regression/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 14 - Logistic Regression/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 14 - Logistic Regression/logistic_regression.R: -------------------------------------------------------------------------------- 1 | # Logistic Regression 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 Logistic Regression to the Training set 23 | classifier = glm(formula = Purchased ~ ., 24 | family = binomial, 25 | data = training_set) 26 | 27 | # Predicting the Test set results 28 | prob_pred = predict(classifier, type = 'response', newdata = test_set[-3]) 29 | y_pred = ifelse(prob_pred > 0.5, 1, 0) 30 | 31 | # Making the Confusion Matrix 32 | cm = table(test_set[, 3], y_pred > 0.5) 33 | 34 | # Visualising the Training set results 35 | # install.packages('ElemStatLearn') 36 | library(ElemStatLearn) 37 | set = training_set 38 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 39 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 40 | grid_set = expand.grid(X1, X2) 41 | colnames(grid_set) = c('Age', 'EstimatedSalary') 42 | prob_set = predict(classifier, type = 'response', newdata = grid_set) 43 | y_grid = ifelse(prob_set > 0.5, 1, 0) 44 | plot(set[, -3], 45 | main = 'Logistic Regression (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 | prob_set = predict(classifier, type = 'response', newdata = grid_set) 60 | y_grid = ifelse(prob_set > 0.5, 1, 0) 61 | plot(set[, -3], 62 | main = 'Logistic Regression (Test set)', 63 | xlab = 'Age', ylab = 'Estimated Salary', 64 | xlim = range(X1), ylim = range(X2)) 65 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 66 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 67 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 15 - K-Nearest Neighbors (K-NN)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 15 - K-Nearest Neighbors (K-NN)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 15 - K-Nearest Neighbors (K-NN)/classification_template.R: -------------------------------------------------------------------------------- 1 | # Classification template 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 classifier to the Training set 23 | # Create your classifier here 24 | 25 | # Predicting the Test set results 26 | y_pred = predict(classifier, newdata = test_set[-3]) 27 | 28 | # Making the Confusion Matrix 29 | cm = table(test_set[, 3], y_pred) 30 | 31 | # Visualising the Training set results 32 | library(ElemStatLearn) 33 | set = training_set 34 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 35 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 36 | grid_set = expand.grid(X1, X2) 37 | colnames(grid_set) = c('Age', 'EstimatedSalary') 38 | y_grid = predict(classifier, newdata = grid_set) 39 | plot(set[, -3], 40 | main = 'Classifier (Training set)', 41 | xlab = 'Age', ylab = 'Estimated Salary', 42 | xlim = range(X1), ylim = range(X2)) 43 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 44 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 45 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 46 | 47 | # Visualising the Test set results 48 | library(ElemStatLearn) 49 | set = test_set 50 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 51 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 52 | grid_set = expand.grid(X1, X2) 53 | colnames(grid_set) = c('Age', 'EstimatedSalary') 54 | y_grid = predict(classifier, newdata = grid_set) 55 | plot(set[, -3], main = 'Classifier (Test set)', 56 | xlab = 'Age', ylab = 'Estimated Salary', 57 | xlim = range(X1), ylim = range(X2)) 58 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 59 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 60 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 15 - K-Nearest Neighbors (K-NN)/knn.R: -------------------------------------------------------------------------------- 1 | # K-Nearest Neighbors (K-NN) 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 K-NN to the Training set and Predicting the Test set results 23 | library(class) 24 | y_pred = knn(train = training_set[, -3], 25 | test = test_set[, -3], 26 | cl = training_set[, 3], 27 | k = 5, 28 | prob = TRUE) 29 | 30 | # Making the Confusion Matrix 31 | cm = table(test_set[, 3], y_pred) 32 | 33 | # Visualising the Training set results 34 | library(ElemStatLearn) 35 | set = training_set 36 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 37 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 38 | grid_set = expand.grid(X1, X2) 39 | colnames(grid_set) = c('Age', 'EstimatedSalary') 40 | y_grid = knn(train = training_set[, -3], test = grid_set, cl = training_set[, 3], k = 5) 41 | plot(set[, -3], 42 | main = 'K-NN (Training set)', 43 | xlab = 'Age', ylab = 'Estimated Salary', 44 | xlim = range(X1), ylim = range(X2)) 45 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 46 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 47 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 48 | 49 | # Visualising the Test set results 50 | library(ElemStatLearn) 51 | set = test_set 52 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 53 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 54 | grid_set = expand.grid(X1, X2) 55 | colnames(grid_set) = c('Age', 'EstimatedSalary') 56 | y_grid = knn(train = training_set[, -3], test = grid_set, cl = training_set[, 3], k = 5) 57 | plot(set[, -3], 58 | main = 'K-NN (Test set)', 59 | xlab = 'Age', ylab = 'Estimated Salary', 60 | xlim = range(X1), ylim = range(X2)) 61 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 62 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 63 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 16 - Support Vector Machine (SVM)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 16 - Support Vector Machine (SVM)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 16 - Support Vector Machine (SVM)/classification_template.R: -------------------------------------------------------------------------------- 1 | # Classification template 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 classifier to the Training set 23 | # Create your classifier here 24 | 25 | # Predicting the Test set results 26 | y_pred = predict(classifier, newdata = test_set[-3]) 27 | 28 | # Making the Confusion Matrix 29 | cm = table(test_set[, 3], y_pred) 30 | 31 | # Visualising the Training set results 32 | library(ElemStatLearn) 33 | set = training_set 34 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 35 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 36 | grid_set = expand.grid(X1, X2) 37 | colnames(grid_set) = c('Age', 'EstimatedSalary') 38 | y_grid = predict(classifier, newdata = grid_set) 39 | plot(set[, -3], 40 | main = 'Classifier (Training set)', 41 | xlab = 'Age', ylab = 'Estimated Salary', 42 | xlim = range(X1), ylim = range(X2)) 43 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 44 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 45 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 46 | 47 | # Visualising the Test set results 48 | library(ElemStatLearn) 49 | set = test_set 50 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 51 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 52 | grid_set = expand.grid(X1, X2) 53 | colnames(grid_set) = c('Age', 'EstimatedSalary') 54 | y_grid = predict(classifier, newdata = grid_set) 55 | plot(set[, -3], main = 'Classifier (Test set)', 56 | xlab = 'Age', ylab = 'Estimated Salary', 57 | xlim = range(X1), ylim = range(X2)) 58 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 59 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 60 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 16 - Support Vector Machine (SVM)/svm.R: -------------------------------------------------------------------------------- 1 | # Support Vector Machine (SVM) 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 SVM to the Training set 23 | # install.packages('e1071') 24 | library(e1071) 25 | classifier = svm(formula = Purchased ~ ., 26 | data = training_set, 27 | type = 'C-classification', 28 | kernel = 'linear') 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, newdata = grid_set) 44 | plot(set[, -3], 45 | main = 'SVM (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, newdata = grid_set) 60 | plot(set[, -3], main = 'SVM (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')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 17 - Kernel SVM/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 17 - Kernel SVM/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 17 - Kernel SVM/classification_template.R: -------------------------------------------------------------------------------- 1 | # Classification template 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 classifier to the Training set 23 | # Create your classifier here 24 | 25 | # Predicting the Test set results 26 | y_pred = predict(classifier, newdata = test_set[-3]) 27 | 28 | # Making the Confusion Matrix 29 | cm = table(test_set[, 3], y_pred) 30 | 31 | # Visualising the Training set results 32 | library(ElemStatLearn) 33 | set = training_set 34 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 35 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 36 | grid_set = expand.grid(X1, X2) 37 | colnames(grid_set) = c('Age', 'EstimatedSalary') 38 | y_grid = predict(classifier, newdata = grid_set) 39 | plot(set[, -3], 40 | main = 'Classifier (Training set)', 41 | xlab = 'Age', ylab = 'Estimated Salary', 42 | xlim = range(X1), ylim = range(X2)) 43 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 44 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 45 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 46 | 47 | # Visualising the Test set results 48 | library(ElemStatLearn) 49 | set = test_set 50 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 51 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 52 | grid_set = expand.grid(X1, X2) 53 | colnames(grid_set) = c('Age', 'EstimatedSalary') 54 | y_grid = predict(classifier, newdata = grid_set) 55 | plot(set[, -3], main = 'Classifier (Test set)', 56 | xlab = 'Age', ylab = 'Estimated Salary', 57 | xlim = range(X1), ylim = range(X2)) 58 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 59 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 60 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 17 - Kernel SVM/classification_template.py: -------------------------------------------------------------------------------- 1 | # Classification 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 | 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 classifier to the Training set 24 | # Create your classifier here 25 | 26 | # Predicting the Test set results 27 | y_pred = classifier.predict(X_test) 28 | 29 | # Making the Confusion Matrix 30 | from sklearn.metrics import confusion_matrix 31 | cm = confusion_matrix(y_test, y_pred) 32 | 33 | # Visualising the Training set results 34 | from matplotlib.colors import ListedColormap 35 | X_set, y_set = X_train, y_train 36 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 37 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 38 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 39 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 40 | plt.xlim(X1.min(), X1.max()) 41 | plt.ylim(X2.min(), X2.max()) 42 | for i, j in enumerate(np.unique(y_set)): 43 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 44 | c = ListedColormap(('red', 'green'))(i), label = j) 45 | plt.title('Classifier (Training set)') 46 | plt.xlabel('Age') 47 | plt.ylabel('Estimated Salary') 48 | plt.legend() 49 | plt.show() 50 | 51 | # Visualising the Test set results 52 | from matplotlib.colors import ListedColormap 53 | X_set, y_set = X_test, y_test 54 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 55 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 56 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 57 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 58 | plt.xlim(X1.min(), X1.max()) 59 | plt.ylim(X2.min(), X2.max()) 60 | for i, j in enumerate(np.unique(y_set)): 61 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 62 | c = ListedColormap(('red', 'green'))(i), label = j) 63 | plt.title('Classifier (Test set)') 64 | plt.xlabel('Age') 65 | plt.ylabel('Estimated Salary') 66 | plt.legend() 67 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 17 - Kernel SVM/kernel_svm.R: -------------------------------------------------------------------------------- 1 | # Kernel SVM 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 Kernel SVM to the Training set 23 | # install.packages('e1071') kernlab 24 | library(e1071) 25 | classifier = svm(formula = Purchased ~ ., 26 | data = training_set, 27 | type = 'C-classification', 28 | kernel = 'radial') 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, newdata = grid_set) 44 | plot(set[, -3], 45 | main = 'Kernel SVM (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, newdata = grid_set) 60 | plot(set[, -3], main = 'Kernel SVM (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')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/Rplot.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/Rplot.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/Rplot02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/Rplot02.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/classification_template.R: -------------------------------------------------------------------------------- 1 | # Classification template 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 classifier to the Training set 23 | # Create your classifier here 24 | 25 | # Predicting the Test set results 26 | y_pred = predict(classifier, newdata = test_set[-3]) 27 | 28 | # Making the Confusion Matrix 29 | cm = table(test_set[, 3], y_pred) 30 | 31 | # Visualising the Training set results 32 | library(ElemStatLearn) 33 | set = training_set 34 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 35 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 36 | grid_set = expand.grid(X1, X2) 37 | colnames(grid_set) = c('Age', 'EstimatedSalary') 38 | y_grid = predict(classifier, newdata = grid_set) 39 | plot(set[, -3], 40 | main = 'Classifier (Training set)', 41 | xlab = 'Age', ylab = 'Estimated Salary', 42 | xlim = range(X1), ylim = range(X2)) 43 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 44 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 45 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 46 | 47 | # Visualising the Test set results 48 | library(ElemStatLearn) 49 | set = test_set 50 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 51 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 52 | grid_set = expand.grid(X1, X2) 53 | colnames(grid_set) = c('Age', 'EstimatedSalary') 54 | y_grid = predict(classifier, newdata = grid_set) 55 | plot(set[, -3], main = 'Classifier (Test set)', 56 | xlab = 'Age', ylab = 'Estimated Salary', 57 | xlim = range(X1), ylim = range(X2)) 58 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 59 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 60 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/classification_template.py: -------------------------------------------------------------------------------- 1 | # Classification 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 | 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 classifier to the Training set 24 | # Create your classifier here 25 | 26 | # Predicting the Test set results 27 | y_pred = classifier.predict(X_test) 28 | 29 | # Making the Confusion Matrix 30 | from sklearn.metrics import confusion_matrix 31 | cm = confusion_matrix(y_test, y_pred) 32 | 33 | # Visualising the Training set results 34 | from matplotlib.colors import ListedColormap 35 | X_set, y_set = X_train, y_train 36 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 37 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 38 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 39 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 40 | plt.xlim(X1.min(), X1.max()) 41 | plt.ylim(X2.min(), X2.max()) 42 | for i, j in enumerate(np.unique(y_set)): 43 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 44 | c = ListedColormap(('red', 'green'))(i), label = j) 45 | plt.title('Classifier (Training set)') 46 | plt.xlabel('Age') 47 | plt.ylabel('Estimated Salary') 48 | plt.legend() 49 | plt.show() 50 | 51 | # Visualising the Test set results 52 | from matplotlib.colors import ListedColormap 53 | X_set, y_set = X_test, y_test 54 | X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01), 55 | np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) 56 | plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape), 57 | alpha = 0.75, cmap = ListedColormap(('red', 'green'))) 58 | plt.xlim(X1.min(), X1.max()) 59 | plt.ylim(X2.min(), X2.max()) 60 | for i, j in enumerate(np.unique(y_set)): 61 | plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], 62 | c = ListedColormap(('red', 'green'))(i), label = j) 63 | plt.title('Classifier (Test set)') 64 | plt.xlabel('Age') 65 | plt.ylabel('Estimated Salary') 66 | plt.legend() 67 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 18 - Naive Bayes/naive_bayes.R: -------------------------------------------------------------------------------- 1 | # Naive Bayes 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 SVM to the Training set 23 | # install.packages('e1071') 24 | library(e1071) 25 | classifier = naiveBayes(x = training_set[-3], 26 | y = training_set$Purchased) 27 | 28 | # Predicting the Test set results 29 | y_pred = predict(classifier, newdata = test_set[-3]) 30 | 31 | # Making the Confusion Matrix 32 | cm = table(test_set[, 3], y_pred) 33 | 34 | # Visualising the Training set results 35 | library(ElemStatLearn) 36 | set = training_set 37 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 38 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 39 | grid_set = expand.grid(X1, X2) 40 | colnames(grid_set) = c('Age', 'EstimatedSalary') 41 | y_grid = predict(classifier, newdata = grid_set) 42 | plot(set[, -3], 43 | main = 'Naive Bayes (Training set)', 44 | xlab = 'Age', ylab = 'Estimated Salary', 45 | xlim = range(X1), ylim = range(X2)) 46 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 47 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 48 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 49 | 50 | # Visualising the Test set results 51 | library(ElemStatLearn) 52 | set = test_set 53 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 54 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 55 | grid_set = expand.grid(X1, X2) 56 | colnames(grid_set) = c('Age', 'EstimatedSalary') 57 | y_grid = predict(classifier, newdata = grid_set) 58 | plot(set[, -3], main = 'Naive Bayes (Test set)', 59 | xlab = 'Age', ylab = 'Estimated Salary', 60 | xlim = range(X1), ylim = range(X2)) 61 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 62 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 63 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/PastHires.csv: -------------------------------------------------------------------------------- 1 | Years Experience,Employed?,Previous employers,Level of Education,Top-tier school,Interned,Hired 2 | 10,Y,4,BS,N,N,Y 3 | 0,N,0,BS,Y,Y,Y 4 | 7,N,6,BS,N,N,N 5 | 2,Y,1,MS,Y,N,Y 6 | 20,N,2,PhD,Y,N,N 7 | 0,N,0,PhD,Y,Y,Y 8 | 5,Y,2,MS,N,Y,Y 9 | 3,N,1,BS,N,Y,Y 10 | 15,Y,5,BS,N,N,Y 11 | 0,N,0,BS,N,N,N 12 | 1,N,1,PhD,Y,N,N 13 | 4,Y,1,BS,N,Y,Y 14 | 0,N,0,PhD,Y,N,Y 15 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/classification_template.R: -------------------------------------------------------------------------------- 1 | # Classification template 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 classifier to the Training set 23 | # Create your classifier here 24 | 25 | # Predicting the Test set results 26 | y_pred = predict(classifier, newdata = test_set[-3]) 27 | 28 | # Making the Confusion Matrix 29 | cm = table(test_set[, 3], y_pred) 30 | 31 | # Visualising the Training set results 32 | library(ElemStatLearn) 33 | set = training_set 34 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 35 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 36 | grid_set = expand.grid(X1, X2) 37 | colnames(grid_set) = c('Age', 'EstimatedSalary') 38 | y_grid = predict(classifier, newdata = grid_set) 39 | plot(set[, -3], 40 | main = 'Classifier (Training set)', 41 | xlab = 'Age', ylab = 'Estimated Salary', 42 | xlim = range(X1), ylim = range(X2)) 43 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 44 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 45 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 46 | 47 | # Visualising the Test set results 48 | library(ElemStatLearn) 49 | set = test_set 50 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 51 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 52 | grid_set = expand.grid(X1, X2) 53 | colnames(grid_set) = c('Age', 'EstimatedSalary') 54 | y_grid = predict(classifier, newdata = grid_set) 55 | plot(set[, -3], main = 'Classifier (Test set)', 56 | xlab = 'Age', ylab = 'Estimated Salary', 57 | xlim = range(X1), ylim = range(X2)) 58 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 59 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 60 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/decision_tree_classification-2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Dec 30 19:23:42 2019 4 | 5 | @author: lenovo 6 | """ 7 | import numpy as np 8 | import pandas as pd 9 | from sklearn import tree 10 | 11 | input_file = "PastHires.csv" 12 | df = pd.read_csv(input_file, header = 0) 13 | df.head() 14 | 15 | d = {'Y': 1, 'N': 0} 16 | df['Hired'] = df['Hired'].map(d) 17 | df['Employed?'] = df['Employed?'].map(d) 18 | df['Top-tier school'] = df['Top-tier school'].map(d) 19 | df['Interned'] = df['Interned'].map(d) 20 | d = {'BS': 0, 'MS': 1, 'PhD': 2} 21 | df['Level of Education'] = df['Level of Education'].map(d) 22 | df.head() 23 | 24 | features = list(df.columns[:6]) 25 | features 26 | 27 | y = df["Hired"] 28 | X = df[features] 29 | clf = tree.DecisionTreeClassifier() 30 | clf = clf.fit(X,y) 31 | 32 | from IPython.display import Image 33 | from sklearn.externals.six import StringIO 34 | import pydotplus 35 | 36 | dot_data = StringIO() 37 | tree.export_graphviz(clf, out_file=dot_data, 38 | feature_names=features) 39 | graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) 40 | Image(graph.create_png()) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/decision_tree_classification.R: -------------------------------------------------------------------------------- 1 | # Decision Tree 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 Decision Tree Classification to the Training set 23 | # install.packages('rpart') 24 | library(rpart) 25 | classifier = rpart(formula = Purchased ~ ., 26 | data = training_set) 27 | 28 | # Predicting the Test set results 29 | y_pred = predict(classifier, newdata = test_set[-3], type = 'class') 30 | 31 | # Making the Confusion Matrix 32 | cm = table(test_set[, 3], y_pred) 33 | 34 | # Visualising the Training set results 35 | library(ElemStatLearn) 36 | set = training_set 37 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 38 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 39 | grid_set = expand.grid(X1, X2) 40 | colnames(grid_set) = c('Age', 'EstimatedSalary') 41 | y_grid = predict(classifier, newdata = grid_set, type = 'class') 42 | plot(set[, -3], 43 | main = 'Decision Tree Classification (Training set)', 44 | xlab = 'Age', ylab = 'Estimated Salary', 45 | xlim = range(X1), ylim = range(X2)) 46 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 47 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 48 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 49 | 50 | # Visualising the Test set results 51 | library(ElemStatLearn) 52 | set = test_set 53 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 54 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 55 | grid_set = expand.grid(X1, X2) 56 | colnames(grid_set) = c('Age', 'EstimatedSalary') 57 | y_grid = predict(classifier, newdata = grid_set, type = 'class') 58 | plot(set[, -3], main = 'Decision Tree Classification (Test set)', 59 | xlab = 'Age', ylab = 'Estimated Salary', 60 | xlim = range(X1), ylim = range(X2)) 61 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 62 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 63 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 64 | 65 | # Plotting the tree 66 | plot(classifier) 67 | text(classifier) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/traing result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 19 - Decision Tree Classification/traing result.png -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 20 - Random Forest Classification/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 3 - Classification/Section 20 - Random Forest Classification/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 20 - Random Forest Classification/classification_template.R: -------------------------------------------------------------------------------- 1 | # Classification template 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 classifier to the Training set 23 | # Create your classifier here 24 | 25 | # Predicting the Test set results 26 | y_pred = predict(classifier, newdata = test_set[-3]) 27 | 28 | # Making the Confusion Matrix 29 | cm = table(test_set[, 3], y_pred) 30 | 31 | # Visualising the Training set results 32 | library(ElemStatLearn) 33 | set = training_set 34 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 35 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 36 | grid_set = expand.grid(X1, X2) 37 | colnames(grid_set) = c('Age', 'EstimatedSalary') 38 | y_grid = predict(classifier, newdata = grid_set) 39 | plot(set[, -3], 40 | main = 'Classifier (Training set)', 41 | xlab = 'Age', ylab = 'Estimated Salary', 42 | xlim = range(X1), ylim = range(X2)) 43 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 44 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 45 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) 46 | 47 | # Visualising the Test set results 48 | library(ElemStatLearn) 49 | set = test_set 50 | X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01) 51 | X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01) 52 | grid_set = expand.grid(X1, X2) 53 | colnames(grid_set) = c('Age', 'EstimatedSalary') 54 | y_grid = predict(classifier, newdata = grid_set) 55 | plot(set[, -3], main = 'Classifier (Test set)', 56 | xlab = 'Age', ylab = 'Estimated Salary', 57 | xlim = range(X1), ylim = range(X2)) 58 | contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE) 59 | points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato')) 60 | points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3')) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/Section 20 - 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) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/notes-1.txt: -------------------------------------------------------------------------------- 1 | Unlike regression where you predict a continuous number, you use 2 | classification to predict a category. There is a wide variety of 3 | classification applications from medicine to marketing. Classification 4 | models include linear models like Logistic Regression, SVM, and nonlinear 5 | ones like K-NN, Kernel SVM and Random Forests. 6 | 7 | In this part, you will understand and learn how to implement the following 8 | Machine Learning Classification models: 9 | 10 | Logistic Regression 11 | K-Nearest Neighbors (K-NN) 12 | Support Vector Machine (SVM) 13 | Kernel SVM 14 | Naive Bayes 15 | Decision Tree Classification 16 | Random Forest Classification -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 3 - Classification/notes-2.txt: -------------------------------------------------------------------------------- 1 | 1. What are the pros and cons of each model ? 2 | 3 | Please find here a cheat-sheet that gives you all the pros and the 4 | cons of each classification model. 5 | 6 | 2. How do I know which model to choose for my problem ? 7 | 8 | Same as for regression models, you first need to figure out whether 9 | your problem is linear or non linear. You will learn how to do that 10 | in Part 10 - Model Selection. Then: 11 | 12 | If your problem is linear, you should go for Logistic Regression or SVM. 13 | 14 | If your problem is non linear, you should go for K-NN, Naive Bayes, 15 | Decision Tree or Random Forest. 16 | 17 | Then which one should you choose in each case ? You will learn that 18 | in Part 10 - Model Selection with k-Fold Cross Validation. 19 | 20 | Then from a business point of view, you would rather use: 21 | 22 | - Logistic Regression or Naive Bayes when you want to rank your predictions 23 | by their probability. For example if you want to rank your customers from the 24 | highest probability that they buy a certain product, to the lowest probability. 25 | Eventually that allows you to target your marketing campaigns. And of course for 26 | this type of business problem, you should use Logistic Regression if your problem 27 | is linear, and Naive Bayes if your problem is non linear. 28 | 29 | - SVM when you want to predict to which segment your customers belong to. 30 | Segments can be any kind of segments, for example some market segments you 31 | identified earlier with clustering. 32 | 33 | - Decision Tree when you want to have clear interpretation of your model results, 34 | 35 | - Random Forest when you are just looking for high performance with less need f 36 | or interpretation. 37 | 38 | 3. How can I improve each of these models ? 39 | 40 | Same answer as in Part 2: 41 | 42 | In Part 10 - Model Selection, you will find the second section dedicated to 43 | Parameter Tuning, that will allow you to improve the performance of your models, 44 | by tuning them. You probably already noticed that each model is composed of two types 45 | of parameters: 46 | 47 | the parameters that are learnt, for example the coefficients in Linear Regression, 48 | 49 | the hyperparameters. 50 | 51 | The hyperparameters are the parameters that are not learnt and that are fixed values 52 | inside the model equations. For example, the regularization parameter lambda or the 53 | penalty parameter C are hyperparameters. So far we used the default value of these 54 | hyperparameters, and we haven't searched for their optimal value so that your model 55 | reaches even higher performance. Finding their optimal value is exactly what Parameter 56 | Tuning is about. So for those of you already interested in improving your model 57 | performance and doing some parameter tuning, feel free to jump directly to 58 | Part 10 - Model Selection. -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Clustering-Pros-Cons.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 4 - Clustering/Clustering-Pros-Cons.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/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 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 3].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.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.R: -------------------------------------------------------------------------------- 1 | # K-Means Clustering 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Mall_Customers.csv') 5 | dataset = dataset[4:5] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Using the elbow method to find the optimal number of clusters 20 | set.seed(6) 21 | wcss = vector() 22 | for (i in 1:10) wcss[i] = sum(kmeans(dataset, i)$withinss) 23 | plot(1:10, 24 | wcss, 25 | type = 'b', 26 | main = paste('The Elbow Method'), 27 | xlab = 'Number of clusters', 28 | ylab = 'WCSS') 29 | 30 | # Fitting K-Means to the dataset 31 | set.seed(29) 32 | kmeans = kmeans(x = dataset, centers = 5) 33 | y_kmeans = kmeans$cluster 34 | 35 | # Visualising the clusters 36 | library(cluster) 37 | clusplot(dataset, 38 | y_kmeans, 39 | lines = 0, 40 | shade = TRUE, 41 | color = TRUE, 42 | labels = 2, 43 | plotchar = FALSE, 44 | span = TRUE, 45 | main = paste('Clusters of customers'), 46 | xlab = 'Annual Income', 47 | ylab = 'Spending Score') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 24 - K-Means Clustering/kmeans.py: -------------------------------------------------------------------------------- 1 | # K-Means Clustering 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('Mall_Customers.csv') 10 | X = dataset.iloc[:, [3, 4]].values 11 | # y = dataset.iloc[:, 3].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.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" 24 | 25 | # Using the elbow method to find the optimal number of clusters 26 | from sklearn.cluster import KMeans 27 | wcss = [] 28 | for i in range(1, 11): 29 | kmeans = KMeans(n_clusters = i, init = 'k-means++', random_state = 42) 30 | kmeans.fit(X) 31 | wcss.append(kmeans.inertia_) 32 | plt.plot(range(1, 11), wcss) 33 | plt.title('The Elbow Method') 34 | plt.xlabel('Number of clusters') 35 | plt.ylabel('WCSS') 36 | plt.show() 37 | 38 | # Fitting K-Means to the dataset 39 | kmeans = KMeans(n_clusters = 5, init = 'k-means++', random_state = 42) 40 | y_kmeans = kmeans.fit_predict(X) 41 | 42 | # Visualising the clusters 43 | plt.scatter(X[y_kmeans == 0, 0], X[y_kmeans == 0, 1], s = 100, c = 'red', label = 'Cluster 1') 44 | plt.scatter(X[y_kmeans == 1, 0], X[y_kmeans == 1, 1], s = 100, c = 'blue', label = 'Cluster 2') 45 | plt.scatter(X[y_kmeans == 2, 0], X[y_kmeans == 2, 1], s = 100, c = 'green', label = 'Cluster 3') 46 | plt.scatter(X[y_kmeans == 3, 0], X[y_kmeans == 3, 1], s = 100, c = 'cyan', label = 'Cluster 4') 47 | plt.scatter(X[y_kmeans == 4, 0], X[y_kmeans == 4, 1], s = 100, c = 'magenta', label = 'Cluster 5') 48 | plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], s = 300, c = 'yellow', label = 'Centroids') 49 | plt.title('Clusters of customers') 50 | plt.xlabel('Annual Income (k$)') 51 | plt.ylabel('Spending Score (1-100)') 52 | plt.legend() 53 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 25 - Hierarchical Clustering/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 4 - Clustering/Section 25 - Hierarchical Clustering/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 25 - Hierarchical Clustering/data_preprocessing_template.R: -------------------------------------------------------------------------------- 1 | # Data Preprocessing Template 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Data.csv') 5 | 6 | # Splitting the dataset into the Training set and Test set 7 | # install.packages('caTools') 8 | library(caTools) 9 | set.seed(123) 10 | split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 11 | training_set = subset(dataset, split == TRUE) 12 | test_set = subset(dataset, split == FALSE) 13 | 14 | # Feature Scaling 15 | # training_set = scale(training_set) 16 | # test_set = scale(test_set) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 25 - Hierarchical Clustering/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 | dataset = pd.read_csv('Data.csv') 10 | X = dataset.iloc[:, :-1].values 11 | y = dataset.iloc[:, 3].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.2, random_state = 0) 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 25 - Hierarchical Clustering/hc.R: -------------------------------------------------------------------------------- 1 | # Hierarchical Clustering 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Mall_Customers.csv') 5 | dataset = dataset[4:5] 6 | 7 | # Splitting the dataset into the Training set and Test set 8 | # install.packages('caTools') 9 | # library(caTools) 10 | # set.seed(123) 11 | # split = sample.split(dataset$DependentVariable, SplitRatio = 0.8) 12 | # training_set = subset(dataset, split == TRUE) 13 | # test_set = subset(dataset, split == FALSE) 14 | 15 | # Feature Scaling 16 | # training_set = scale(training_set) 17 | # test_set = scale(test_set) 18 | 19 | # Using the dendrogram to find the optimal number of clusters 20 | dendrogram = hclust(d = dist(dataset, method = 'euclidean'), method = 'ward.D') 21 | plot(dendrogram, 22 | main = paste('Dendrogram'), 23 | xlab = 'Customers', 24 | ylab = 'Euclidean distances') 25 | 26 | # Fitting Hierarchical Clustering to the dataset 27 | hc = hclust(d = dist(dataset, method = 'euclidean'), method = 'ward.D') 28 | y_hc = cutree(hc, 5) 29 | 30 | # Visualising the clusters 31 | library(cluster) 32 | clusplot(dataset, 33 | y_hc, 34 | lines = 0, 35 | shade = TRUE, 36 | color = TRUE, 37 | labels= 2, 38 | plotchar = FALSE, 39 | span = TRUE, 40 | main = paste('Clusters of customers'), 41 | xlab = 'Annual Income', 42 | ylab = 'Spending Score') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/Section 25 - Hierarchical Clustering/hc.py: -------------------------------------------------------------------------------- 1 | # Hierarchical Clustering 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('Mall_Customers.csv') 10 | X = dataset.iloc[:, [3, 4]].values 11 | # y = dataset.iloc[:, 3].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.2, random_state = 0)""" 16 | 17 | # Feature 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.transform(X_test) 22 | sc_y = StandardScaler() 23 | y_train = sc_y.fit_transform(y_train.reshape(-1,1))""" 24 | 25 | # Using the dendrogram to find the optimal number of clusters 26 | import scipy.cluster.hierarchy as sch 27 | dendrogram = sch.dendrogram(sch.linkage(X, method = 'ward')) 28 | plt.title('Dendrogram') 29 | plt.xlabel('Customers') 30 | plt.ylabel('Euclidean distances') 31 | plt.show() 32 | 33 | # Fitting Hierarchical Clustering to the dataset 34 | from sklearn.cluster import AgglomerativeClustering 35 | hc = AgglomerativeClustering(n_clusters = 5, affinity = 'euclidean', linkage = 'ward') 36 | y_hc = hc.fit_predict(X) 37 | 38 | # Visualising the clusters 39 | plt.scatter(X[y_hc == 0, 0], X[y_hc == 0, 1], s = 100, c = 'red', label = 'Cluster 1') 40 | plt.scatter(X[y_hc == 1, 0], X[y_hc == 1, 1], s = 100, c = 'blue', label = 'Cluster 2') 41 | plt.scatter(X[y_hc == 2, 0], X[y_hc == 2, 1], s = 100, c = 'green', label = 'Cluster 3') 42 | plt.scatter(X[y_hc == 3, 0], X[y_hc == 3, 1], s = 100, c = 'cyan', label = 'Cluster 4') 43 | plt.scatter(X[y_hc == 4, 0], X[y_hc == 4, 1], s = 100, c = 'magenta', label = 'Cluster 5') 44 | plt.title('Clusters of customers') 45 | plt.xlabel('Annual Income (k$)') 46 | plt.ylabel('Spending Score (1-100)') 47 | plt.legend() 48 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/notes-1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 4 - Clustering/notes-1.txt -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 4 - Clustering/notes-2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 4 - Clustering/notes-2.txt -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_Python/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_Python/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_Python/__pycache__/apyori.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_Python/__pycache__/apyori.cpython-37.pyc -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_Python/apriori.py: -------------------------------------------------------------------------------- 1 | # Apriori 2 | 3 | # Importing the libraries 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | 8 | # Data Preprocessing 9 | dataset = pd.read_csv('Market_Basket_Optimisation.csv', header = None) 10 | transactions = [] 11 | for i in range(0, 7501): 12 | transactions.append([str(dataset.values[i,j]) for j in range(0, 20)]) 13 | 14 | # Training Apriori on the dataset 15 | from apyori import apriori 16 | rules = apriori(transactions, min_support = 0.003, min_confidence = 0.2, min_lift = 3, min_length = 2) 17 | 18 | # Visualising the results 19 | results = list(rules) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_R/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_R/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 28 - Apriori/Apriori_R/apriori.R: -------------------------------------------------------------------------------- 1 | # Apriori 2 | 3 | # Data Preprocessing 4 | # install.packages('arules') 5 | library(arules) 6 | dataset = read.csv('Market_Basket_Optimisation.csv', header = FALSE) 7 | dataset = read.transactions('Market_Basket_Optimisation.csv', sep = ',', rm.duplicates = TRUE) 8 | summary(dataset) 9 | itemFrequencyPlot(dataset, topN = 10) 10 | 11 | # Training Apriori on the dataset 12 | rules = apriori(data = dataset, parameter = list(support = 0.003, confidence = 0.2)) 13 | 14 | # Visualising the results 15 | inspect(sort(rules, by = 'lift')[1:10]) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 29 - Eclat/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 5 - Association Rule Learning/Section 29 - Eclat/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 5 - Association Rule Learning/Section 29 - Eclat/eclat.R: -------------------------------------------------------------------------------- 1 | # Eclat 2 | 3 | # Data Preprocessing 4 | # install.packages('arules') 5 | library(arules) 6 | dataset = read.csv('Market_Basket_Optimisation.csv') 7 | dataset = read.transactions('Market_Basket_Optimisation.csv', sep = ',', rm.duplicates = TRUE) 8 | summary(dataset) 9 | itemFrequencyPlot(dataset, topN = 10) 10 | 11 | # Training Eclat on the dataset 12 | rules = eclat(data = dataset, parameter = list(support = 0.003, minlen = 2)) 13 | 14 | # Visualising the results 15 | inspect(sort(rules, by = 'support')[1:10]) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Q-learning/q_learning.py: -------------------------------------------------------------------------------- 1 | 2 | import gym 3 | import random 4 | 5 | random.seed(1234) 6 | 7 | streets = gym.make("Taxi-v3").env 8 | streets.render() 9 | 10 | initial_state = streets.encode(2, 3, 2, 0) 11 | 12 | streets.s = initial_state 13 | 14 | streets.render() 15 | 16 | streets.P[initial_state] 17 | 18 | import numpy as np 19 | 20 | q_table = np.zeros([streets.observation_space.n, streets.action_space.n]) 21 | 22 | learning_rate = 0.1 23 | discount_factor = 0.6 24 | exploration = 0.1 25 | epochs = 10000 26 | 27 | for taxi_run in range(epochs): 28 | state = streets.reset() 29 | done = False 30 | 31 | while not done: 32 | random_value = random.uniform(0, 1) 33 | if (random_value < exploration): 34 | action = streets.action_space.sample() # Explore a random action 35 | else: 36 | action = np.argmax(q_table[state]) # Use the action with the highest q-value 37 | 38 | next_state, reward, done, info = streets.step(action) 39 | 40 | prev_q = q_table[state, action] 41 | next_max_q = np.max(q_table[next_state]) 42 | new_q = (1 - learning_rate) * prev_q + learning_rate * (reward + discount_factor * next_max_q) 43 | q_table[state, action] = new_q 44 | 45 | state = next_state 46 | 47 | q_table[initial_state] 48 | 49 | from IPython.display import clear_output 50 | from time import sleep 51 | 52 | for tripnum in range(1, 11): 53 | state = streets.reset() 54 | 55 | done = False 56 | trip_length = 0 57 | 58 | while not done and trip_length < 25: 59 | action = np.argmax(q_table[state]) 60 | next_state, reward, done, info = streets.step(action) 61 | clear_output(wait=True) 62 | print("Trip number " + str(tripnum) + " Step " + str(trip_length)) 63 | print(streets.render(mode='ansi')) 64 | sleep(.5) 65 | state = next_state 66 | trip_length += 1 67 | 68 | sleep(2) 69 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/UCB_Algorithm_Slide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/UCB_Algorithm_Slide.png -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/random_selection.R: -------------------------------------------------------------------------------- 1 | # Random Selection 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Ads_CTR_Optimisation.csv') 5 | 6 | # Implementing Random Selection 7 | N = 10000 8 | d = 10 9 | ads_selected = integer(0) 10 | total_reward = 0 11 | for (n in 1:N) { 12 | ad = sample(1:10, 1) 13 | ads_selected = append(ads_selected, ad) 14 | reward = dataset[n, ad] 15 | total_reward = total_reward + reward 16 | } 17 | 18 | # Visualising the results 19 | hist(ads_selected, 20 | col = 'blue', 21 | main = 'Histogram of ads selections', 22 | xlab = 'Ads', 23 | ylab = 'Number of times each ad was selected') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/random_selection.py: -------------------------------------------------------------------------------- 1 | # Random Selection 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('Ads_CTR_Optimisation.csv') 10 | 11 | # Implementing Random Selection 12 | import random 13 | N = 10000 14 | d = 10 15 | ads_selected = [] 16 | total_reward = 0 17 | for n in range(0, N): 18 | ad = random.randrange(d) 19 | ads_selected.append(ad) 20 | reward = dataset.values[n, ad] 21 | total_reward = total_reward + reward 22 | 23 | # Visualising the results 24 | plt.hist(ads_selected) 25 | plt.title('Histogram of ads selections') 26 | plt.xlabel('Ads') 27 | plt.ylabel('Number of times each ad was selected') 28 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/upper_confidence_bound.R: -------------------------------------------------------------------------------- 1 | # Upper Confidence Bound 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Ads_CTR_Optimisation.csv') 5 | 6 | # Implementing UCB 7 | N = 10000 8 | d = 10 9 | ads_selected = integer(0) 10 | numbers_of_selections = integer(d) 11 | sums_of_rewards = integer(d) 12 | total_reward = 0 13 | for (n in 1:N) { 14 | ad = 0 15 | max_upper_bound = 0 16 | for (i in 1:d) { 17 | if (numbers_of_selections[i] > 0) { 18 | average_reward = sums_of_rewards[i] / numbers_of_selections[i] 19 | delta_i = sqrt(3/2 * log(n) / numbers_of_selections[i]) 20 | upper_bound = average_reward + delta_i 21 | } else { 22 | upper_bound = 1e400 23 | } 24 | if (upper_bound > max_upper_bound) { 25 | max_upper_bound = upper_bound 26 | ad = i 27 | } 28 | } 29 | ads_selected = append(ads_selected, ad) 30 | numbers_of_selections[ad] = numbers_of_selections[ad] + 1 31 | reward = dataset[n, ad] 32 | sums_of_rewards[ad] = sums_of_rewards[ad] + reward 33 | total_reward = total_reward + reward 34 | } 35 | 36 | # Visualising the results 37 | hist(ads_selected, 38 | col = 'blue', 39 | main = 'Histogram of ads selections', 40 | xlab = 'Ads', 41 | ylab = 'Number of times each ad was selected') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 32 - Upper Confidence Bound (UCB)/upper_confidence_bound.py: -------------------------------------------------------------------------------- 1 | # Upper Confidence Bound 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('Ads_CTR_Optimisation.csv') 10 | 11 | # Implementing UCB 12 | import math 13 | N = 10000 14 | d = 10 15 | ads_selected = [] 16 | numbers_of_selections = [0] * d 17 | sums_of_rewards = [0] * d 18 | total_reward = 0 19 | for n in range(0, N): 20 | ad = 0 21 | max_upper_bound = 0 22 | for i in range(0, d): 23 | if (numbers_of_selections[i] > 0): 24 | average_reward = sums_of_rewards[i] / numbers_of_selections[i] 25 | delta_i = math.sqrt(3/2 * math.log(n + 1) / numbers_of_selections[i]) 26 | upper_bound = average_reward + delta_i 27 | else: 28 | upper_bound = 1e400 29 | if upper_bound > max_upper_bound: 30 | max_upper_bound = upper_bound 31 | ad = i 32 | ads_selected.append(ad) 33 | numbers_of_selections[ad] = numbers_of_selections[ad] + 1 34 | reward = dataset.values[n, ad] 35 | sums_of_rewards[ad] = sums_of_rewards[ad] + reward 36 | total_reward = total_reward + reward 37 | 38 | # Visualising the results 39 | plt.hist(ads_selected) 40 | plt.title('Histogram of ads selections') 41 | plt.xlabel('Ads') 42 | plt.ylabel('Number of times each ad was selected') 43 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/Thompson_Sampling_Slide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/Thompson_Sampling_Slide.png -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/random_selection.R: -------------------------------------------------------------------------------- 1 | # Random Selection 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Ads_CTR_Optimisation.csv') 5 | 6 | # Implementing Random Selection 7 | N = 10000 8 | d = 10 9 | ads_selected = integer(0) 10 | total_reward = 0 11 | for (n in 1:N) { 12 | ad = sample(1:10, 1) 13 | ads_selected = append(ads_selected, ad) 14 | reward = dataset[n, ad] 15 | total_reward = total_reward + reward 16 | } 17 | 18 | # Visualising the results 19 | hist(ads_selected, 20 | col = 'blue', 21 | main = 'Histogram of ads selections', 22 | xlab = 'Ads', 23 | ylab = 'Number of times each ad was selected') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/random_selection.py: -------------------------------------------------------------------------------- 1 | # Random Selection 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('Ads_CTR_Optimisation.csv') 10 | 11 | # Implementing Random Selection 12 | import random 13 | N = 10000 14 | d = 10 15 | ads_selected = [] 16 | total_reward = 0 17 | for n in range(0, N): 18 | ad = random.randrange(d) 19 | ads_selected.append(ad) 20 | reward = dataset.values[n, ad] 21 | total_reward = total_reward + reward 22 | 23 | # Visualising the results 24 | plt.hist(ads_selected) 25 | plt.title('Histogram of ads selections') 26 | plt.xlabel('Ads') 27 | plt.ylabel('Number of times each ad was selected') 28 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/thompson_sampling.R: -------------------------------------------------------------------------------- 1 | # Thompson Sampling 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Ads_CTR_Optimisation.csv') 5 | 6 | # Implementing Thompson Sampling 7 | N = 10000 8 | d = 10 9 | ads_selected = integer(0) 10 | numbers_of_rewards_1 = integer(d) 11 | numbers_of_rewards_0 = integer(d) 12 | total_reward = 0 13 | for (n in 1:N) { 14 | ad = 0 15 | max_random = 0 16 | for (i in 1:d) { 17 | random_beta = rbeta(n = 1, 18 | shape1 = numbers_of_rewards_1[i] + 1, 19 | shape2 = numbers_of_rewards_0[i] + 1) 20 | if (random_beta > max_random) { 21 | max_random = random_beta 22 | ad = i 23 | } 24 | } 25 | ads_selected = append(ads_selected, ad) 26 | reward = dataset[n, ad] 27 | if (reward == 1) { 28 | numbers_of_rewards_1[ad] = numbers_of_rewards_1[ad] + 1 29 | } else { 30 | numbers_of_rewards_0[ad] = numbers_of_rewards_0[ad] + 1 31 | } 32 | total_reward = total_reward + reward 33 | } 34 | 35 | # Visualising the results 36 | hist(ads_selected, 37 | col = 'blue', 38 | main = 'Histogram of ads selections', 39 | xlab = 'Ads', 40 | ylab = 'Number of times each ad was selected') -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/Section 33 - Thompson Sampling/thompson_sampling.py: -------------------------------------------------------------------------------- 1 | # Thompson Sampling 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('Ads_CTR_Optimisation.csv') 10 | 11 | # Implementing Thompson Sampling 12 | import random 13 | N = 10000 14 | d = 10 15 | ads_selected = [] 16 | numbers_of_rewards_1 = [0] * d 17 | numbers_of_rewards_0 = [0] * d 18 | total_reward = 0 19 | for n in range(0, N): 20 | ad = 0 21 | max_random = 0 22 | for i in range(0, d): 23 | random_beta = random.betavariate(numbers_of_rewards_1[i] + 1, numbers_of_rewards_0[i] + 1) 24 | if random_beta > max_random: 25 | max_random = random_beta 26 | ad = i 27 | ads_selected.append(ad) 28 | reward = dataset.values[n, ad] 29 | if reward == 1: 30 | numbers_of_rewards_1[ad] = numbers_of_rewards_1[ad] + 1 31 | else: 32 | numbers_of_rewards_0[ad] = numbers_of_rewards_0[ad] + 1 33 | total_reward = total_reward + reward 34 | 35 | # Visualising the results - Histogram 36 | plt.hist(ads_selected) 37 | plt.title('Histogram of ads selections') 38 | plt.xlabel('Ads') 39 | plt.ylabel('Number of times each ad was selected') 40 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 6 - Reinforcement Learning/notes-1.txt: -------------------------------------------------------------------------------- 1 | Reinforcement Learning is a branch of Machine Learning, also called Online 2 | Learning. It is used to solve interacting problems where the data observed 3 | up to time t is considered to decide which action to take at time t + 1. It 4 | is also used for Artificial Intelligence when training machines to perform tasks 5 | such as walking. Desired outcomes provide the AI with reward, undesired with 6 | punishment. Machines learn through trial and error. 7 | 8 | In this part, you will understand and learn how to implement the following 9 | Reinforcement Learning models: 10 | 11 | Upper Confidence Bound (UCB) 12 | Thompson Sampling -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/natural_language_processing.R: -------------------------------------------------------------------------------- 1 | # Natural Language Processing 2 | 3 | # Importing the dataset 4 | dataset_original = read.delim('Restaurant_Reviews.tsv', quote = '', stringsAsFactors = FALSE) 5 | 6 | # Cleaning the texts 7 | # install.packages('tm') 8 | # install.packages('SnowballC') 9 | library(tm) 10 | library(SnowballC) 11 | corpus = VCorpus(VectorSource(dataset_original$Review)) 12 | corpus = tm_map(corpus, content_transformer(tolower)) 13 | corpus = tm_map(corpus, removeNumbers) 14 | corpus = tm_map(corpus, removePunctuation) 15 | corpus = tm_map(corpus, removeWords, stopwords()) 16 | corpus = tm_map(corpus, stemDocument) 17 | corpus = tm_map(corpus, stripWhitespace) 18 | 19 | # Creating the Bag of Words model 20 | dtm = DocumentTermMatrix(corpus) 21 | dtm = removeSparseTerms(dtm, 0.999) 22 | dataset = as.data.frame(as.matrix(dtm)) 23 | dataset$Liked = dataset_original$Liked 24 | 25 | # Importing the dataset 26 | dataset = read.csv('Social_Network_Ads.csv') 27 | dataset = dataset[3:5] 28 | 29 | # Encoding the target feature as factor 30 | dataset$Liked = factor(dataset$Liked, levels = c(0, 1)) 31 | 32 | # Splitting the dataset into the Training set and Test set 33 | # install.packages('caTools') 34 | library(caTools) 35 | set.seed(123) 36 | split = sample.split(dataset$Liked, SplitRatio = 0.8) 37 | training_set = subset(dataset, split == TRUE) 38 | test_set = subset(dataset, split == FALSE) 39 | 40 | # Fitting Random Forest Classification to the Training set 41 | # install.packages('randomForest') 42 | library(randomForest) 43 | classifier = randomForest(x = training_set[-692], 44 | y = training_set$Liked, 45 | ntree = 10) 46 | 47 | # Predicting the Test set results 48 | y_pred = predict(classifier, newdata = test_set[-692]) 49 | 50 | # Making the Confusion Matrix 51 | cm = table(test_set[, 692], y_pred) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/natural_language_processing.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 texts 12 | import re 13 | import nltk 14 | nltk.download('stopwords') 15 | from nltk.corpus import stopwords 16 | from nltk.stem.porter import PorterStemmer 17 | corpus = [] 18 | for i in range(0, 1000): 19 | review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i]) 20 | review = review.lower() 21 | review = review.split() 22 | ps = PorterStemmer() 23 | review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))] 24 | review = ' '.join(review) 25 | corpus.append(review) 26 | 27 | # Creating the Bag of Words model 28 | from sklearn.feature_extraction.text import CountVectorizer 29 | cv = CountVectorizer(max_features = 1500) 30 | X = cv.fit_transform(corpus).toarray() 31 | y = dataset.iloc[:, 1].values 32 | 33 | # Splitting the dataset into the Training set and Test set 34 | from sklearn.model_selection import train_test_split 35 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0) 36 | 37 | # Fitting Naive Bayes to the Training set 38 | from sklearn.naive_bayes import GaussianNB 39 | classifier = GaussianNB() 40 | classifier.fit(X_train, y_train) 41 | 42 | # Predicting the Test set results 43 | y_pred = classifier.predict(X_test) 44 | 45 | # Making the Confusion Matrix 46 | from sklearn.metrics import confusion_matrix 47 | cm = confusion_matrix(y_test, y_pred) 48 | 49 | # naive based classifer 50 | # true positive= 55 51 | # false positive = 42 52 | # true Negative = 91 53 | # false negative = 12 54 | 55 | #Accuracy score 56 | AS=(55+91)/200 #.73 57 | 58 | #Precision 59 | P=54/(55+42) #0.57 60 | 61 | #Recall 62 | R=55/(55+12) # 0.82 63 | 64 | #F1 Score 65 | 2*P*R/(P+R) #0.67 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/natural_language_processing_Decision_Tree.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 texts 12 | import re 13 | import nltk 14 | nltk.download('stopwords') 15 | from nltk.corpus import stopwords 16 | from nltk.stem.porter import PorterStemmer 17 | corpus = [] 18 | for i in range(0, 1000): 19 | review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i]) 20 | review = review.lower() 21 | review = review.split() 22 | ps = PorterStemmer() 23 | review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))] 24 | review = ' '.join(review) 25 | corpus.append(review) 26 | 27 | # Creating the Bag of Words model 28 | from sklearn.feature_extraction.text import CountVectorizer 29 | cv = CountVectorizer(max_features = 1500) 30 | X = cv.fit_transform(corpus).toarray() 31 | y = dataset.iloc[:, 1].values 32 | 33 | # Splitting the dataset into the Training set and Test set 34 | from sklearn.model_selection import train_test_split 35 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0) 36 | 37 | # Fitting Decsion Tree Classification to the Training set 38 | from sklearn.tree import DecisionTreeClassifier 39 | classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0) 40 | classifier.fit(X_train, y_train) 41 | 42 | # Predicting the Test set results 43 | y_pred = classifier.predict(X_test) 44 | 45 | # Making the Confusion Matrix 46 | from sklearn.metrics import confusion_matrix 47 | cm = confusion_matrix(y_test, y_pred) 48 | 49 | # DEcision Tree based classifer 50 | # true positive= 74 51 | # false positive = 23 52 | # true Negative = 68 53 | # false negative = 35 54 | 55 | #Accuracy score 56 | AS=(74+68)/200 #.71 57 | 58 | #Precision 59 | P=74/(74+23) #0.76 60 | 61 | #Recall 62 | R=74/(74+35) # 0.68 63 | 64 | #F1 Score 65 | 2*P*R/(P+R) #0.718 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/natural_language_processing_Max_entropy.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 texts 12 | import re 13 | import nltk 14 | nltk.download('stopwords') 15 | from nltk.corpus import stopwords 16 | from nltk.stem.porter import PorterStemmer 17 | def word_features(word): 18 | return {'items': word} 19 | from nltk import MaxentClassifier 20 | numIterations = 100 21 | algorithm = nltk.classify.MaxentClassifier.ALGORITHMS[0] 22 | # needs data set in form of list(tuple(dict, str)) 23 | corpus = [] 24 | for i in range(0, 1000): 25 | review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i]) 26 | review = review.lower() 27 | review = review.split() 28 | ps = PorterStemmer() 29 | review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))] 30 | #review = ' '.join(review) 31 | if(dataset['Liked'][i]==0): 32 | result = "negative"; 33 | else: 34 | result = "positive" 35 | for word in review: 36 | corpus.append((word_features(word), result)) 37 | 38 | # Creating the Bag of Words model 39 | #from sklearn.feature_extraction.text import CountVectorizer 40 | #cv = CountVectorizer(max_features = 1500) 41 | #X = cv.fit_transform(corpus).toarray() 42 | #y = dataset.iloc[:, 1].values 43 | 44 | # Splitting the dataset into the Training set and Test set 45 | from sklearn.model_selection import train_test_split 46 | X_train, X_test = train_test_split(corpus, test_size = 0.20, random_state = 0) 47 | 48 | # Fitting maxentropy to the Training set 49 | classifier = nltk.MaxentClassifier.train(X_train, algorithm, max_iter=numIterations) 50 | 51 | # Predicting the Test set results 52 | y_pred = classifier.classify(word_features("first")) 53 | 54 | # Making the Confusion Matrix 55 | from sklearn.metrics import confusion_matrix 56 | cm = confusion_matrix(y_test, y_pred) 57 | print(nltk.classify.accuracy(classifier, X_test)) 58 | 59 | #Maximum Entropy 60 | 61 | #Accuracy = 0.73 62 | 63 | #Precision = 0.684 64 | 65 | #Recall = 0.883 66 | 67 | #F1 Score = 0.771 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/Section 36 - Natural Language Processing/natural_language_processing_RANDOM_FOREST.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 texts 12 | import re 13 | import nltk 14 | nltk.download('stopwords') 15 | from nltk.corpus import stopwords 16 | from nltk.stem.porter import PorterStemmer 17 | corpus = [] 18 | for i in range(0, 1000): 19 | review = re.sub('[^a-zA-Z]', ' ', dataset['Review'][i]) 20 | review = review.lower() 21 | review = review.split() 22 | ps = PorterStemmer() 23 | review = [ps.stem(word) for word in review if not word in set(stopwords.words('english'))] 24 | review = ' '.join(review) 25 | corpus.append(review) 26 | 27 | # Creating the Bag of Words model 28 | from sklearn.feature_extraction.text import CountVectorizer 29 | cv = CountVectorizer(max_features = 1500) 30 | X = cv.fit_transform(corpus).toarray() 31 | y = dataset.iloc[:, 1].values 32 | 33 | # Splitting the dataset into the Training set and Test set 34 | from sklearn.model_selection import train_test_split 35 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.20, random_state = 0) 36 | 37 | # Fitting Random Forest Classification to the Training set 38 | from sklearn.ensemble import RandomForestClassifier 39 | classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0) 40 | classifier.fit(X_train, y_train) 41 | 42 | # Predicting the Test set results 43 | y_pred = classifier.predict(X_test) 44 | 45 | # Making the Confusion Matrix 46 | from sklearn.metrics import confusion_matrix 47 | cm = confusion_matrix(y_test, y_pred) 48 | 49 | # Random forest based classifer 50 | # true positive= 87 51 | # false positive = 10 52 | # true Negative = 57 53 | # false negative = 46 54 | 55 | #Accuracy score 56 | AS=(87+57)/200 #.72 57 | 58 | #Precision 59 | P=87/(87+10) #0.90 60 | 61 | #Recall 62 | R=87/(87+46) # 0.65 63 | 64 | #F1 Score 65 | 2*P*R/(P+R) #0.75 -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 7 - Natural Language Processing/notes-1.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 7 - Natural Language Processing/notes-1.txt -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/A list of cost functions used in neural networks, alongside applications - Cross Validated.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 8 - Deep Learning/A list of cost functions used in neural networks, alongside applications - Cross Validated.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 39 - Artificial Neural Networks (ANN)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 8 - Deep Learning/Section 39 - Artificial Neural Networks (ANN)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 39 - Artificial Neural Networks (ANN)/Stochastic_Gradient_Descent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 8 - Deep Learning/Section 39 - Artificial Neural Networks (ANN)/Stochastic_Gradient_Descent.png -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 39 - Artificial Neural Networks (ANN)/ann.R: -------------------------------------------------------------------------------- 1 | # Artificial Neural Network 2 | 3 | # Importing the dataset 4 | dataset = read.csv('Churn_Modelling.csv') 5 | dataset = dataset[4:14] 6 | 7 | # Encoding the categorical variables as factors 8 | dataset$Geography = as.numeric(factor(dataset$Geography, 9 | levels = c('France', 'Spain', 'Germany'), 10 | labels = c(1, 2, 3))) 11 | dataset$Gender = as.numeric(factor(dataset$Gender, 12 | levels = c('Female', 'Male'), 13 | labels = c(1, 2))) 14 | 15 | # Splitting the dataset into the Training set and Test set 16 | # install.packages('caTools') 17 | library(caTools) 18 | set.seed(123) 19 | split = sample.split(dataset$Exited, SplitRatio = 0.8) 20 | training_set = subset(dataset, split == TRUE) 21 | test_set = subset(dataset, split == FALSE) 22 | 23 | # Feature Scaling 24 | training_set[-11] = scale(training_set[-11]) 25 | test_set[-11] = scale(test_set[-11]) 26 | 27 | # Fitting ANN to the Training set 28 | # install.packages('h2o') 29 | library(h2o) 30 | h2o.init(nthreads = -1) 31 | model = h2o.deeplearning(y = 'Exited', 32 | training_frame = as.h2o(training_set), 33 | activation = 'Rectifier', 34 | hidden = c(5,5), 35 | epochs = 100, 36 | train_samples_per_iteration = -2) 37 | 38 | # Predicting the Test set results 39 | y_pred = h2o.predict(model, newdata = as.h2o(test_set[-11])) 40 | y_pred = (y_pred > 0.5) 41 | y_pred = as.vector(y_pred) 42 | 43 | # Making the Confusion Matrix 44 | cm = table(test_set[, 11], y_pred) 45 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 39 - Artificial Neural Networks (ANN)/ann.py: -------------------------------------------------------------------------------- 1 | # Artificial Neural Network 2 | 3 | # Installing Keras 4 | # Enter the following command in a terminal (or anaconda prompt for Windows users): conda install -c conda-forge keras 5 | 6 | # Part 1 - Data Preprocessing 7 | 8 | # Importing the libraries 9 | import numpy as np 10 | import matplotlib.pyplot as plt 11 | import pandas as pd 12 | 13 | # Importing the dataset 14 | dataset = pd.read_csv('Churn_Modelling.csv') 15 | X = dataset.iloc[:, 3:13].values 16 | y = dataset.iloc[:, 13].values 17 | 18 | # Encoding categorical data 19 | from sklearn.preprocessing import LabelEncoder, OneHotEncoder 20 | labelencoder_X_1 = LabelEncoder() 21 | X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) 22 | labelencoder_X_2 = LabelEncoder() 23 | X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2]) 24 | onehotencoder = OneHotEncoder(categorical_features = [1]) 25 | X = onehotencoder.fit_transform(X).toarray() 26 | X = X[:, 1:] 27 | 28 | # Splitting the dataset into the Training set and Test set 29 | from sklearn.model_selection import train_test_split 30 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0) 31 | 32 | # Feature Scaling 33 | from sklearn.preprocessing import StandardScaler 34 | sc = StandardScaler() 35 | X_train = sc.fit_transform(X_train) 36 | X_test = sc.transform(X_test) 37 | 38 | # Part 2 - Now let's make the ANN! 39 | 40 | # Importing the Keras libraries and packages 41 | import keras 42 | from keras.models import Sequential 43 | from keras.layers import Dense 44 | 45 | # Initialising the ANN 46 | classifier = Sequential() 47 | 48 | # Adding the input layer and the first hidden layer 49 | classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu', input_dim = 11)) 50 | 51 | # Adding the second hidden layer 52 | classifier.add(Dense(units = 6, kernel_initializer = 'uniform', activation = 'relu')) 53 | 54 | # Adding the output layer 55 | classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) 56 | 57 | # Compiling the ANN 58 | classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) 59 | 60 | # Fitting the ANN to the Training set 61 | classifier.fit(X_train, y_train, batch_size = 10, epochs = 100) 62 | 63 | # Part 3 - Making the predictions and evaluating the model 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) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 40 - Convolutional Neural Networks (CNN)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 8 - Deep Learning/Section 40 - Convolutional Neural Networks (CNN)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 40 - Convolutional Neural Networks (CNN)/.gitignore: -------------------------------------------------------------------------------- 1 | ml-100k 2 | dataset -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 40 - Convolutional Neural Networks (CNN)/cnn.py: -------------------------------------------------------------------------------- 1 | # Convolutional Neural Network 2 | 3 | # Installing Keras 4 | # Enter the following command in a terminal (or anaconda prompt for Windows users): conda install -c conda-forge keras 5 | 6 | # Part 1 - Building the CNN 7 | 8 | # Importing the Keras libraries and packages 9 | from keras.models import Sequential 10 | from keras.layers import Conv2D 11 | from keras.layers import MaxPooling2D 12 | from keras.layers import Flatten 13 | from keras.layers import Dense 14 | 15 | # Initialising the CNN 16 | classifier = Sequential() 17 | 18 | # Step 1 - Convolution 19 | classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu')) 20 | 21 | # Step 2 - Pooling 22 | classifier.add(MaxPooling2D(pool_size = (2, 2))) 23 | 24 | # Adding a second convolutional layer 25 | classifier.add(Conv2D(32, (3, 3), activation = 'relu')) 26 | classifier.add(MaxPooling2D(pool_size = (2, 2))) 27 | 28 | # Step 3 - Flattening 29 | classifier.add(Flatten()) 30 | 31 | # Step 4 - Full connection 32 | classifier.add(Dense(units = 128, activation = 'relu')) 33 | classifier.add(Dense(units = 1, activation = 'sigmoid')) 34 | 35 | # Compiling the CNN 36 | classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) 37 | 38 | # Part 2 - Fitting the CNN to the images 39 | 40 | from keras.preprocessing.image import ImageDataGenerator 41 | 42 | train_datagen = ImageDataGenerator(rescale = 1./255, 43 | shear_range = 0.2, 44 | zoom_range = 0.2, 45 | horizontal_flip = True) 46 | 47 | test_datagen = ImageDataGenerator(rescale = 1./255) 48 | 49 | training_set = train_datagen.flow_from_directory('dataset/training_set', 50 | target_size = (64, 64), 51 | batch_size = 32, 52 | class_mode = 'binary') 53 | 54 | test_set = test_datagen.flow_from_directory('dataset/test_set', 55 | target_size = (64, 64), 56 | batch_size = 32, 57 | class_mode = 'binary') 58 | 59 | classifier.fit_generator(training_set, 60 | steps_per_epoch = 8000, 61 | epochs = 5, 62 | validation_data = test_set, 63 | validation_steps = 2000) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/Section 41 - Recurrent Neural Network (RNN)/keras_RNN.py: -------------------------------------------------------------------------------- 1 | from tensorflow.keras.preprocessing import sequence 2 | from tensorflow.keras.models import Sequential 3 | from tensorflow.keras.layers import Dense, Embedding 4 | from tensorflow.keras.layers import LSTM 5 | from tensorflow.keras.datasets import imdb 6 | 7 | print('Loading data...') 8 | (x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=20000) 9 | 10 | x_train[0] 11 | y_train[0] 12 | 13 | x_train = sequence.pad_sequences(x_train, maxlen=80) 14 | x_test = sequence.pad_sequences(x_test, maxlen=80) 15 | 16 | model = Sequential() 17 | model.add(Embedding(20000, 128)) 18 | model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2)) 19 | model.add(Dense(1, activation='sigmoid')) 20 | 21 | model.compile(loss='binary_crossentropy', 22 | optimizer='adam', 23 | metrics=['accuracy']) 24 | 25 | """This will take a very long time to 26 | run, even on a fast PC! Don't execute 27 | the next blocks unless you're prepared 28 | to tie up your computer for an hour or more.""" 29 | 30 | model.fit(x_train, y_train, 31 | batch_size=32, 32 | epochs=15, 33 | verbose=2, 34 | validation_data=(x_test, y_test)) 35 | 36 | score, acc = model.evaluate(x_test, y_test, 37 | batch_size=32, 38 | verbose=2) 39 | print('Test score:', score) 40 | print('Test accuracy:', acc) -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/neural networks and deep learning.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 8 - Deep Learning/neural networks and deep learning.pdf -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 8 - Deep Learning/notes-1.txt: -------------------------------------------------------------------------------- 1 | Deep Learning is the most exciting and powerful branch of Machine Learning. 2 | Deep Learning models can be used for a variety of complex tasks: 3 | 4 | Artificial Neural Networks for Regression and Classification 5 | Convolutional Neural Networks for Computer Vision 6 | Recurrent Neural Networks for Time Series Analysis 7 | Self Organizing Maps for Feature Extraction 8 | Deep Boltzmann Machines for Recommendation Systems 9 | Auto Encoders for Recommendation Systems 10 | In this part, you will understand and learn how to implement the' 11 | following Deep Learning models: 12 | 13 | Artificial Neural Networks for a Business Problem 14 | Convolutional Neural Networks for a Computer Vision task -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 9 - Dimensionality Reduction/Section 43 - Principal Component Analysis (PCA)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 9 - Dimensionality Reduction/Section 43 - Principal Component Analysis (PCA)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 9 - Dimensionality Reduction/Section 44 - Linear Discriminant Analysis (LDA)/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 9 - Dimensionality Reduction/Section 44 - Linear Discriminant Analysis (LDA)/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 9 - Dimensionality Reduction/Section 45 - Kernel PCA/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/Part 9 - Dimensionality Reduction/Section 45 - Kernel PCA/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/Part 9 - Dimensionality Reduction/notes-1.txt: -------------------------------------------------------------------------------- 1 | Remember in Part 3 - Classification, we worked with datasets composed of 2 | only two independent variables. We did for two reasons: 3 | 4 | Because we needed two dimensions to visualize better how Machine Learning 5 | models worked (by plotting the prediction regions and the prediction boundary 6 | for each model). 7 | Because whatever is the original number of our independent variables, we can 8 | often end up with two independent variables by applying an appropriate 9 | Dimensionality Reduction technique. 10 | 11 | 12 | There are two types of Dimensionality Reduction techniques: 13 | 14 | Feature Selection 15 | Feature Extraction 16 | 17 | 18 | Feature Selection techniques are Backward Elimination, Forward Selection, 19 | Bidirectional Elimination, Score Comparison and more. We covered these 20 | techniques in Part 2 - Regression. 21 | 22 | In this part we will cover the following Feature Extraction techniques: 23 | 24 | Principal Component Analysis (PCA) 25 | Linear Discriminant Analysis (LDA) 26 | Kernel PCA 27 | Quadratic Discriminant Analysis (QDA) 28 | -------------------------------------------------------------------------------- /Machine Learning A-Z/Recommender System/.gitignore: -------------------------------------------------------------------------------- 1 | ml-100k -------------------------------------------------------------------------------- /Machine Learning A-Z/Recommender System/item_based_collabrative_filtering.py: -------------------------------------------------------------------------------- 1 | 2 | import pandas as pd 3 | 4 | r_cols = ['user_id', 'movie_id', 'rating'] 5 | ratings = pd.read_csv('ml-100k/u.data', sep='\t', names=r_cols, usecols=range(3), encoding="ISO-8859-1") 6 | 7 | m_cols = ['movie_id', 'title'] 8 | movies = pd.read_csv('ml-100k/u.item', sep='|', names=m_cols, usecols=range(2), encoding="ISO-8859-1") 9 | 10 | ratings = pd.merge(movies, ratings) 11 | 12 | ratings.head() 13 | 14 | userRatings = ratings.pivot_table(index=['user_id'],columns=['title'],values='rating') 15 | userRatings.head() 16 | 17 | corrMatrix = userRatings.corr() 18 | corrMatrix.head() 19 | 20 | corrMatrix = userRatings.corr(method='pearson', min_periods=100) 21 | corrMatrix.head() 22 | 23 | myRatings = userRatings.loc[0].dropna() 24 | myRatings 25 | 26 | simCandidates = pd.Series() 27 | for i in range(0, len(myRatings.index)): 28 | print ("Adding sims for " + myRatings.index[i] + "...") 29 | # Retrieve similar movies to this one that I rated 30 | sims = corrMatrix[myRatings.index[i]].dropna() 31 | # Now scale its similarity by how well I rated this movie 32 | sims = sims.map(lambda x: x * myRatings[i]) 33 | # Add the score to the list of similarity candidates 34 | simCandidates = simCandidates.append(sims) 35 | 36 | #Glance at our results so far: 37 | print ("sorting...") 38 | simCandidates.sort_values(inplace = True, ascending = False) 39 | print (simCandidates.head(10)) 40 | 41 | simCandidates = simCandidates.groupby(simCandidates.index).sum() 42 | simCandidates.sort_values(inplace = True, ascending = False) 43 | simCandidates.head(10) 44 | 45 | filteredSims = simCandidates.drop(myRatings.index) 46 | filteredSims.head(10) -------------------------------------------------------------------------------- /Machine Learning A-Z/Recommender System/similarmovies.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | r_cols = ['user_id', 'movie_id', 'rating'] 4 | ratings = pd.read_csv('ml-100k/u.data', sep='\t', names=r_cols, usecols=range(3), encoding="ISO-8859-1") 5 | 6 | m_cols = ['movie_id', 'title'] 7 | movies = pd.read_csv('ml-100k/u.item', sep='|', names=m_cols, usecols=range(2), encoding="ISO-8859-1") 8 | 9 | ratings = pd.merge(movies, ratings) 10 | ratings.head() 11 | 12 | movieRatings = ratings.pivot_table(index=['user_id'],columns=['title'],values='rating') 13 | movieRatings.head() 14 | 15 | starWarsRatings = movieRatings['Star Wars (1977)'] 16 | starWarsRatings.head() 17 | 18 | similarMovies = movieRatings.corrwith(starWarsRatings) 19 | similarMovies = similarMovies.dropna() 20 | df = pd.DataFrame(similarMovies) 21 | df.head(10) 22 | 23 | similarMovies.sort_values(ascending=False) 24 | 25 | import numpy as np 26 | movieStats = ratings.groupby('title').agg({'rating': [np.size, np.mean]}) 27 | movieStats.head() 28 | 29 | popularMovies = movieStats['rating']['size'] >= 100 30 | movieStats[popularMovies].sort_values([('rating', 'mean')], ascending=False)[:15] 31 | 32 | df = movieStats[popularMovies].join(pd.DataFrame(similarMovies, columns=['similarity'])) 33 | df.head() 34 | 35 | df.sort_values(['similarity'], ascending=False)[:15] -------------------------------------------------------------------------------- /Machine Learning A-Z/Tensorflow/Keras.py: -------------------------------------------------------------------------------- 1 | from tensorflow import keras 2 | from tensorflow.keras.datasets import mnist 3 | from tensorflow.keras.models import Sequential 4 | from tensorflow.keras.layers import Dense, Dropout 5 | from tensorflow.keras.optimizers import RMSprop 6 | 7 | (mnist_train_images, mnist_train_labels), (mnist_test_images, mnist_test_labels) = mnist.load_data() 8 | 9 | train_images = mnist_train_images.reshape(60000, 784) 10 | test_images = mnist_test_images.reshape(10000, 784) 11 | train_images = train_images.astype('float32') 12 | test_images = test_images.astype('float32') 13 | train_images /= 255 14 | test_images /= 255 15 | 16 | train_labels = keras.utils.to_categorical(mnist_train_labels, 10) 17 | test_labels = keras.utils.to_categorical(mnist_test_labels, 10) 18 | 19 | import matplotlib.pyplot as plt 20 | 21 | def display_sample(num): 22 | #Print the one-hot array of this sample's label 23 | print(train_labels[num]) 24 | #Print the label converted back to a number 25 | label = train_labels[num].argmax(axis=0) 26 | #Reshape the 768 values to a 28x28 image 27 | image = train_images[num].reshape([28,28]) 28 | plt.title('Sample: %d Label: %d' % (num, label)) 29 | plt.imshow(image, cmap=plt.get_cmap('gray_r')) 30 | plt.show() 31 | 32 | display_sample(1000) 33 | 34 | model = Sequential() 35 | model.add(Dense(512, activation='relu', input_shape=(784,))) 36 | model.add(Dense(10, activation='softmax')) 37 | model.summary() 38 | 39 | model.compile(loss='categorical_crossentropy', 40 | optimizer=RMSprop(), 41 | metrics=['accuracy']) 42 | 43 | history = model.fit(train_images, train_labels, 44 | batch_size=100, 45 | epochs=10, 46 | verbose=2, 47 | validation_data=(test_images, test_labels)) 48 | 49 | """But, even with just 10 epochs, we've outperformed our Tensorflow version considerably!""" 50 | 51 | score = model.evaluate(test_images, test_labels, verbose=0) 52 | print('Test loss:', score[0]) 53 | print('Test accuracy:', score[1]) 54 | 55 | for x in range(1000): 56 | test_image = test_images[x,:].reshape(1,784) 57 | predicted_cat = model.predict(test_image).argmax() 58 | label = test_labels[x].argmax() 59 | if (predicted_cat != label): 60 | plt.title('Prediction: %d Label: %d' % (predicted_cat, label)) 61 | plt.imshow(test_image.reshape([28,28]), cmap=plt.get_cmap('gray_r')) 62 | plt.show() -------------------------------------------------------------------------------- /Machine Learning A-Z/Tensorflow/keras_RNN.py: -------------------------------------------------------------------------------- 1 | from tensorflow.keras.preprocessing import sequence 2 | from tensorflow.keras.models import Sequential 3 | from tensorflow.keras.layers import Dense, Embedding 4 | from tensorflow.keras.layers import LSTM 5 | from tensorflow.keras.datasets import imdb 6 | 7 | print('Loading data...') 8 | (x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=20000) 9 | 10 | x_train[0] 11 | y_train[0] 12 | 13 | x_train = sequence.pad_sequences(x_train, maxlen=80) 14 | x_test = sequence.pad_sequences(x_test, maxlen=80) 15 | 16 | model = Sequential() 17 | model.add(Embedding(20000, 128)) 18 | model.add(LSTM(128, dropout=0.2, recurrent_dropout=0.2)) 19 | model.add(Dense(1, activation='sigmoid')) 20 | 21 | model.compile(loss='binary_crossentropy', 22 | optimizer='adam', 23 | metrics=['accuracy']) 24 | 25 | """This will take a very long time to 26 | run, even on a fast PC! Don't execute 27 | the next blocks unless you're prepared 28 | to tie up your computer for an hour or more.""" 29 | 30 | model.fit(x_train, y_train, 31 | batch_size=32, 32 | epochs=15, 33 | verbose=2, 34 | validation_data=(x_test, y_test)) 35 | 36 | score, acc = model.evaluate(x_test, y_test, 37 | batch_size=32, 38 | verbose=2) 39 | print('Test score:', score) 40 | print('Test accuracy:', acc) -------------------------------------------------------------------------------- /Machine Learning A-Z/Tensorflow/predict_political_party.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | feature_names = ['party','handicapped-infants', 'water-project-cost-sharing', 4 | 'adoption-of-the-budget-resolution', 'physician-fee-freeze', 5 | 'el-salvador-aid', 'religious-groups-in-schools', 6 | 'anti-satellite-test-ban', 'aid-to-nicaraguan-contras', 7 | 'mx-missle', 'immigration', 'synfuels-corporation-cutback', 8 | 'education-spending', 'superfund-right-to-sue', 'crime', 9 | 'duty-free-exports', 'export-administration-act-south-africa'] 10 | 11 | voting_data = pd.read_csv('house-votes-84.data.txt', na_values=['?'], 12 | names = feature_names) 13 | voting_data.head() 14 | voting_data.describe() 15 | voting_data.dropna(inplace=True) 16 | voting_data.describe() 17 | voting_data.replace(('y', 'n'), (1, 0), inplace=True) 18 | voting_data.replace(('democrat', 'republican'), (1, 0), inplace=True) 19 | voting_data.head() 20 | all_features = voting_data[feature_names].drop('party', axis=1).values 21 | all_classes = voting_data['party'].values 22 | 23 | 24 | from tensorflow.keras.layers import Dense, Dropout 25 | from tensorflow.keras.models import Sequential 26 | from sklearn.model_selection import cross_val_score 27 | 28 | def create_model(): 29 | model = Sequential() 30 | #16 feature inputs (votes) going into an 32-unit layer 31 | model.add(Dense(32, input_dim=16, kernel_initializer='normal', activation='relu')) 32 | # Another hidden layer of 16 units 33 | model.add(Dense(16, kernel_initializer='normal', activation='relu')) 34 | # Output layer with a binary classification (Democrat or Republican political party) 35 | model.add(Dense(1, kernel_initializer='normal', activation='sigmoid')) 36 | # Compile model 37 | model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) 38 | return model 39 | 40 | from tensorflow.keras.wrappers.scikit_learn import KerasClassifier 41 | 42 | # Wrap our Keras model in an estimator compatible with scikit_learn 43 | estimator = KerasClassifier(build_fn=create_model, epochs=100, verbose=0) 44 | # Now we can use scikit_learn's cross_val_score to evaluate this model identically to the others 45 | cv_scores = cross_val_score(estimator, all_features, all_classes, cv=10) 46 | cv_scores.mean() -------------------------------------------------------------------------------- /Machine Learning A-Z/Tensorflow/simplest_code_TENSORFLOW.py: -------------------------------------------------------------------------------- 1 | #SIMPLEST TENSORFLOW CODE 2 | import tensorflow as tf 3 | 4 | a = tf.Variable(1, name="a") 5 | b = tf.Variable(2, name="b") 6 | f = a + b 7 | 8 | tf.print("The sum of a and b is", f) -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/0.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/1.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/10.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/11.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/12.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/13.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/14.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/15.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/16.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/17.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/18.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/19.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/2.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/21.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/22.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/23.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/24.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/25.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/26.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/27.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/28.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/29.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/3.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/30.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/31.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/32.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/33.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/34.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/35.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/36.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/37.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/38.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/4.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/40.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/41.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/42.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/43.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/44.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/45.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/46.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/47.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/48.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/49.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/5.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/6.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/7.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/8.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/examples/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/examples/9.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/fire_detection.model/.gitignore: -------------------------------------------------------------------------------- 1 | ml-100k 2 | variables -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/fire_detection.model/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/fire_detection.model/saved_model.pb -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/lrfind_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/lrfind_plot.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/output/training_plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/output/training_plot.png -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/predict_fire.py: -------------------------------------------------------------------------------- 1 | # USAGE 2 | # python predict_fire.py 3 | 4 | # import the necessary packages 5 | from tensorflow.keras.models import load_model 6 | from pyimagesearch import config 7 | from imutils import paths 8 | import numpy as np 9 | import imutils 10 | import random 11 | import cv2 12 | import os 13 | 14 | # load the trained model from disk 15 | print("[INFO] loading model...") 16 | model = load_model(config.MODEL_PATH) 17 | 18 | # grab the paths to the fire and non-fire images, respectively 19 | print("[INFO] predicting...") 20 | firePaths = list(paths.list_images(config.FIRE_PATH)) 21 | nonFirePaths = list(paths.list_images(config.NON_FIRE_PATH)) 22 | 23 | # combine the two image path lists, randomly shuffle them, and sample 24 | # them 25 | imagePaths = firePaths + nonFirePaths 26 | random.shuffle(imagePaths) 27 | imagePaths = imagePaths[:config.SAMPLE_SIZE] 28 | 29 | # loop over the sampled image paths 30 | for (i, imagePath) in enumerate(imagePaths): 31 | # load the image and clone it 32 | image = cv2.imread(imagePath) 33 | output = image.copy() 34 | 35 | # resize the input image to be a fixed 128x128 pixels, ignoring 36 | # aspect ratio 37 | image = cv2.resize(image, (128, 128)) 38 | image = image.astype("float32") / 255.0 39 | 40 | # make predictions on the image 41 | preds = model.predict(np.expand_dims(image, axis=0))[0] 42 | j = np.argmax(preds) 43 | label = config.CLASSES[j] 44 | 45 | # draw the activity on the output frame 46 | text = label if label == "Non-Fire" else "WARNING! Fire!" 47 | output = imutils.resize(output, width=500) 48 | cv2.putText(output, text, (35, 50), cv2.FONT_HERSHEY_SIMPLEX, 49 | 1.25, (0, 255, 0), 5) 50 | 51 | # write the output image to disk 52 | filename = "{}.png".format(i) 53 | p = os.path.sep.join([config.OUTPUT_IMAGE_PATH, filename]) 54 | cv2.imwrite(p, output) -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/pyimagesearch/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/pyimagesearch/.DS_Store -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/pyimagesearch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine Learning A-Z/keras-fire-detection/pyimagesearch/__init__.py -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/pyimagesearch/config.py: -------------------------------------------------------------------------------- 1 | # import the necessary packages 2 | import os 3 | 4 | # initialize the path to the fire and non-fire dataset directories 5 | FIRE_PATH = os.path.sep.join(["Robbery_Accident_Fire_Database2", 6 | "Fire"]) 7 | NON_FIRE_PATH = "spatial_envelope_256x256_static_8outdoorcategories" 8 | 9 | # initialize the class labels in the dataset 10 | CLASSES = ["Non-Fire", "Fire"] 11 | 12 | # define the size of the training and testing split 13 | TRAIN_SPLIT = 0.75 14 | TEST_SPLIT = 0.25 15 | 16 | # define the initial learning rate, batch size, and number of epochs 17 | INIT_LR = 1e-2 18 | BATCH_SIZE = 64 19 | NUM_EPOCHS = 50 20 | 21 | # set the path to the serialized model after training 22 | MODEL_PATH = os.path.sep.join(["output", "fire_detection.model"]) 23 | 24 | # define the path to the output learning rate finder plot and 25 | # training history plot 26 | LRFIND_PLOT_PATH = os.path.sep.join(["output", "lrfind_plot.png"]) 27 | TRAINING_PLOT_PATH = os.path.sep.join(["output", "training_plot.png"]) 28 | 29 | # define the path to the output directory that will store our final 30 | # output with labels/annotations along with the number of iamges to 31 | # sample 32 | OUTPUT_IMAGE_PATH = os.path.sep.join(["output", "examples"]) 33 | SAMPLE_SIZE = 50 -------------------------------------------------------------------------------- /Machine Learning A-Z/keras-fire-detection/pyimagesearch/firedetectionnet.py: -------------------------------------------------------------------------------- 1 | # import the necessary packages 2 | from tensorflow.keras.models import Sequential 3 | from tensorflow.keras.layers import BatchNormalization 4 | from tensorflow.keras.layers import SeparableConv2D 5 | from tensorflow.keras.layers import MaxPooling2D 6 | from tensorflow.keras.layers import Activation 7 | from tensorflow.keras.layers import Flatten 8 | from tensorflow.keras.layers import Dropout 9 | from tensorflow.keras.layers import Dense 10 | 11 | class FireDetectionNet: 12 | @staticmethod 13 | def build(width, height, depth, classes): 14 | # initialize the model along with the input shape to be 15 | # "channels last" and the channels dimension itself 16 | model = Sequential() 17 | inputShape = (height, width, depth) 18 | chanDim = -1 19 | 20 | # CONV => RELU => POOL 21 | model.add(SeparableConv2D(16, (7, 7), padding="same", 22 | input_shape=inputShape)) 23 | model.add(Activation("relu")) 24 | model.add(BatchNormalization(axis=chanDim)) 25 | model.add(MaxPooling2D(pool_size=(2, 2))) 26 | 27 | # CONV => RELU => POOL 28 | model.add(SeparableConv2D(32, (3, 3), padding="same")) 29 | model.add(Activation("relu")) 30 | model.add(BatchNormalization(axis=chanDim)) 31 | model.add(MaxPooling2D(pool_size=(2, 2))) 32 | 33 | # (CONV => RELU) * 2 => POOL 34 | model.add(SeparableConv2D(64, (3, 3), padding="same")) 35 | model.add(Activation("relu")) 36 | model.add(BatchNormalization(axis=chanDim)) 37 | model.add(SeparableConv2D(64, (3, 3), padding="same")) 38 | model.add(Activation("relu")) 39 | model.add(BatchNormalization(axis=chanDim)) 40 | model.add(MaxPooling2D(pool_size=(2, 2))) 41 | 42 | # first set of FC => RELU layers 43 | model.add(Flatten()) 44 | model.add(Dense(128)) 45 | model.add(Activation("relu")) 46 | model.add(BatchNormalization()) 47 | model.add(Dropout(0.5)) 48 | 49 | # second set of FC => RELU layers 50 | model.add(Dense(128)) 51 | model.add(Activation("relu")) 52 | model.add(BatchNormalization()) 53 | model.add(Dropout(0.5)) 54 | 55 | # softmax classifier 56 | model.add(Dense(classes)) 57 | model.add(Activation("softmax")) 58 | 59 | # return the constructed network architecture 60 | return model -------------------------------------------------------------------------------- /Machine-Learning-A-Z-Q-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/Machine-Learning-A-Z-Q-A.pdf -------------------------------------------------------------------------------- /resource/27129696_acc1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/27129696_acc1.jpg -------------------------------------------------------------------------------- /resource/Certificate.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/Certificate.PNG -------------------------------------------------------------------------------- /resource/Description.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/Description.PNG -------------------------------------------------------------------------------- /resource/Udemy.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/Udemy.PNG -------------------------------------------------------------------------------- /resource/kiril.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/kiril.jpg -------------------------------------------------------------------------------- /resource/martin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/martin.jpg -------------------------------------------------------------------------------- /resource/ponteves.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ashleshk/Machine-Learning-A-Z-hands-on-Python-And-R-in-data-Science/d804e7eeace1e5187b156b2fa3e71125b2a3448a/resource/ponteves.jpg --------------------------------------------------------------------------------