Skip to content

Commit

Permalink
Added Naive Bayes learner widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Dec 23, 2013
1 parent 5c82cf0 commit 4dd1176
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Orange/widgets/classify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Widgets for the Classify category.
"""


NAME = "Classify"

DESCRIPTION = "Classification algorithms."

BACKGROUND = "#FAC1D9"

ICON = "icons/Category-Classify.svg"

PRIORITY = 3
26 changes: 26 additions & 0 deletions Orange/widgets/classify/icons/Category-Classify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Orange/widgets/classify/icons/NaiveBayes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions Orange/widgets/classify/ownaivebayes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
Naive Bayes Learner
"""

import Orange.data
import Orange.classification.naive_bayes
from Orange.widgets import widget, gui, settings


class OWNaiveBayes(widget.OWWidget):
name = "Naive Bayes"
icon = "icons/NaiveBayes.svg"
inputs = [("Data", Orange.data.Table, "setData")]
outputs = [
("Learner", Orange.classification.naive_bayes.BayesLearner),
("Classifier", Orange.classification.naive_bayes.BayesClassifier)
]

want_main_area = False

learner_name = settings.Setting("Naive Bayes")

def __init__(self):
super().__init__()

# GUI
gui.lineEdit(gui.widgetBox(self.controlArea, self.tr("Name")),
self, "learner_name")

gui.rubber(self.controlArea)

gui.button(self.controlArea, self, self.tr("&Apply"),
callback=self.apply)

self.data = None

self.initialize()

def initialize(self):
"""
Initialize the widget's state.
"""
learner = Orange.classification.naive_bayes.BayesLearner()
learner.name = self.learner_name
self.send("Learner", learner)
self.send("Classifier", None)

def setData(self, data):
self.data = data
if data is not None:
self.apply()
else:
self.send("Classifier", None)

def apply(self):
classifier = None
learner = Orange.classification.naive_bayes.BayesLearner()
learner.name = self.learner_name

if self.data is not None:
classifier = learner(self.data)
classifier.name = self.learner_name

self.send("Learner", learner)
self.send("Classifier", classifier)

0 comments on commit 4dd1176

Please sign in to comment.