Skip to content

Instantly share code, notes, and snippets.

@Salinger
Created June 3, 2013 11:19
Show Gist options
  • Save Salinger/5697523 to your computer and use it in GitHub Desktop.
Save Salinger/5697523 to your computer and use it in GitHub Desktop.
library(ggplot2) # For Plot
library(kernlab) # For SVM
auth = read.table("./CodeIQ_auth.txt",header=F,sep=" ")
names(auth) <- c("volume","weight","truth") # 0 is Fake
my_coins = read.table("./CodeIQ_mycoins.txt",header=F,sep=" ")
names(my_coins) <- c("volume","weight")
g = ggplot(auth,aes(x=volume,y=weight)) + geom_point(aes(color=truth))
print(g)
browser() # Check train data
# Create SVM train data
train.features = cbind(auth$volume,auth$weight)
train.labels = auth$truth
predict.features <- cbind(my_coins$volume,my_coins$weight)
classifier <- ksvm(
train.features,
train.labels,
type="C-svc",
kerel="vanilladot", # Liner kernel
C=1
)
my_coins["truth"] <- predict(classifier,predict.features)
print(my_coins$truth)
write.table(my_coins ,file="result.csv",row.names = F)
# Plot result
my_coins$truth[my_coins$truth == 0] <- 2 # 2 is predicted Fake
my_coins$truth[my_coins$truth == 1] <- 3
result <- rbind(auth,my_coins)
result$truth <- factor(result$truth, levels = c(0,1,2,3))
g = ggplot(result,aes(x=volume,y=weight)) + geom_point(aes(color=truth))
print(g)
@thaiviet1994
Copy link

Creating a “truth table” is not hard, you can use an useful tool (CKod, at http://ckod.sourceforge.net/_/) to make a “truth table”.

  1. CKod homepage: http://ckod.sourceforge.net/
  2. CKod online: http://ckod.sourceforge.net/_/
  3. CKod forum: http://ckod.sourceforge.net/~/

Good luck to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment