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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 28 10:33:41 PDT 2016


Author: spawley
Date: 2016-03-28 10:33:41 -0700 (Mon, 28 Mar 2016)
New Revision: 68172

Modified:
   grass-addons/grass7/raster/r.randomforest/r.randomforest.py
Log:
adding r2 to randomforest output

Modified: grass-addons/grass7/raster/r.randomforest/r.randomforest.py
===================================================================
--- grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-03-28 17:22:55 UTC (rev 68171)
+++ grass-addons/grass7/raster/r.randomforest/r.randomforest.py	2016-03-28 17:33:41 UTC (rev 68172)
@@ -329,13 +329,16 @@
             else:
                 rf = RandomForestClassifier(n_jobs=-1, n_estimators=int(ntrees), oob_score=True, \
                 max_features = mfeatures, min_samples_split = minsplit, random_state = randst)
+            rf = rf.fit(training_data, training_labels)
+            print('Our OOB prediction of accuracy is: {oob}%'.format(oob=rf.oob_score_ * 100))
         else:
             rf = RandomForestRegressor(n_jobs=-1, n_estimators=int(ntrees), oob_score=True, \
             max_features = mfeatures, min_samples_split = minsplit, random_state = randst)
-        rf = rf.fit(training_data, training_labels)
+            rf = rf.fit(training_data, training_labels)
+            print('Our coefficient of determination R^2 of the prediction is: {r2}%'.format \
+            (r2=rf.score(X = training_data, y=training_labels)))
     
         # diagnostics
-        print('Our OOB prediction of accuracy is: {oob}%'.format(oob=rf.oob_score_ * 100))
         rfimp = pd.DataFrame(rf.feature_importances_)
         rfimp.insert(loc=0, column='Raster', value = maplist)
         rfimp.columns = ['Raster', 'Importance']



More information about the grass-commit mailing list