Commits

Miran Levar  committed c1969b8

Clustering random forests widget and some widget documentation.

  • Participants
  • Parent commits f9890f7

Comments (0)

Files changed (20)

File _multitarget/widgets/OWBinaryRelevance.py

 """
 <name>Binary Relevance</name>
 <description>Binary relevance learner wrapper</description>
-<priority>1300</priority>
+<priority>1000</priority>
+<category>Multitarget</category>
 <tags>multitarget,binary,relevance,wrapper</tags>
 <icon>icons/BinaryRelevance.png</icon>
 

File _multitarget/widgets/OWClassifierChain.py

 <name>Classifier Chain</name>
 <description>Chain normal single target classifiers to
 support multitarget problems</description>
+<category>Multitarget</category>
 <priority>1100</priority>
 <tags>wrapper,multitarget,chain</tags>
 <icon>icons/ClassifierChain.png</icon>

File _multitarget/widgets/OWClusteringRandomForest.py

+"""
+<name>Clustering Random Forest</name>
+<description>Clustering random forest learner/classifier for multi
+target classification.</description>
+<icon>icons/ClusteringRandomForest.png</icon>
+<priority>110</priority>
+"""
+
+import Orange
+import Orange.multitarget
+
+from Orange.tuning import PreprocessedLearner
+
+from OWWidget import *
+import OWGUI
+
+class OWClusteringRandomForest(OWWidget):
+    settingsList = ["name", "trees", "min_instances", "min_majority",
+                    "max_depth", "min_MSE", "method"]
+
+    def __init__(self, parent=None, signalManager=None,
+                 title="Clustering Random Forest"):
+        OWWidget.__init__(self, parent, signalManager, title,
+                          wantMainArea=False)
+
+        self.inputs = [("Data", Orange.data.Table, self.set_data),
+                       ("Preprocess", PreprocessedLearner,
+                        self.set_preprocessor)
+                       ]
+        self.outputs = [("Learner", Orange.classification.Learner),
+                        ("Classifier", Orange.classification.Classifier)
+                        ]
+
+        self.name = 'Clustering Random Forest'
+        self.trees = 25
+        self.max_depth = 100
+        self.min_majority = 1.0
+        self.min_MSE = 0.001
+        self.min_instances = 5
+        self.method = 0
+
+        self.maxTrees = 10000
+
+        self.loadSettings()
+
+        self.data = None
+        self.preprocessor = None
+
+        box = OWGUI.widgetBox(self.controlArea, "Classifier/Learner Name")
+            OWGUI.lineEdit(box, self, "name")
+
+        OWGUI.spin(self.bBox, self, "trees", 1, 1000, orientation="horizontal", label="Number of trees in forest")
+
+        OWGUI.separator(self.controlArea)
+
+        OWGUI.spin(box, self, "max_depth", 1, 1000, 1,
+                   "Stop splitting nodes at depth")
+
+        OWGUI.doubleSpin(box, self, "min_majority", 0.01, 1.0, 0.01,
+                         "Minimal majority class proportion (%)",
+                         tooltip="Minimal proportion of the majority class "
+                                 "value each of the class variables has to "
+                                 "reach to stop induction (only used for "
+                                 "classification)"
+                        )
+
+        OWGUI.doubleSpin(box, self, "min_MSE", 0.001, 1.0, 0.001,
+                         "Min. mean squared error",
+                         tooltip="Minimal mean squared error each of the "
+                                 "class variables has to reach to stop "
+                                 "induction (only used for regression)."
+                         )
+
+        OWGUI.spin(box, self, "min_instances", 1, 1000, 1,
+                   "Min. instances in leaves")
+
+
+        OWGUI.radioButtonsInBox(self.controlArea, self, "method",
+              box = "Feature scorer",
+              btnLabels = ["Inter dist", "Intra dist", "Silhouette" ,"Gini-index"],
+              tooltips = ["Maximal distance between clusters",
+                          "Minimal distance inside clusters ",
+                          "Silhouette measure with prototypes",
+                          "Gini-index, used for nominal class variables"]
+                          )
+
+        OWGUI.separator(self.controlArea)
+
+        OWGUI.button(self.controlArea, self, "&Apply",
+                     callback=self.apply,
+                     tooltip="Create the learner and apply it on input data.",
+                     autoDefault=True
+                     )
+
+        self.data = None
+        self.preprocessor = None
+        self.apply()
+
+    def sendReport(self):
+        self.reportSettings(
+            "Parameters",
+            [("# of trees", self.trees),
+            ("Max depth", self.max_depth),
+             ("Min. majority", self.min_majority),
+             ("Min MSE", self.min_MSE),
+             ("Min instances in leaves", self.min_instances)
+             ]
+        )
+        self.reportData(self.data)
+
+
+    def set_data(self, data=None):
+        """Set the widget input data.
+        """
+        self.data = data
+        self.error([0])
+        if data is not None and not data.domain.class_vars:
+            data = None
+            self.error(0, "Input data must have multi target domain.")
+
+        self.data = data
+        self.apply()
+
+        self.send("Random Forest Classifier", self.classifier)
+        
+    def set_preprocessor(self, preprocessor=None):
+        """Set data preprocessor.
+        """
+        self.preprocessor = preprocessor
+
+
+
+    def apply(self):
+        """Apply the settings to the output learner. If input data is available
+        then also construct a classifier.
+
+        """
+
+        learner = Orange.multitarget.tree.ClusteringTreeLearner(
+                    max_depth=self.max_depth,
+                    min_majority=self.min_majority,
+                    min_MSE=self.min_MSE,
+                    min_instances=self.min_instances,
+                    method=self.method,
+                    name=self.name)
+
+        learner = Orange.ensemble.forest.RandomForestLearner(base_learner=learner, \
+            trees=self.trees, name=self.name)
+
+        if self.preprocessor is not None:
+            learner = self.preprocessor.wrapLearner(learner)
+
+        classifier = None
+        self.error([1])
+        if self.data is not None:
+            try:
+                classifier = learner(self.data)
+                classifier.name = self.name
+            except Exception, ex:
+                self.error(1, str(ex))
+
+        self.send("Learner", learner)
+        self.send("Classifier", classifier)
+
+
+
+
+if __name__=="__main__":
+    # no tests currently
+    pass

File _multitarget/widgets/OWClusteringTree.py

 <description>Classification tree learner/classifier for multi
 target classification</description>
 <priority>100</priority>
+<category>Multitarget</category>
 <tags>tree,multitarget</tags>
 <icon>icons/ClusteringTree.png</icon>
 
                     min_majority=self.min_majority,
                     min_MSE=self.min_MSE,
                     min_instances=self.min_instances,
-                    method = self.method,
+                    method=self.method,
                     name=self.name)
 
         if self.preprocessor is not None:

File _multitarget/widgets/OWEnsembleClassifierChain.py

 <name>Ensemble Classifier Chain</name>
 <description>Train an ensemble of chain classifiers</description>
 <priority>1200</priority>
+<category>Multitarget</category>
 <tags>wrapper,multitarget,chain,ensemble</tags>
 <icon>icons/EnsembleClassifierChain.png</icon>
 """

File _multitarget/widgets/OWNeuralNetwork.py

 <name>Neural Network</name>
 <description>Neural network learner/classifier supporting multi target problems.</description>
 <category>Multitarget</category>
-<priority>50<priority>
+<priority>20<priority>
 <tags>neural,network,multitarget</tags>
 <icon>icons/NeuralNetwork.png</icon>
 

File _multitarget/widgets/OWPLSClassifier.py

 """<name>PLS Classification</name>
 <description>PLS Classification</description>
+<category>Multitarget</category>
 <priority>160</priority>
 <icon>icons/PLSClassification.png</icon>
 """

File _multitarget/widgets/OWTestMultitargetLearners.py

 <name>Test Multitarget Learners</name>
 </description>A widget for scoring the performance of learning algorithms
 on multitarget domains</description>
-<priority>1000</priority>
+<category>Multitarget</category>
+<priority>2000</priority>
 """
 
 import Orange

File _multitarget/widgets/icons/ClusteringRandomForest.png

Added
New image

File docs/rst/BinaryRelevance.rst

+BinaryRelevance
+================
+
+.. image:: ../../_multitarget/widgets/icons/BinaryRelevance.png
+   :alt: Widget icon
+   
+Signals
+-------
+
+Inputs:
+   - Learner
+   		The base learner used in the ensemble technique.
+
+Outputs:
+   - Learner or Classifier
+
+Description
+-----------
+
+.. image:: images/binary1.*
+   :alt: Usage example
+
+Binary relevance learner takes a single-target learner and with it creates a classifier for every class variable in the data. 
+
+

File docs/rst/ClassifierChain.rst

+ClassifierChain
+================
+
+.. image:: ../../_multitarget/widgets/icons/ClassifierChain.png
+   :alt: Widget icon
+   
+Signals
+-------
+
+Inputs:
+   - Learner
+   		The base learner used in the ensemble technique.
+
+Outputs:
+   - Learner or Classifier
+
+Description
+-----------
+
+.. image:: images/cchain1.*
+   :alt: Usage example
+
+Classifier chain learner takes a single-target learner and with it creates a classifier for every class variable in the data. Every time a classifier is created, the values of that class variable are added to features. The order in which the class variables are chosen is random.
+
+
+Setting:
+	- Use actual values
+		If checked, the values added into features are actual values from the data. Otherwise the values predicted by the classifier are used.
+
+

File docs/rst/ClusteringTree.rst

+EnsembleClassifierChains
+=========================
+
+.. image:: ../../_multitarget/widgets/icons/EnsembleClassifierChain.png
+   :alt: Widget icon
+   
+Signals
+-------
+
+Inputs:
+   - Learner
+   		The base learner used in the ensemble technique.
+
+Outputs:
+   - Learner or Classifier
+
+Description
+-----------
+
+.. image:: images/ecchain1.*
+   :alt: Usage example
+
+Ensemble classifier chain learner takes a single-target learner and with it creates a number of classifier chains. Each chain is constructed on a random sample of the dataset.
+
+
+Setting:
+	- Number of chains
+		Number of classifier chains that are built.
+	- Sample size
+		The size of the random sample taken from the dataset for each chain.
+	- Use actual values
+		If checked, the values added into features are actual values from the data. Otherwise the values predicted by the classifier are used.
+
+

File docs/rst/EnsembleClassifierChains.rst

+EnsembleClassifierChains
+=========================
+
+.. image:: ../../_multitarget/widgets/icons/EnsembleClassifierChain.png
+   :alt: Widget icon
+   
+Signals
+-------
+
+Inputs:
+   - Learner
+   		The base learner used in the ensemble technique.
+
+Outputs:
+   - Learner or Classifier
+
+Description
+-----------
+
+.. image:: images/ecchain1.*
+   :alt: Usage example
+
+Ensemble classifier chain learner takes a single-target learner and with it creates a number of classifier chains. Each chain is constructed on a random sample of the dataset.
+
+
+Setting:
+	- Number of chains
+		Number of classifier chains that are built.
+	- Sample size
+		The size of the random sample taken from the dataset for each chain.
+	- Use actual values
+		If checked, the values added into features are actual values from the data. Otherwise the values predicted by the classifier are used.
+
+

File docs/rst/Orange.multitarget.rst

 
 Multi-target prediction tries to achieve better prediction accuracy or speed
 through prediction of multiple dependent variables at once. It works on
-:ref:`multi-target data <multiple-classes>`, which is also supported by
-Orange's tab file format using :ref:`multiclass directive <tab-delimited>`.
+multi-target data, which is also supported by
+Orange's tab file format using multiclass directive.
 
 List of supported  learners: 
 

File docs/rst/conf.py

         else:
             return Mock()
 
-MOCK_MODULES = ['scipy', 'scipy.sparse', 'scipy.optimize']
+MOCK_MODULES = ['numpy', 'numpy.linalg', 'scipy', 'scipy.sparse', 'scipy.optimize']
 for mod_name in MOCK_MODULES:
     sys.modules[mod_name] = Mock()
 

File docs/rst/images/binary1.png

Added
New image

File docs/rst/images/cchain1.png

Added
New image

File docs/rst/images/ecchain1.png

Added
New image

File docs/rst/index.rst

 
    Orange.multitarget
 
+
+Widgets
+----------------------
+
+.. toctree::
+   :maxdepth: 1
+
+   BinaryRelevance
+   ClassifierChain
+   EnsembleClassifierChains
+   PLSClassification
+   ClusteringTree
+   NeuralNetwork
+   TestMultitargetLearners
+
+
 Installation
 ------------
 

File rdt_requirements

 numpydoc
+mock
 -e hg+https://bitbucket.org/biolab/orange/#egg=Orange