[GRASS-SVN] r68840 - grass-addons/grass7/raster/r.randomforest

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 3 08:56:29 PDT 2016


Author: spawley
Date: 2016-07-03 08:56:29 -0700 (Sun, 03 Jul 2016)
New Revision: 68840

Modified:
   grass-addons/grass7/raster/r.randomforest/r.randomforest.py
Log:
Bug fixeds to r.randomforest

Modified: grass-addons/grass7/raster/r.randomforest/r.randomforest.py
===================================================================
--- grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-07-02 22:28:18 UTC (rev 68839)
+++ grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-07-03 15:56:29 UTC (rev 68840)
@@ -159,6 +159,12 @@
 def score_classification_results(X, y, clf, kfolds, rstate):
     # PURPOSE: custom function performs cross validation on a classification model,
     # RETURNS: a 1D list representing accuracy, AUROC, precision, recall, kappa and specificity
+    
+    # lazy import of sklearn
+    try:
+        from sklearn import cross_validation, metrics
+    except:
+        grass.fatal("Scikit-learn python module (python-sklearn) is not installed.....exiting")
         
     kf = cross_validation.KFold(len(y), n_folds=kfolds, shuffle=True, random_state=rstate)
 
@@ -213,6 +219,12 @@
     # RETURNS: 2D list of CLASS and mean performance measure result
     # RETURNS: 2D list of CLASS and standard deviation of performance measure result
     # Performance measures are sensitivity, recall
+    
+    # lazy import of sklearn
+    try:
+        from sklearn import cross_validation, metrics
+    except:
+        grass.fatal("Scikit-learn python module (python-sklearn) is not installed.....exiting")
 
     class_list = np.unique(y)
     nclasses = len(np.unique(y))



More information about the grass-commit mailing list