# import numpy
from sklearn.ensemble import RandomForestClassifier as RandomForest
from sklearn.preprocessing import Imputer
from numpy import isnan
import Orange.data
import Orange.classification

def replace_nan(X, imp_model):
        # Default scikit Imputer
        # Use Orange imputer when implemented
        if isnan(X).sum():
                X = imp_model.transform(X)
        return X

# TODO: implement sending a single decision tree
class RandomForestLearner(Orange.classification.SklFitter):
    def __init__(self, n_estimators=10, max_features="auto",
                 random_state=None, max_depth=3, max_leaf_nodes=5):
        self.params = vars()

    def fit(self, X, Y, W):
        self.imputer = Imputer()
        self.imputer.fit(X)
        X = replace_nan(X, self.imputer)
        rf_model = RandomForest(**self.params)
        rf_model.fit(X, Y.ravel())
        return RandomForestClassifier(rf_model, self.imputer)


class RandomForestClassifier(Orange.classification.SklModel):
    def __init__(self, clf, imp):
        self.clf = clf
        self.imputer = imp

    def predict(self, X):
        X = replace_nan(X, imp_model=self.imputer)
        value = self.clf.predict(X)
        prob = self.clf.predict_proba(X)
        return value, prob

@@ -1,10 +1,8 @@
-# 
 import n
@@ -3,18 +3,21 @@
 port num
-py
+bers%0A
 %0Afrom sk
@@ -143,16 +143,17 @@
 t isnan%0A
+%0A
 import O
@@ -193,16 +193,17 @@
 cation%0A%0A
+%0A
 def repl
@@ -225,20 +225,16 @@
 model):%0A
-    
     # De
@@ -254,20 +254,16 @@
 Imputer%0A
-    
     # Us
@@ -300,20 +300,16 @@
 ted%0A    
- 
-   
 if isnan
@@ -327,24 +327,16 @@
         
-      
-  
 X = imp_
@@ -350,28 +350,24 @@
 ransform(X)%0A
-    
     return X
@@ -372,56 +372,8 @@
  X%0A%0A
-# TODO: implement sending a single decision tree
 %0Acla
@@ -710,32 +710,266 @@
 , self.imputer)%0A
+%0A        params = dict(self.params)%0A        max_features = params%5B%22max_features%22%5D%0A        if isinstance(max_features, numbers.Integral) and %5C%0A                X.shape%5B1%5D %3C max_features:%0A            params%5B%22max_features%22%5D = X.shape%5B1%5D%0A%0A
         rf_model
@@ -986,21 +986,16 @@
 orest(**
-self.
 params)%0A

Fix an error when number of predictor columns is less than max_features.