R/sendToDatabase.R

Defines functions sendToDatabase

#' @title Send Meta-Features to the Database
#' @description Save Meta Features with results obtained in the database
#' @param df data frame with meta features
#' @param algorithmName Name of best classifier algorithm
#' @param bestParams best parameters chosen
#' @seealso \code{\link[utils]{head}}
#' @examples \dontrun{ sendToDatabase(metaFeats, "svmkk", list(x=1, y=2, z=3))
#' }
sendToDatabase <- function(df, algorithmName, bestParams){
  library("RMySQL")
  mydb = dbConnect(MySQL(), user='root', password='', dbname='autorlearn', host='localhost')
  #mydb = dbConnect(MySQL(), user='eb2a_16942489', password='', dbname='eb2a_16942489_AutoRLearn', host='sql205.eb2a.com')
  df$params <- sprintf("'%s'", paste( unlist(bestParams), collapse='-'))
  df$classifierAlgorithm <- sprintf("'%s'", algorithmName)
  query <- sprintf("INSERT INTO metafeatures (classifierAlgorithm, datasetRatio,  featuresKurtStdDev,  featuresKurtMean,  featuresKurtMax, featuresKurtMin,  featuresSkewStdDev, featuresSkewMean,  featuresSkewMax,  featuresSkewMin,  symbolsStdDev,  symbolsSum,  symbolsMean,  classProbStdDev, classProbMean,  classProbMax,  classProbMin,  classEntropy,  ratioNumToCat,  nCatFeatures,  nNumFeatures, nInstances,  nFeatures,  nClasses,  lognFeatures,  lognInstances, parameters) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
                   df$classifierAlgorithm,
                   df$datasetRatio, df$featuresKurtStdDev, df$featuresKurtMean, df$featuresKurtMax, df$featuresKurtMin, df$featuresSkewStdDev,
                   df$featuresSkewMean, df$featuresSkewMax, df$featuresSkewMin, df$symbolsStdDev, df$symbolsSum, df$symbolsMean, df$classProbStdDev,
                   df$classProbMean, df$classProbMax, df$classProbMin, df$classEntropy, df$ratioNumToCat, df$nCatFeatures, df$nNumFeatures,
                   df$nInstances, df$nFeatures, df$nClasses, df$lognFeatures, df$lognInstances, df$params)
  dbSendQuery(mydb, query)
  on.exit(dbDisconnect(mydb))
}
mmaher22/AutoRLearn documentation built on Aug. 19, 2018, 8:50 p.m.