Note from Matt: I converted this from the Rmd file with the ipyrmd utility, which worked almost perfectly.
This is my first time using a notebook and github so I just want to run the inital SVM to see how it works and what is the accuracy I am getting.
In [ ]:
# Uncomment this line if you don't already have this library.
# install.packages("e1071", repos="http://cran.rstudio.com/")
In [4]:
library(e1071)
In [5]:
train_prod = read.csv('../facies_vectors.csv')
test_prod = read.csv('../nofacies_data.csv')
In [6]:
str(train_prod)
str(test_prod)
In [7]:
train_prod = train_prod[!is.na(train_prod$PE),]
In [8]:
train_prod$Facies = as.factor(as.character(train_prod$Facies))
In [9]:
train_row = sample(nrow(train_prod), 0.7*nrow(train_prod), replace=F)
train_local = train_prod[train_row,]
test_local = train_prod[-train_row,]
In [10]:
SVM.local.model = svm(Facies~., data = train_local[!colnames(train_local) %in% c('Formation',
'Well.Name',
'Depth'
)])
SVM.local.pred = predict(SVM.local.model, newdata = test_local)
In [11]:
acc_table_SVM = table(SVM.local.pred, test_local$Facies)
acc_table_SVM
acc_SVM = sum(diag(acc_table_SVM))/nrow(test_local)
acc_SVM
Out[11]:
Out[11]:
In [12]:
SVM.prod.pred = predict(SVM.local.model, newdata = test_prod)
In [13]:
sub = cbind(test_prod, Facies = SVM.prod.pred)
In [14]:
write.csv(sub, row.names= F, 'SVM_predicted_facies_MATT.csv')