1
#Predict the test set results 
prob_pred = predict(classifier, type = 'response', newdata = test_set[-3])
y_pred = ifelse(prob_pred>0.5, 1, 0)

# Visualising the Test set results
install.packages('ElemStatLearn'
library(ElemStatLearn)
set = test_set
X1 = seq(min(set[, 1]) - 1, max(set[, 1]) + 1, by = 0.01)
X2 = seq(min(set[, 2]) - 1, max(set[, 2]) + 1, by = 0.01)
grid_set = expand.grid(X1, X2)
colnames(grid_set) = c('Age', 'EstimatedSalary')
prob_set = predict(classifier, type = 'response', newdata = grid_set)
y_grid = ifelse(prob_set > 0.5, 1, 0)
plot(set[, -3],
     main = 'Logistic Regression (Test set)',
     xlab = 'Age', ylab = 'Estimated Salary',
     xlim = range(X1), ylim = range(X2))
contour(X1, X2, matrix(as.numeric(y_grid), length(X1), length(X2)), add = TRUE)
points(grid_set, pch = '.', col = ifelse(y_grid == 1, 'springgreen3', 'tomato'))
points(set, pch = 21, bg = ifelse(set[, 3] == 1, 'green4', 'red3'))

Expected visualized result as shown in image enter image description here

Is there any alternative package available to get the same result as shown in image?

  • download the archive from [link]https://cran.r-project.org/src/contrib/Archive/ElemStatLearn/ and then in R Studio, go to Tools->Install Packages, in the popup box select Package Archive and Browse where the tar.gz file has been downloaded. Hope this helps – jsaf Feb 16 '21 at 13:42

0 Answers0