# Data Preprocessing # install.packages('arules') library(arules) dataset = read.csv('Market_Basket_Optimisation.csv', header = FALSE) #sparce matrix dataset = read.transactions('Market_Basket_Optimisation.csv', sep = ',', rm.duplicates = TRUE) distribution of transactions with duplicates: 1 5 summary(dataset) transactions as itemMatrix in sparse format with 7501 rows (elements/itemsets/transactions) and 119 columns (items) and a density of 0.03288973 most frequent items: mineral water eggs spaghetti french fries chocolate (Other) 1788 1348 1306 1282 1229 22405 element (itemset/transactio...
# Importing the dataset dataset = read.csv('Social_Network_Ads.csv') dataset = dataset[3:5] # Encoding the target feature as factor dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1)) # Splitting the dataset into the Training set and Test set # install.packages('caTools') library(caTools) set.seed(123) split = sample.split(dataset$Purchased, SplitRatio = 0.75) training_set = subset(dataset, split == TRUE) test_set = subset(dataset, split == FALSE) # Feature Scaling training_set[-3] = scale(training_set[-3]) test_set[-3] = scale(test_set[-3]) # Fitting Decision Tree Classification to the Training set # install.packages('rpart') library(rpart) classifier = rpart(formula = Purchased ~ ., data = training_set) # Predicting the Test set results y_pred = predict(classifier, newdata = test_set[-3], type = 'clas...
Comments
Post a Comment