Genetic Algorithm Optimization of RF Model

I am working on a problem set in which I have Cost Per Click and Day of the week as independent variables and Profit as dependent variable. I want to use this dataset to train a model to predict the optimal Cost Per Click for the next day.

I have trained a random forest model on the training data. Now in order to predict the optimal cost per click for the next day, I am planning to use the Day of the week of the next day and test a series of different Cost Per Click on the trained random forest model and compare profit from each iteration. Whichever Cost per click gives the max profit, I want to pick that. For this optimization I am thinking of using Genetic Algorithm.

I have never used Genetic Algorithm before and I am currently struggling with writing the fitness function in this case. Below is my rookie attempt:

For e.g. in my below attempt, fit_rf is my trained random forest model and ind_var is the day_of_week and cost_per_click variable. Does below fitness makes sense to solve the above problem?

 fitness - function(x) {
      df - mdb_train[x == 1, ]   
       profit - predict(fit_rf, df)   
       profit - ifelse(profitmdb_train$profit,profit,mdb_train$profit)  
       return(mdb_train$CPC)  
  }

 GA - ga(binary, fitness = fitness, nBits = ncol(mdb_train),names = ind_var, monitor = plot,maxiter = 10)

Topic genetic-algorithms regression random-forest optimization r

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.