[GRASS-SVN] r70790 - grass-addons/grass7/vector/v.class.mlR

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 22 10:35:01 PDT 2017


Author: mlennert
Date: 2017-03-22 10:35:01 -0700 (Wed, 22 Mar 2017)
New Revision: 70790

Modified:
   grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html
   grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py
Log:
v.class.mlR: added xgboost classification algorithm and improved information on the tunegrids parameter


Modified: grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html
===================================================================
--- grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html	2017-03-22 16:19:54 UTC (rev 70789)
+++ grass-addons/grass7/vector/v.class.mlR/v.class.mlR.html	2017-03-22 17:35:01 UTC (rev 70790)
@@ -38,11 +38,17 @@
 
 <p>The user can define a customized tunegrid for each classifier, using
 the <em>tunegrids</em> parameter. Any customized tunegrid has to be defined
-as a Python dictionary, with the classifiers as keys, and tunegrid data frames
-as content as defined 
+as a Python dictionary, with the classifiers as keys, and the input to 
+expand.grid() as content as defined 
 <a href="http://topepo.github.io/caret/model-training-and-tuning.html#alternate-tuning-grids">
 	in the caret documentation</a>.
 
+<p>For example, to define customized tuning grids for svmRadial and 
+RandomForest, the user can define the paramter as:<br>
+<div class="code"><pre>
+tunegrids="{'svmRadial': 'sigma=c(0.01,0.05,0.1), C=c(1,16,128)', 'rf': 'mtry=c(3,10,20)'}"
+</pre></div>
+
 <p>The module can run the model tuning using parallel processing. In order
 for this to work, the R-package <em>doParallel</em> has to be installed. The
 <em>processes</em> parameter allows to chose the number of processes to

Modified: grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py
===================================================================
--- grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py	2017-03-22 16:19:54 UTC (rev 70789)
+++ grass-addons/grass7/vector/v.class.mlR/v.class.mlR.py	2017-03-22 17:35:01 UTC (rev 70790)
@@ -112,8 +112,8 @@
 #% description: Classifiers to use
 #% required: yes
 #% multiple: yes
-#% options: svmRadial,rf,rpart,C5.0,knn,knn1
-#% answer: svmRadial,rf,rpart,C5.0,knn,knn1
+#% options: svmRadial,rf,rpart,C5.0,knn,knn1,xgbTree
+#% answer: svmRadial,rf,C5.0,xgbTree
 #%end
 #%option
 #% key: folds
@@ -273,7 +273,7 @@
     weighting_functions['bwwv'] = "weights <- 1-(max(weighting_base) - weighting_base)/(max(weighting_base) - min(weighting_base))"
     weighting_functions['qbwwv'] = "weights <- ((min(weighting_base) - weighting_base)/(max(weighting_base) - min(weighting_base)))**2"
 
-    packages = {'svmRadial': 'kernlab', 'rf': 'randomForest', 'rpart': 'rpart', 'C5.0': 'C50'}
+    packages = {'svmRadial': ['kernlab'], 'rf': ['randomForest'], 'rpart': ['rpart'], 'C5.0': ['C50'], 'xgbTree': ['xgboost', 'plyr']}
 
     install_package = "if(!is.element('%s', installed.packages()[,1])){\n"
     install_package += "cat('\\n\\nInstalling %s package from CRAN\n')\n"
@@ -308,12 +308,6 @@
     weighting_modes = options['weighting_modes'].split(',')
     weighting_metric = options['weighting_metric']
     processes = int(options['processes'])
-    if processes > 1:
-	install = install_package % ('doParallel', 'doParallel', 'doParallel')
-	r_file.write(install)
-	r_file.write("\n")
-
-        
     folds = options['folds']
     partitions = options['partitions']
     tunelength = options['tunelength']
@@ -374,6 +368,10 @@
 
     r_file = open(r_commands, 'w')
 
+    if processes > 1:
+	install = install_package % ('doParallel', 'doParallel', 'doParallel')
+	r_file.write(install)
+	r_file.write("\n")
 
     # automatic installation of missing R packages
     install = install_package % ('caret', 'caret', 'caret')
@@ -386,10 +384,10 @@
         # knn is included in caret
 	if classifier == "knn" or classifier == "knn1":
 	    continue	
-        package = packages[classifier]
-        install = install_package % (package, package, package)
-	r_file.write(install)
-	r_file.write("\n")
+        for package in packages[classifier]:
+            install = install_package % (package, package, package)
+            r_file.write(install)
+            r_file.write("\n")
     r_file.write("\n")
     r_file.write('require(caret)')
     r_file.write("\n")



More information about the grass-commit mailing list