University of Ottawa**We aren't endorsed by this school
Course
CSI 3120
Subject
Mathematics
Date
Dec 22, 2024
Pages
5
Uploaded by CaptainDiscoveryCrab15
Question 36Mounir Zouhari2024-11-24Part 1: Sketching the curveThe equation(1 +X1)2+ (2−X2)2= 4represents a circle with center at(−1,2)and radius2. Here’s theR code to sketch this circle.# Librarieslibrary(ggplot2)# Define the circle equationcircle_eq<-function(x1, x2) {(1+x1)ˆ2+(2-x2)ˆ2}# Generate grid points for visualizationx_vals<-seq(-4,2,length.out =300)# X1 rangey_vals<-seq(-1,5,length.out =300)# X2 rangegrid_data<-expand.grid(X1 =x_vals,X2 =y_vals)# Compute values for the decision boundarygrid_data$Z<-circle_eq(grid_data$X1, grid_data$X2)# Plot the circle (decision boundary)ggplot(grid_data,aes(x =X1,y =X2))+geom_contour(aes(z =Z),breaks =4,color ="blue",size =1)+labs(title ="Non-linear Decision Boundary",x ="X1",y ="X2")+theme_minimal()+theme(plot.title =element_text(hjust =0.5))## Warning: Using ‘size‘ aesthetic for lines was deprecated in ggplot2 3.4.0.## i Please use ‘linewidth‘ instead.## This warning is displayed once every 8 hours.## Call ‘lifecycle::last_lifecycle_warnings()‘ to see where this warning was## generated.1
01234-3-2-101X1X2Non-linear Decision BoundaryPart 2•Points satisfying(1 +X1)2+ (2−X2)2>4: Outside the circle (blue region).•Points satisfying(1 +X1)2+ (2−X2)2≤4: Inside the circle (red region).# Add classification regions based on inequalitygrid_data$Class<-ifelse(grid_data$Z>4,"Outside (Blue)","Inside (Red)")# Plot the circle with shaded regionsggplot(grid_data,aes(x =X1,y =X2))+geom_contour(aes(z =Z),breaks =4,color ="blue",size =1)+geom_raster(aes(fill =Class),alpha =0.4)+scale_fill_manual(values =c("Inside (Red)"="pink","Outside (Blue)"="lightblue"))+labs(title ="Decision Boundary with Regions",x ="X1",y ="X2")+theme_minimal()+theme(plot.title =element_text(hjust =0.5))2
024-4-202X1X2ClassInside (Red)Outside (Blue)Decision Boundary with RegionsPart 3: Classify specific pointsClassify points: 1.(0,0)2.(−1,1)3.(2,2)4.(3,8)For each point, substituteX1andX2into the equation:(1 +X1)2+ (2−X2)2If the result is>4, classify asBlue (outside). If≤4, classify asRed (inside).# Define points to classifytest_points<-data.frame(X1 =c(0,-1,2,3),X2 =c(0,1,2,8))# Classify each pointtest_points$Z<-circle_eq(test_points$X1, test_points$X2)test_points$Class<-ifelse(test_points$Z>4,"Blue (Outside)","Red (Inside)")# Print the classificationsprint(test_points)3
##X1 X2ZClass## 1005 Blue (Outside)## 2 -111Red (Inside)## 3229 Blue (Outside)## 438 52 Blue (Outside)# Add points to the plotggplot(grid_data,aes(x =X1,y =X2))+geom_contour(aes(z =Z),breaks =4,color ="blue",size =1)+geom_raster(aes(fill =Class),alpha =0.4)+scale_fill_manual(values =c("Inside (Red)"="pink","Outside (Blue)"="lightblue"))+geom_point(data =test_points,aes(x =X1,y =X2),color ="black",size =3)+geom_text(data =test_points,aes(x =X1,y =X2,label =Class),vjust =-1,color ="black")+labs(title ="Classification of Specific Points",x ="X1",y ="X2")+theme_minimal()+theme(plot.title =element_text(hjust =0.5))Blue (Outside)Red (Inside)Blue (Outside)Blue (Outs02468-4-202X1X2ClassInside (Red)Outside (Blue)Classification of Specific Points1.Point(0,0): Lies outside the circle ((1 + 0)2+ (2−0)2= 5), classified asBlue (Outside).2.Point(−1,1): Lies inside the circle ((1−1)2+ (2−1)2= 1), classified asRed (Inside).3.Point(2,2): Lies outside the circle ((1 + 2)2+ (2−2)2= 9), classified asBlue (Outside).4.Point(3,8): Lies outside the circle ((1 + 3)2+ (2−8)2= 52), classified asBlue (Outside).4
Part 4The equation:(1 +X1)2+ (2−X2)2= 4is non-linear inX1andX2. However, introducing new variables:Z1=X1, Z2=X2, Z3=X21, Z4=X22,makes the equation linear in the transformed feature space. The resulting equation becomes:Z3+Z4+ 2Z1−4Z2+ 1 = 4This is linear inZ1, Z2, Z3, Z4.5