Tutorial on “Orange: An Open Source Data Mining Package” Prepared By: Mr. KISHOJ BAJRACHARYA (ID No: 111224) [email protected]Department of Computer Science and Information Management School of Engineering and Technology Asian Institute of Technology October 12, 2011 Contents 1 Orange 2 1.1 Introduction ........................................... 2 1.2 Features of Orange ....................................... 2 1.3 Installing Orange-Canvas .................................... 2 1.3.1 Installing on Windows ................................. 2 1.3.2 Installing on Ubuntu .................................. 4 1.4 Python Scripting ........................................ 4 2 Python Scripting Code Examples 6 2.1 Using Python Code ....................................... 6 2.2 Support, Confidence and Lift for Association Rule ....................... 7 2.3 Naive Bayes Classifier ..................................... 8 2.4 Regression ............................................ 9 2.5 K-Means Clustering Algorithm ................................. 10 3 References 13 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Tutorial on “Orange: An Open Source Data Mining Package”
Orange is a collection of Python-based modules that sit over the core library of C++ objects and routinesthat handles machine learning and data mining algorithms. It is an open source data mining package buildon Python, Wrapped C, C++ and Qt.
Orange widgets provide a graphical users interface to Oranges data mining and machine learning meth-ods. They include widgets for data entry and pre-processing, data visualization, classification, regression,association rules and clustering, a set of widgets for model evaluation and visualization of evaluation re-sults, and widgets for exporting the models into Decision support system. Orange widgets and OrangeCanvas are all written in Python using Qt graphical users interface library. This allows Orange to run onvarious platforms, including MS Windows and Linux.
1.2 Features of Orange
1. Open and free software: Orange is an open source and free data mining software tool.
2. Platform independent software: Orange is supported on various versions of Linux, Microsoft win-dows, and Apples Mac.
3. Programming support: Orange supports visual programming tools for Data mining: Users candesign data analysis process via visual programming. Orange provides different visualization likebardiagram, scatterplots, trees, network, etc.
4. Scripting Interface: Orange provides python scripting. Programmers can test various new algorithmsand data analysis using python scripting.
5. Support for other components: Orange provides support for Machine Learning, bioinformatics, textmining, etc.
1.3 Installing Orange-Canvas
Orange-Canvas can be install on any platform. Browse the URI http://orange.biolab.si/nightly_builds.html for more informations on installing Orange-Canvas on different platforms. Here we focuson two platforms: Windows 7 and Ubuntu.
1.3.1 Installing on Windows
1. Browse the URI http://orange.biolab.si/nightly_builds.html.
1. Browse the URI http://orange.biolab.si/download/archive/.
2. Download the compressed file “orange-2.0-20101215svn.zip”.
3. Extract all the files from the file “orange-2.0-20101215svn.zip”.
unzip orange-2.0-20101215svn.zip
4. Type the following commands on linux terminal
python setup.py build
sudo python setup.py install
python setup.py install –user
1.4 Python Scripting
Using the scripting language python in which the module orange can be imported by following code.# Import module orange for python scriptingimport orange
Orange provides scripting interface on python programming language. Programmers can test various newalgorithms and data analysis using python scripting.
2.1 Using Python Code
The following code in the file test.py is used to test python scripting for Orange. It shows the simple pythonprogram to test the importing of data from an external file and play with the data access mechanism.
5 # Importing data from the file named "test.tab"6 data = orange.ExampleTable("test")7
8 # Printing the attributes of the table9 print "Attributes:"
10 print data.domain.attributes11
12 # List of attributes13 attributeList = []14
15 # Printing the attributes of the table16 for i in data.domain.attributes:17 attributeList.append(i.name)18 print i.name19 attributeList.append(data.domain.classVar.name)20
21 # Class Name22 print "Class:", data.domain.classVar.name23
29 # Displaying the data from the table30 print "Data items:"31 for i in range(14):32 print data[i]
Let the data table for above code be shown as in Fig 6.
Fig 6: Data Table 1
6
The output of the above program is shown in Fig 7.
Fig 7: Output of test.py
2.2 Support, Confidence and Lift for Association Rule
The following “example2.py” shows how do we use scripting language like python to get support andconfidence for all the possible association rules developed from the data of imported file “association.tab”.
5 # Importing data from a file named association.tab6 data = orange.ExampleTable("association")7
8 # Data Preprocessing9 data = orange.Preprocessor_discretize(data, method=orange.EquiNDiscretization(numberOfIntervals=4))
10
11 # Data Selection (We have range of 2)12 data = data.select(range(2))13
14 # List of supports15 iList = [0.1, 0.2, 0.3, 0.4]16
17 for x in iList:18 # Developing association rules from Orange19 rules = orange.AssociationRulesInducer(data, support=x)20
21 # if there is no association rule22 if(len(rules) == 0):23 print "No any association rules for support = \%5.3f" \% (x)24 # if there exists an association rule25 else:26 print "\%i rules with support = \%5.3f found.\n" \% (len(rules), x)27 orngAssoc.sort(rules, ["support", "confidence", "lift"])28 orngAssoc.printRules(rules[:(len(rules))], ["support", "confidence", "lift"])29 print
The output of the above program is shown in Fig 8.
7
Fig 8: Output of example2.py
2.3 Naive Bayes Classifier
Using Python, we observe the working of Bayesian classifier from voting data set i.e. “voting.tab” and willuse it to classify the first five instances from this data set.
1 # classifier.py2 import orange3 data = orange.ExampleTable("voting")4 classifier = orange.BayesLearner(data)5 for i in range(5):6 c = classifier(data[i])7 print "\%d: \%s (originally \%s)" \% (i+1, c, data[i].getclass())
The script loads the data, uses it to constructs a classifier using naive Bayesian method, and then classifiesfirst five instances of the data set. Naive Bayes made a mistake at a third instance, but otherwise predictedcorrectly as shown if the figure below.
8
Fig 9: Output of classifier.py
2.4 Regression
Following example uses both regression trees and k-nearest neighbors, and also uses a majority learnerwhich for regression simply returns an average value from learning data set.
6 # To plot the 2D-point7 def plot_scatter(data, km, attx, atty, filename="kmeans-scatter", title=None):8 """plot a data scatter plot with the position of centroids"""9 pylab.rcParams.update({’font.size’: 8, ’figure.figsize’: [4,3]})
10
11 # For the points12 x = [float(d[attx]) for d in data]13 y = [float(d[atty]) for d in data]14 colors = ["c", "b"]15 cs = "".join([colors[c] for c in km.clusters])16 pylab.scatter(x, y, c=cs, s=10)17
18 # For the centroid points19 xc = [float(d[attx]) for d in km.centroids]20 yc = [float(d[atty]) for d in km.centroids]21 pylab.scatter(xc, yc, marker="x", c="k", s=200)22
34 # Read the data from table35 data = orange.ExampleTable("data")36 km = orngClustering.KMeans(data, 2, minscorechange=-1, maxiters=10, inner_callback=in_callback)
11
The output of this program is shown below: Result of test.py
Fig 12(a): During iteration 0
Fig 12(b): During iteration 1
12
3 References
The following are the references taken as a help to prepare this manual: