Homework 1

.docx

School

Georgia Institute Of Technology *

*We aren’t endorsed by this school

Course

6501

Subject

Industrial Engineering

Date

Dec 6, 2023

Type

docx

Pages

2

Uploaded by MegaIron12500

Report
Homework 1 August 31 st , 2022 # QUESTION 2.1 Recently I was talking with the Real-Estate department team from the company that I’m working at. It is very interesting how SVM and classifications could play a huge role. When a company trying to open a new branch, or invest in a location or a building, there are a few predictors to be determined. Such as, the median income of that location, market price, force majeure risks, number of populations, and crime rates. # QUESTION 2.2 library ( kernlab ) library ( rsample ) library ( caret ) creditdata = read.table ( "credit_card_data.txt" , header = FALSE , stringsAsFactors = FALSE ) #import data data = as.matrix ( creditdata ) head ( creditdata ) #to sample the first small sample of rows present in the input data frame tail ( creditdata ) #to sample the last small sample of rows present in the input data frame svm_c = function ( c ){ #defining a function model = ksvm ( data [ , 1 : 10 ] ,as.factor ( data [ , 11 ]) ,type = "C- svc" , kernel = "vanilladot" ,C = lambda,scaled = TRUE ) #call ksvm pred = predict ( model, data [ , 1 : 10 ]) #see what the model predicts sum ( pred == data [ , 11 ]) / nrow ( data ) #see what fraction of the model’s predictions match the actual classification } print ( svm_c ( 10 )) #Checking for the accuracy of the model print ( svm_c ( 100 )) #Checking for the accuracy of the model print ( svm_c ( 1000 )) #hecking for the accuracy of the model # Using 100 as the best C model = ksvm ( data [ , 1 : 10 ] ,as.factor ( data [ , 11 ]) ,type = "C- svc" , kernel = "vanilladot" ,C = 100 ,scaled = TRUE ) calculate_a = colSums ( model@xmatrix [[ 1 ]] * model@ coef [[ 1 ]]) #calculate a1 ... am print ( calculate_a ) calculate_a0 = model@b #calculate a0 print ( calculate_a0 ) # -0.08158492 pred = predict ( model, data [ , 1 : 10 ]) #getting the prediction print ( sum ( pred == data [ , 11 ]) / nrow ( data )) #86.39%
#Analysis: #The result shows that the ideal classifier is: #y = -0.0010065348*V1 -0.0011729048*V2 -0.0016261967*V3 0.0030064203*V4 1.0049405641*V5 -0.0028259432*V6 # -0.0002600295*V7 -0.0005349551*V8 -0.0012283758*V9 + 0.1063633995*V10 #The accuracy for prediction is 0.8639144 # QIESTION 2.3 library ( kknn ) #enabling the KKNN package acc_all = c () predicted = c () data = read.delim ( "credit_card_data-headers.txt" ) set.seed ( 3 ) #initialize a pseudorandom number generator gp = runif ( nrow ( data )) #creating random deviates of n rows from the data file data_random = data [ order ( gp ) , ] #sorting the random deviates for ( k in 1 : 20 ) { for ( i in 1 : nrow ( data_random )) { model = kknn ( R1 ~ .,data_random [- i, ] ,data_random [ i, ] ,k = k, scale = TRUE ) predicted [ i ] = as.integer ( fitted ( model )+ 0.5 ) } acc_onek = sum ( predicted == data_random [ , 11 ]) / nrow ( data_random ) acc_all = c ( acc_all,acc_onek ) } max ( acc_all ) # 85.32% match ( max ( acc_all ) , acc_all ) # k = 12 plot ( c ( 1 : 20 ) , acc_all ) #Analysis: #The result shows that the max accuracy k is 12, from the range of 1 to 20
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help