Posts

Showing posts from December, 2018

Regression

Regression Regression methods (linear & non-linear) both are used to predict real values. Regression Methods Simple Linear Regression Multiple Linear Regression Polynomial Regression Support Vector for Regression Decision Tree Classification Random Forest Classification

Feature Scaling

Feature Scaling #Feature Scalling train_set[,2:3] = scale(train_set[,2:3]) test_set[,2:3] = scale(test_set[,2:3]) Add above code to perform Feature Scaling. Here we use [,2:3] means all row & 2nd,3rd column. Note in R index starts from 1 but in Python 0. Check our final Data_Preprocessing.R file click here.

Split Dataset into TrainSet & TestSet

Split Dataset into TrainSet & TestSet In Library menu selects caTools install that library by writing following line into R Script install.packages('caTools') only one time after comment it. Select that library Split data into TrainSet & TestSet #split data into Train Set & Text Set set.seed(123) split = sample.split( dataset$Purchased , SplitRatio = 0.8) train_set = subset( dataset , split==TRUE) test_set = subset( dataset , split==FALSE) If you write this code then it splits dataset into train_set & test_set It generates train_set & test_set  Global variable data

Categorical Data

Categorical Data Here in Data.csv, two column  are Categorical Data Country (France / Spain /Germany) Purchased (YES/NO) So we want to make categorical data. #categorical data dataset$Country = factor ( dataset$Country,                            levels = c('France','Spain','Germany'),                            labels = c(1,2,3)) dataset$Purchased =factor( dataset$Purchased ,                            levels =c('Yes','No'),                            labels = c(1,0)) Just add this line of code and run it, observe dataset variable. It assigns country column 1,2,3 to France, Spain, Germany. purchased column 1,0 to  Yes, No.

Handling the Missing values

Handling the missing values into Data.csv Write following lines of code in R Script to handle missing values. What we are doing here Just placing an average of other observation into missing values. Here in Age & Salary column, we contain null value so we want to fill it with an average of other observation. #handling missing values dataset$Age = ifelse(   is.na(dataset$Age),   ave(dataset$Age,FUN = function(x) mean (x,na.rm=TRUE)),   dataset$Age ) dataset$Salary = ifelse(   is.na(dataset$Salary),   ave(dataset$Salary,FUN = function(x) mean (x,na.rm=TRUE)),   dataset$Salary ) ifelse argument is.na(dataset$Age) gives a TRUE/FALSE value. the value if  1st argument returns TRUE, ave is used to perform average. the value if 1st argument return FALSE,dataset$Age After writing this line of code in R Script  Press alt+enter See dataset data from Global Environment. 

Import DataSet

Image
Import Dataset Set up the Current working directory Create a new File (R Script). Select the Files Menu  By clicking on to the folder reach up to our dataset folder.  As the above image, we have reached up to our dataset folder. Click on more Click on set as the working directory. 2. Import Dataset Just write the following line to import data into our R Script dataset=read.csv('Data.csv') After writing it just press alt+enter then it generates database Global Environment Data as shown in the image. Just click on dataset data to check your CSV file. Data.csv is the file name.

Download DataSet

Download DataSet Download Folder Hierarchy:  click here. This Folder Hierarchy is used in all projects. Extract Folder Hierarchy into any folder of your computer. Download Dataset of Section:2: Data preprocessing  click here Extract Dataset Zip & move it to the folder Hierarchy according to its appropriate location. Now, we are completed to download the dataset. Our Dataset contains Data.csv file. Information about the company's customer. It has 4 column Country (IV) Age (IV) Salary (IV) Purchase (DV) 10 Observation (10 row) There are two types of Variable Dependent Variable (DV) Independent Variable (Features) (IV)

Download R Studio

Download R Studio Download R Studio click here. Download R click here Install both the software  And Get start for R Studio Project

Import Library

Image
Open R Studio At the right bottom menu, there is a package menu. Click on package menu. Select the library which you want to import.