Unit-7 Tools of AI (April 9, 2024)
Unit-7 Tools of AI (April 9, 2024)
1
Machine Learning Tools
Machine learning is one of the most revolutionary technologies that is making lives
simpler. It is a subfield of Artificial Intelligence, which analyses the data, build
the model, and make predictions. Due to its popularity and great applications,
every tech enthusiast wants to learn and build new machine learning Apps.
However, to build ML models, it is important to master machine learning tools.
Mastering machine learning tools will enable you to play with the data, train your
models, discover new methods, and create algorithms.
There are different tools, software, and platform available for machine learning,
and also new software and tools are evolving day by day. Although there are many
options and availability of Machine learning tools, choosing the best tool per your
model is a challenging task. If you choose the right tool for your model, you can
make it faster and more efficient and choosing the tool completely depends on the
requirement for one's project, skills, and price to the tool. Most of these tools are
freely available, except for some tools such as Rapid Miner. Each tool works in a
different language and provides some specifications. There are some popular and
commonly used Machine learning tools are as below :
1.Weka
2. KNIME
3.TensorFlow
4. PyTorch
5. Google Cloud ML Engine
6. Amazon Machine Learning (AML)
7. Accord.NET
8. Apache Mahout
9. Shogun
10. Oryx2
11. Apache Spark MLlib
12. Google ML kit for Mobile
2
Weka –
(Machine Learning Tool/Clustering Tool/Decision Tree Tool)
If you observe the beginning of the flow of the image, you will understand that
there are many stages in dealing with Big Data to make it suitable for machine
learning −
3
First, you will start with the raw data collected from the field. This data may
contain several null values and irrelevant fields. You use the data preprocessing
tools provided in WEKA to cleanse the data.
Then, you would save the preprocessed data in your local storage for applying ML
algorithms.
Next, depending on the kind of ML model that you are trying to develop you would
select one of the options such as Classify, Cluster, or Associate. The Attributes
Selection allows the automatic selection of features to create a reduced dataset.
Note that under each category, WEKA provides the implementation of several
algorithms. You would select an algorithm of your choice, set the desired
parameters and run it on the dataset.
Then, WEKA would give you the statistical output of the model processing. It
provides you a visualization tool to inspect the data.
The various models can be applied on the same dataset. You can then compare the
outputs of different models and select the best that meets your purpose.
Thus, the use of WEKA results in a quicker development of machine learning
models on the whole.
Now that we have seen what WEKA is and what it does, in the next chapter let us
learn how to install WEKA on your local computer.
Some of the key features of Weka are:
4
Features:
• Data preparation
• Classification
• Regression
• Clustering
• Visualization and
• Association rules mining.
Pros:
• Provides online courses for training.
• Easy to understand algorithms.
• It is good for students as well.
Cons:
• Not much documentation and online support are available.
Weka - Installation
To install WEKA on your machine, visit WEKA’s official website and download
the installation file. WEKA supports installation on Windows, Mac OS X and
Linux. You just need to follow the instructions on this page to install WEKA for
your OS.
The steps for installing on Mac are as follows −
• Download the Mac installation file.
• Double click on the downloaded weka-3-8-3-corretto-jvm.dmg file.
You will see the following screen on successful installation.
The GUI Chooser application allows you to run five different types of applications
as listed here −
• Explorer
• Experimenter
• KnowledgeFlow
• Workbench
• Simple CLI
6
On the top, you will see several tabs as listed here −
• Preprocess
• Classify
• Cluster
• Associate
• Select Attributes
• Visualize
Under these tabs, there are several pre-implemented machine learning algorithms.
Let us look into each of them in detail now.
Preprocess Tab
Initially as you open the explorer, only the Preprocess tab is enabled. The first
step in machine learning is to preprocess the data. Thus, in the Preprocess option,
you will select the data file, process it and make it fit for applying the various
machine learning algorithms.
Classify Tab
The Classify tab provides you several machine learning algorithms for the
classification of your data. To list a few, you may apply algorithms such as Linear
Regression, Logistic Regression, Support Vector Machines, Decision Trees,
RandomTree, RandomForest, NaiveBayes, and so on. The list is very exhaustive
and provides both supervised and unsupervised machine learning algorithms.
Cluster Tab
Under the Cluster tab, there are several clustering algorithms provided - such as
SimpleKMeans, FilteredClusterer, HierarchicalClusterer, and so on.
Associate Tab
Under the Associate tab, you would find Apriori, FilteredAssociator and
FPGrowth.
7
Select Attributes allows you feature selections based on several algorithms such
as ClassifierSubsetEval, PrinicipalComponents, etc.
Visualize Tab
Lastly, the Visualize option allows you to visualize your processed data for
analysis.
As you noticed, WEKA provides several ready-to-use algorithms for testing and
building your machine learning applications. To use WEKA effectively, you must
have a sound knowledge of these algorithms, how they work, which one to choose
under what circumstances, what to look for in their processed output, and so on. In
short, you must have a solid foundation in machine learning to use WEKA
effectively in building your apps.
Weka - Loading Data
We start with the first tab that you use to preprocess the data. This is common to
all algorithms that you would apply to your data for building the model and is a
common step for all subsequent operations in WEKA.
For a machine learning algorithm to give acceptable accuracy, it is important that
you must cleanse your data first. This is because the raw data collected from the
field may contain null values, irrelevant columns and so on.
In this chapter, you will learn how to preprocess the raw data and create a clean,
meaningful dataset for further use.
First, you will learn to load the data file into the WEKA explorer. The data can be
loaded from the following sources −
• Local file system
• Web
• Database
Here, we will see all the three options of loading data in detail.
Just under the Machine Learning tabs that you studied in the previous lesson, you
would find the following three buttons −
8
• Open file ...
• Open URL ...
• Open DB ...
Click on the Open file ... button. A directory navigator window opens as shown in
the following screen −
Now, navigate to the folder where your data files are stored. WEKA installation
comes up with many sample databases for you to experiment. These are available
in the data folder of the WEKA installation.
For learning purpose, select any data file from this folder. The contents of the file
would be loaded in the WEKA environment. We will very soon learn how to
inspect and process this loaded data. Before that, let us look at how to load the data
file from the Web.
Once you click on the Open URL ... button, you can see a window as follows −
9
We will open the file from a public URL Type the following URL in the popup
box −
https://storm.cis.fordham.edu/~gweiss/data-mining/weka-
data/weather.nominal.arff
You may specify any other URL where your data is stored. The Explorer will load
the data from the remote site into its environment.
Once you click on the Open DB ... button, you can see a window as follows −
10
Set the connection string to your database, set up the query for data selection,
process the query and load the selected records in WEKA.
Weka - File Formats
WEKA supports a large number of file formats for the data. Here is the complete
list −
• arff
• arff.gz
• bsi
• csv
• dat
• data
• json
• json.gz
• libsvm
• m
• names
• xrff
• xrff.gz
The types of files that it supports are listed in the drop-down list box at the bottom
of the screen. This is shown in the screenshot given below.
11
As you would notice it supports several formats including CSV and JSON. The
default file type is Arff.
Arff Format
• The @data tag starts the list of data rows each containing the comma
separated fields.
• The attributes can take nominal values as in the case of outlook shown
here −
@attribute outlook (sunny, overcast, rainy)
• The attributes can take real values as in this case −
−
@attribute play (yes, no)
• The Target assumes two nominal values yes or no.
Other Formats
The Explorer can load the data in any of the earlier mentioned formats. As arff is
the preferred format in WEKA, you may load the data from any format and save
it to arff format for later use. After preprocessing the data, just save it to arff format
for further analysis.
Now that you have learned how to load data into WEKA, in the next chapter, you
will learn how to preprocess the data.
Weka - Preprocessing the Data
The data that is collected from the field contains many unwanted things that leads
to wrong analysis. For example, the data may contain null fields, it may contain
columns that are irrelevant to the current analysis, and so on. Thus, the data must
be preprocessed to meet the requirements of the type of analysis you are seeking.
This is the done in the preprocessing module.
To demonstrate the available features in preprocessing, we will use
the Weather database that is provided in the installation.
Using the Open file ... option under the Preprocess tag select the weather-
nominal.arff file.
13
When you open the file, your screen looks like as shown here −
This screen tells us several things about the loaded data, which are discussed
further in this chapter.
Understanding Data
14
Let us first look at the highlighted Current relation sub window. It shows the
name of the database that is currently loaded. You can infer two points from this
sub window −
• There are 14 instances - the number of rows in the table.
• The table contains 5 attributes - the fields, which are discussed in the
upcoming sections.
On the left side, notice the Attributes sub window that displays the various fields
in the database.
The weather database contains five fields - outlook, temperature, humidity, windy
and play. When you select an attribute from this list by clicking on it, further details
on the attribute itself are displayed on the right hand side.
Let us select the temperature attribute first. When you click on it, you would see
the following screen −
15
In the Selected Attribute subwindow, you can observe the following −
• The name and the type of the attribute are displayed.
• The type for the temperature attribute is Nominal.
• The number of Missing values is zero.
• There are three distinct values with no unique value.
• The table underneath this information shows the nominal values for this
field as hot, mild and cold.
• It also shows the count and weight in terms of a percentage for each
nominal value.
At the bottom of the window, you see the visual representation of the class values.
If you click on the Visualize All button, you will be able to see all features in one
single window as shown here −
16
Removing Attributes
Many a time, the data that you want to use for model building comes with many
irrelevant fields. For example, the customer database may contain his mobile
number which is relevant in analysing his credit rating.
To remove Attribute/s select them and click on the Remove button at the bottom.
The selected attributes would be removed from the database. After you fully
preprocess the data, you can save it for model building.
Next, you will learn to preprocess the data by applying filters on this data.
17
Applying Filters
Some of the machine learning techniques such as association rule mining requires
categorical data. To illustrate the use of filters, we will use weather-
numeric.arff database that contains two numeric attributes
- temperature and humidity.
We will convert these to nominal by applying a filter on our raw data. Click on
the Choose button in the Filter subwindow and select the following filter −
weka→filters→supervised→attribute→Discretize
18
Let us look into another filter now. Suppose you want to select the best attributes
for deciding the play. Select and apply the following filter −
weka→filters→supervised→attribute→AttributeSelection
You will notice that it removes the temperature and humidity attributes from the
database.
After you are satisfied with the preprocessing of your data, save the data by
clicking the Save ... button. You will use this saved file for model building.
In the next chapter, we will explore the model building using several predefined
ML algorithms.
Weka - Classifiers
Many machine learning applications are classification related. For example, you
may like to classify a tumor as malignant or benign. You may like to decide
whether to play an outside game depending on the weather conditions. Generally,
this decision is dependent on several features/conditions of the weather. So you
may prefer to use a tree classifier to make your decision of whether to play or not.
In this chapter, we will learn how to build such a tree classifier on weather data to
decide on the playing conditions.
We will use the preprocessed weather data file from the previous lesson. Open the
saved file by using the Open file ... option under the Preprocess tab, click on
the Classify tab, and you would see the following screen −
19
Before you learn about the available classifiers, let us examine the Test options.
You will notice four testing options as listed below −
• Training set
• Supplied test set
• Cross-validation
• Percentage split
Unless you have your own training set or a client supplied test set, you would use
cross-validation or percentage split options. Under cross-validation, you can set
the number of folds in which entire data would be split and used during each
iteration of training. In the percentage split, you will split the data between training
and testing using the set split percentage.
Now, keep the default play option for the output class −
20
Next, you will select the classifier.
Selecting Classifier
21
Click on the Start button to start the classification process. After a while, the
classification results would be presented on your screen as shown here −
22
Let us examine the output shown on the right hand side of the screen.
It says the size of the tree is 6. You will very shortly see the visual representation
of the tree. In the Summary, it says that the correctly classified instances as 2 and
the incorrectly classified instances as 3, It also says that the Relative absolute error
is 110%. It also shows the Confusion Matrix. Going into the analysis of these
results is beyond the scope of this tutorial. However, you can easily make out from
these results that the classification is not acceptable and you will need more data
for analysis, to refine your features selection, rebuild the model and so on until you
are satisfied with the model’s accuracy. Anyway, that’s what WEKA is all about.
It allows you to test your ideas quickly.
Visualize Results
To see the visual representation of the results, right click on the result in the Result
list box. Several options would pop up on the screen as shown here −
Select Visualize tree to get a visual representation of the traversal tree as seen in
the screenshot below −
23
Selecting Visualize classifier errors would plot the results of classification as
shown here −
Now, try a different selection in each of these boxes and notice how the X & Y
axes change. The same can be achieved by using the horizontal strips on the right
hand side of the plot. Each strip represents an attribute. Left click on the strip sets
the selected attribute on the X-axis while a right click would set it on the Y-axis.
There are several other plots provided for your deeper analysis. Use them
judiciously to fine tune your model. One such plot of Cost/Benefit analysis is
shown below for your quick reference.
25
Explaining the analysis in these charts is beyond the scope of this tutorial. The
reader is encouraged to brush up their knowledge of analysis of machine learning
algorithms.
In the next chapter, we will learn the next set of machine learning algorithms, that
is clustering.
Weka - Clustering
A clustering algorithm finds groups of similar instances in the entire dataset.
WEKA supports several clustering algorithms such as EM, FilteredClusterer,
HierarchicalClusterer, SimpleKMeans and so on. You should understand these
algorithms completely to fully exploit the WEKA capabilities.
As in the case of classification, WEKA allows you to visualize the detected clusters
graphically. To demonstrate the clustering, we will use the provided iris database.
The data set contains three classes of 50 instances each. Each class refers to a type
of iris plant.
Loading Data
26
In the WEKA explorer select the Preprocess tab. Click on the Open file ... option
and select the iris.arff file in the file selection dialog. When you load the data, the
screen looks like as shown below −
You can observe that there are 150 instances and 5 attributes. The names of
attributes are listed
as sepallength, sepalwidth, petallength, petalwidth and class. The first four
attributes are of numeric type while the class is a nominal type with 3 distinct
values. Examine each attribute to understand the features of the database. We will
not do any preprocessing on this data and straight-away proceed to model building.
Clustering
Click on the Cluster TAB to apply the clustering algorithms to our loaded data.
Click on the Choose button. You will see the following screen −
27
Now, select EM as the clustering algorithm. In the Cluster mode sub window,
select the Classes to clusters evaluation option as shown in the screenshot below
−
Click on the Start button to process the data. After a while, the results will be
presented on the screen.
28
Next, let us study the results.
Examining Output
29
Next, we will look at the visual representation of the clusters.
Visualizing Clusters
To visualize the clusters, right click on the EM result in the Result list. You will
see the following options −
30
Select Visualize cluster assignments. You will see the following output −
31
As in the case of classification, you will notice the distinction between the correctly
and incorrectly identified instances. You can play around by changing the X and
Y axes to analyze the results. You may use jittering as in the case of classification
to find out the concentration of correctly identified instances. The operations in
visualization plot are similar to the one you studied in the case of classification.
To demonstrate the power of WEKA, let us now look into an application of another
clustering algorithm. In the WEKA explorer, select the HierarchicalClusterer as
your ML algorithm as shown in the screenshot shown below −
Choose the Cluster mode selection to Classes to cluster evaluation, and click on
the Start button. You will see the following output −
32
Notice that in the Result list, there are two results listed: the first one is the EM
result and the second one is the current Hierarchical. Likewise, you can apply
multiple ML algorithms to the same dataset and quickly compare their results.
If you examine the tree produced by this algorithm, you will see the following
output −
33
Here, you will study the Associate type of ML algorithms.
Weka - Feature Selection
When a database contains a large number of attributes, there will be several
attributes which do not become significant in the analysis that you are currently
seeking. Thus, removing the unwanted attributes from the dataset becomes an
important task in developing a good machine learning model.
You may examine the entire dataset visually and decide on the irrelevant attributes.
This could be a huge task for databases containing a large number of attributes like
the supermarket case that you saw in an earlier lesson. Fortunately, WEKA
provides an automated tool for feature selection.
This chapter demonstrate this feature on a database containing a large number of
attributes.
Loading Data
In the Preprocess tag of the WEKA explorer, select the labor.arff file for loading
into the system. When you load the data, you will see the following screen −
34
Notice that there are 17 attributes. Our task is to create a reduced dataset by
eliminating some of the attributes which are irrelevant to our analysis.
Features Extraction
Under the Attribute Evaluator and Search Method, you will find several
options. We will just use the defaults here. In the Attribute Selection Mode, use
full training set option.
Click on the Start button to process the dataset. You will see the following output
−
35
At the bottom of the result window, you will get the list of Selected attributes. To
get the visual representation, right click on the result in the Result list.
The output is shown in the following screenshot −
36
Clicking on any of the squares will give you the data plot for your further analysis.
A typical data plot is shown below −
This is similar to the ones we have seen in the earlier chapters. Play around with
the different options available to analyze the results.
You have seen so far the power of WEKA in quickly developing machine learning
models. What we used is a graphical tool called Explorer for developing these
models. WEKA also provides a command line interface that gives you more power
than provided in the explorer.
Clicking the Simple CLI button in the GUI Chooser application starts this
command line interface which is shown in the screenshot below −
37
Type your commands in the input box at the bottom. You will be able to do all that
you have done so far in the explorer plus much more. Refer to
WEKA documentation (https://www.cs.waikato.ac.nz/ml/weka/documentation.ht
ml) for further details.
Lastly, WEKA is developed in Java and provides an interface to its API. So if you
are a Java developer and keen to include WEKA ML implementations in your own
Java projects, you can do so easily.
38
KNIME
(Machine Learning Tool/Clustering Tool/Decision Tree Tool)
KNIME is a tool for data analytics, reporting and integration platform. Using the
data pipelining concept, it combines different components for machine learning
and data mining.
Features:
• It can integrate the code of programming languages like C, C++, R,
Python, Java, JavaScript etc.
• It can be used for business intelligence, financial data analysis, and
CRM.
Pros:
• It can work as a SAS alternative.
• It is easy to deploy and install.
• Easy to learn.
Cons:
• Difficult to build complicated models.
• Limited visualization and exporting capabilities.
KNIME - Introduction
Developing Machine Learning models is always considered very challenging due
to its cryptic nature. Generally, to develop machine learning applications, you must
be a good developer with an expertise in command-driven development. The
introduction of KNIME has brought the development of Machine Learning models
in the purview of a common man.
KNIME provides a graphical interface (a user friendly GUI) for the entire
development. In KNIME, you simply have to define the workflow between the
various predefined nodes provided in its repository. KNIME provides several
predefined components called nodes for various tasks such as reading data,
39
applying various ML algorithms, and visualizing data in various formats. Thus, for
working with KNIME, no programming knowledge is required. Isn’t this exciting?
The upcoming chapters of this tutorial will teach you how to master the data
analytics using several well-tested ML algorithms.
KNIME - Installation
KNIME Analytics Platform is available for Windows, Linux and MacOS. In this
chapter, let us look into the steps for installing the platform on the Mac. If you use
Windows or Linux, just follow the installation instructions given on the KNIME
download page. The binary installation for all three platforms is available
at KNIME’s page.
Mac Installation
Download the binary installation from the KNIME official site. Double click on
the downloaded dmg file to start the installation. When the installation completes,
just drag the KNIME icon to the Applications folder as seen here −
40
You may set the selected folder as default and the next time you launch KNIME,
it will not
41
As has been marked in the screenshot, the workbench consists of several views.
The views which are of immediate use to us are marked in the screenshot and listed
below −
• Workspace
• Outline
• Nodes Repository
• KNIME Explorer
• Console
• Description
As we move ahead in this chapter, let us learn these views each in detail.
Workspace View
The most important view for us is the Workspace view. This is where you would
create your machine learning model. The workspace view is highlighted in the
screenshot below −
The screenshot shows an opened workspace. You will soon learn how to open an
existing workspace.
42
Each workspace contains one or more nodes. You will learn the significance of
these nodes later in the tutorial. The nodes are connected using arrows. Generally,
the program flow is defined from left to right, though this is not required. You may
freely move each node anywhere in the workspace. The connecting lines between
the two would move appropriately to maintain the connection between the nodes.
You may add/remove connections between nodes at any time. For each node a
small description may be optionally added.
Outline View
The workspace view may not be able to show you the entire workflow at a time.
That is the reason, the outline view is provided.
The outline view shows a miniature view of the entire workspace. There is a zoom
window inside this view that you can slide to see the different portions of the
workflow in the Workspace view.
Node Repository
This is the next important view in the workbench. The Node repository lists the
various nodes available for your analytics. The entire repository is nicely
categorized based on the node functions. You will find categories such as −
43
• IO
• Views
• Analytics
Under each category you would find several options. Just expand each category
view to see what you have there. Under the IO category, you will find nodes to
read your data in various file formats, such as ARFF, CSV, PMML, XLS, etc.
Depending on your input source data format, you will select the appropriate node
for reading your dataset.
By this time, probably you have understood the purpose of a node. A node defines
a certain kind of functionality that you can visually include in your workflow.
44
The Analytics node defines the various machine learning algorithms, such as
Bayes, Clustering, Decision Tree, Ensemble Learning, and so on.
The first two categories list the workspaces defined on the KNIME server. The
third option LOCAL is used for storing all the workspaces that you create on your
local machine. Try expanding these tabs to see the various predefined workspaces.
Especially, expand EXAMPLES tab.
45
KNIME provides several examples to get you started with the platform. In the next
chapter, you will be using one of these examples to get yourself acquainted with
the platform.
Console View
As the name indicates, the Console view provides a view of the various console
messages while executing your workflow.
The Console view is useful in diagnosing the workflow and examining the
analytics results.
Description View
Toolbar
Besides the above described views, the workbench has other views such as toolbar.
The toolbar contains various icons that facilitate a quick action. The icons are
enabled/disabled depending on the context. You can see the action that each icon
performs by hovering mouse on it. The following screen shows the action taken
by Configure icon.
47
Enabling/Disabling Views
The various views that you have seen so far can be turned on/off easily. Clicking
the Close icon in the view will close the view. To reinstate the view, go to
the View menu option and select the desired view. The selected view will be added
to the workbench.
Now, as you have been acquainted with the workbench, I will show you how to
run a workflow and study the analytics performed by it.
KNIME - Running Your First Workflow
KNIME has provided several good workflows for ease of learning. In this chapter,
we shall pick up one of the workflows provided in the installation to explain the
various features and the power of analytics platform. We will use a simple
classifier based on a Decision Tree for our study.
48
Double click on the selected item to open the workflow. Observe the Workspace
view. You will see the workflow containing several nodes. The purpose of this
workflow is to predict the income group from the democratic attributes of the adult
data set taken from UCI Machine Learning Repository. The task of this ML model
is to classify the people in a specific region as having income greater or lesser than
50K.
The Workspace view along with its outline is shown in the screenshot below −
49
Notice the presence of several nodes picked up from the Nodes repository and
connected in a workflow by arrows. The connection indicates that the output of
one node is fed to the input of the next node. Before we learn the functionality of
each of the nodes in the workflow, let us first execute the entire workflow.
Executing Workflow
The status indicator is red indicating that this node has not been executed so far.
During the execution, the center circle which is yellow in color would light up. On
successful execution, the last circle turns green. There are more indicators to give
you the status information in case of errors. You will learn them when an error
occurs in the processing.
Note that currently the indicators on all nodes are red indicating that no node is
executed so far. To run all nodes, click on the following menu item −
Node → Execute All
50
After a while, you will find that each node status indicator has now turned green
indicating that there are no errors.
In the next chapter, we will explore the functionality of the various nodes in the
workflow.
KNIME - Exploring Workflow
If you check out the nodes in the workflow, you can see that it contains the
following −
• File Reader,
• Color Manager
• Partitioning
• Decision Tree Learner
• Decision Tree Predictor
• Score
• Interactive Table
• Scatter Plot
• Statistics
These are easily seen in the Outline view as shown here −
Each node provides a specific functionality in the workflow. We will now look
into how to configure these nodes to meet up the desired functionality. Please note
that we will discuss only those nodes that are relevant to us in the current context
of exploring the workflow.
File Reader
52
The Configure menu option allows for the node configuration.
The Execute menu runs the node. Note that if the node has already been run and
if it is in a green state, this menu is disabled. Also, note the presence of Edit Note
Description menu option. This allows you to write the description for your node.
Now, select the Configure menu option, it shows the screen containing the data
from the adult.csv file as seen in the screenshot here −
When you execute this node, the data will be loaded in the memory. The entire
data loading program code is hidden from the user. You can now appreciate the
usefulness of such nodes - no coding required.
Our next node is the Color Manager.
Color Manager
Select the Color Manager node and go into its configuration by right clicking on
it. A colors settings dialog would appear. Select the income column from the
dropdown list.
Your screen would look like the following −
53
Notice the presence of two constraints. If the income is less than 50K, the datapoint
will acquire green color and if it is more it gets red color. You will see the data
point mappings when we look at the scatter plot later in this chapter.
Partitioning
In machine learning, we usually split the entire available data in two parts. The
larger part is used in training the model, while the smaller portion is used for
testing. There are different strategies used for partitioning the data.
To define the desired partitioning, right click on the Partitioning node and select
the Configure option. You would see the following screen −
54
In the case, the system modeller has used the Relative (%) mode and the data is
split in 80:20 ratio. While doing the split, the data points are picked up randomly.
This ensures that your test data may not be biased. In case of Linear sampling, the
remaining 20% data used for testing may not correctly represent the training data
as it may be totally biased during its collection.
If you are sure that during data collection, the randomness is guaranteed, then you
may select the linear sampling. Once your data is ready for training the model, feed
it to the next node, which is the Decision Tree Learner.
The Decision Tree Learner node as the name suggests uses the training data and
builds a model. Check out the configuration setting of this node, which is depicted
in the screenshot below −
As you see the Class is income. Thus the tree would be built based on the income
column and that is what we are trying to achieve in this model. We want a
separation of people having income greater or lesser than 50K.
After this node runs successfully, your model would be ready for testing.
55
Decision Tree Predictor
The Decision Tree Predictor node applies the developed model to the test data set
and appends the model predictions.
The output of the predictor is fed to two different nodes - Scorer and Scatter Plot.
Next, we will examine the output of prediction.
Scorer
This node generates the confusion matrix. To view it, right click on the node. You
will see the following popup menu −
56
Click the View: Confusion Matrix menu option and the matrix will pop up in a
separate window as shown in the screenshot here −
57
It indicates that the accuracy of our developed model is 83.71%. If you are not
satisfied with this, you may play around with other parameters in model building,
especially, you may like to revisit and cleanse your data.
Scatter Plot
To see the scatter plot of the data distribution, right click on the Scatter Plot node
and select the menu option Interactive View: Scatter Plot. You will see the
following plot −
The plot gives the distribution of different income group people based on the
threshold of 50K in two different colored dots - red and blue. These were the colors
set in our Color Manager node. The distribution is relative to the age as plotted
on the x-axis. You may select a different feature for x-axis by changing the
configuration of the node.
The configuration dialog is shown here where we have selected the marital-
status as a feature for x-axis.
58
This completes our discussion on the predefined model provided by KNIME. We
suggest you to take up the other two nodes (Statistics and Interactive Table) in the
model for your self-study.
Let us now move on to the most important part of the tutorial – creating your own
model.
Creating Workflow
To create a new workflow, select the following menu option in the KNIME
workbench.
59
File → New
You will see the following screen −
Select the New KNIME Workflow option and click on the Next button. On the
next screen, you will be asked for the desired name for the workflow and the
destination folder for saving it. Enter this information as desired and
click Finish to create a new workspace.
A new workspace with the given name would be added to the Workspace view as
seen here −
60
You will now add the various nodes in this workspace to create your model.
Before, you add nodes, you have to download and prepare the iris dataset for our
use.
Preparing Dataset
Download the iris dataset from the UCI Machine Learning Repository
site Download Iris Dataset. The downloaded iris.data file is in CSV format. We
will make some changes in it to add the column names.
Open the downloaded file in your favorite text editor and add the following line at
the beginning.
sepal length, petal length, sepal width, petal width, class
When our File Reader node reads this file, it will automatically take the above
fields as column names.
Now, you will start adding various nodes.
Go to the Node Repository view, type “file” in the search box to locate the File
Reader node. This is seen in the screenshot below −
61
Select and double click the File Reader to add the node into the workspace.
Alternatively, you may use drag-n-drop feature to add the node into the workspace.
After the node is added, you will have to configure it. Right click on the node and
select the Configure menu option. You have done this in the earlier lesson.
The settings screen looks like the following after the datafile is loaded.
To load your dataset, click on the Browse button and select the location of your
iris.data file. The node will load the contents of the file which are displayed in the
lower portion of the configuration box. Once you are satisfied that the datafile is
located properly and loaded, click on the OK button to close the configuration
dialog.
You will now add some annotation to this node. Right click on the node and
select New Workflow Annotation menu option. An annotation box would appear
on the screen as shown in the screenshot here:
62
Click inside the box and add the following annotation −
Reads iris.data
Click anywhere outside the box to exit the edit mode. Resize and place the box
around the node as desired. Finally, double click on the Node 1 text underneath
the node to change this string to the following −
Loads data
At this point, your screen would look like the following −
We will now add a new node for partitioning our loaded dataset into training and
testing.
63
Adding Partitioning Node
64
Next, make the connection between the two nodes. To do so, click on the output
of the File Reader node, keep the mouse button clicked, a rubber band line would
appear, drag it to the input of Partitioning node, release the mouse button. A
connection is now established between the two nodes.
Add the annotation, change the description, position the node and annotation view
as desired. Your screen should look like the following at this stage −
65
Next, we will add the k-Means node.
Select the k-Means node from the repository and add it to the workspace. If you
want to refresh your knowledge on k-Means algorithm, just look up its description
in the description view of the workbench. This is shown in the screenshot below −
66
Incidentally, you may look up the description of different algorithms in the
description window before taking a final decision on which one to use.
Open the configuration dialog for the node. We will use the defaults for all fields
as shown here −
67
Next, we will add a Cluster Assigner node.
The Cluster Assigner assigns new data to an existing set of prototypes. It takes
two inputs - the prototype model and the datatable containing the input data. Look
up the node’s description in the description window which is depicted in the
screenshot below −
68
The Cluster Assigner does not need any special configuration. Just accept the
defaults.
Now, add some annotation and description to this node. Rearrange your nodes.
Your screen should look like the following −
69
the k-Means node first through the Color Manager node and then through Shape
Manager node.
Locate the Color Manager node in the repository. Add it to the workspace. Leave
the configuration to its defaults. Note that you must open the configuration dialog
and hit OK to accept the defaults. Set the description text for the node.
Make a connection from the output of k-Means to the input of Color Manager.
Your screen would look like the following at this stage −
Locate the Shape Manager in the repository and add it to the workspace. Leave
its configuration to the defaults. Like the previous one, you must open the
configuration dialog and hit OK to set defaults. Establish the connection from the
output of Color Manager to the input of Shape Manager. Set the description for
the node.
Your screen should look like the following −
70
Now, you will be adding the last node in our model and that is the scatter plot.
Locate Scatter Plot node in the repository and add it to the workspace. Connect
the output of Shape Manager to the input of Scatter Plot. Leave the configuration
to defaults. Set the description.
Finally, add a group annotation to the recently added three nodes
Annotation: Visualization
Reposition the nodes as desired. Your screen should look like the following at this
stage.
You would see the scatter plot on the screen as shown here −
72
You can run through different visualizations by changing x- and y- axis. To do so,
click on the settings menu at the top right corner of the scatter plot. A popup menu
would appear as shown in the screenshot below −
You can set the various parameters for the plot on this screen to visualize the data
from several aspects.
This completes our task of model building.
KNIME - Summary and Future Work
KNIME provides a graphical tool for building Machine Learning models. Here,
you learned how to download and install KNIME on your machine.
Summary
You learned the various views provided in the KNIME workbench. KNIME
provides several predefined workflows for your learning. We used one such
workflow to learn the capabilities of KNIME. KNIME provides several pre-
programmed nodes for reading data in various formats, analyzing data using
several ML algorithms, and finally visualizing data in many different ways.
Towards the end of the tutorial, you created your own model starting from scratch.
We used the well-known iris dataset to classify the plants using k-Means
algorithm.
By this way , You are now ready to use these techniques for your own analytics.
73
Decision Tree and Tools
(Weka and KNIME tools already explained above)
A decision tree is a flowchart that starts with one main idea — or question —
and branches out with potential outcomes of each decision. By using a decision
tree, you can identify the best possible course of action.
The visual element of a decision tree helps you include more potential actions and
outcomes than you might’ve if you just talked about it, mitigating risks of
unforeseen consequences.
Plus, the diagram allows you to include smaller details and create a step-by-step
plan, so once you choose your path, it’s already laid out for you to follow.
A decision tree contains four elements: the root node, decision nodes, leaf nodes,
and branches that connect them together.
• The root node is where the tree starts. It's the big issue or decision you are
addressing.
• As the name suggests, the decision nodes represent a decision in your tree.
you're deciding where to eat for lunch, a potential decision node is eat a
74
hamburger at McDonald's. A corresponding leaf node could be: Save money
by spending less than $5.
• Branches are the arrows that connect each element in a decision tree.
Follow the branches to understand the risks and rewards of each decision.
Now let's explore how to read and analyze the decisions in the tree.
For the sake of simplicity, we’ll assume both options appeal to your ideal
demographic and make sense for your brand.
Here’s a preliminary decision tree you’d draw for your advertising campaign:
As you can see, you want to put your ultimate objective at the top — in this
case, Advertising Campaign is the decision you need to make.
Next, you’ll need to draw arrows (your branches) to each potential action you
could take (your leaves).
For our example, you only have two initial actions to take: Facebook Paid Ads, or
Instagram Sponsorships. However, your tree might include multiple alternative
options depending on the objective.
75
Now, you’ll want to draw branches and leaves to compare costs. If this were the
final step, the decision would be obvious: Instagram costs $10 less, so you’d likely
choose that.
However, that isn't the final step. You need to figure out the odds for success versus
failure. Depending on the complexity of your objective, you might examine
existing data in the industry or from prior projects at your company, your team’s
capabilities, budget, time-requirements, and predicted outcomes. You might also
consider external circumstances that could affect success.
Instagram, on the other hand, has an ROI of $900. If you fail, you risk losing $50.
To evaluate risk versus reward, you need to find out Expected Value for both
avenues. Here’s how you’d figure out your Expected Value:
• Take your predicted success (50%) and multiply it by the potential amount
of money earned ($1000 for Facebook). That’s 500.
• Then, take your predicted chance of failure (50%) and multiply it by the
amount of money lost (-$200 for Facebook). That’s -100.
• Add those two numbers together. Using this formula, you’ll see Facebook’s
Expected Value is 400, while Instagram’s Expected Value is 425.
With this predictive information, you should be able to make a better, more
confident decision — in this case, it looks like Instagram is a better option. Even
though Facebook has a higher ROI, Instagram has a higher Expected Value, and
you risk losing less money.
76
1. Define your main idea or question.
The first step is identifying your root node. This is the main issue, question, or idea
you want to explore. Write your root node at the top of your flowchart.
5. Evaluate outcomes.
The last step is evaluating outcomes. In this step, you are determining which
decision is most ideal based on the amount of risk you're willing to take.
77
Remember, the highest-value decision may not be the best course of action. Why?
Although it comes with a high reward, it may also bring a high level of risk.
It's up to you — and your team — to determine the best outcome based on your
budget, timeline, and other factors.
For instance, perhaps you’re deciding whether your small startup should merge
with a bigger company. In this case, there could be math involved, but your
decision tree might also include more quantitative questions, like: Does this
company represent our brand values? Yes/No. Do our customers benefit from the
merge? Yes/No.
To clarify this point, let’s take a look at some diverse decision tree examples.
78
Decision trees are a popular type of supervised learning algorithm that builds
classification or regression models in the shape of a tree (that’s why they are also
known as regression and classification trees). They work for both categorical
data and continuous data.
Here best open source license classification tree software solutions that run on
Windows, Linux, and Mac OS X.
1. Weka
2. KNIME
3. Rapid Miner
4. SilverDecisions
5. Orange
6. Rattle
7. SMILES
8. Scikit-learn
9. OC1 Decision Tree Software System
10. Simple Decision Tree
1. Weka
This is a Java-based free and open source tool for Windows, Linux, and Mac OS
X. Weka is a powerful collection of machine learning algorithms for data mining
purposes.
The algorithms can be applied directly to a dataset as well as called from Java
code. Weka contains tools for classification, regression, visualization and
clustering, and association rules.
Moreover, Weka has free online courses that teach machine learning and data
mining using Weka.
79
2. KNIME
KNIME Analytics Platform is one of the best open solutions for data-driven
innovation. The platform is fast to deploy, easy to scale, and very intuitive to learn.
KNIME will provide you with 1500 modules, hundreds of ready-to-run examples
(including decision tree examples), a variety of integrated tools, and an extremely
wide choice of advanced algorithms. Great software for any data scientist.
3. Rapid Miner
This is a very powerful and popular data mining software solution which provides
you with predictive advanced analytics. And it is one of the best open source
decision tree software tool with no-coding required.
Written in Java, it holds a variety of data mining functions such as visualization,
data pre-processing, cleansing, filtering, clustering, and predictive analysis. Its
Decision Tree operator generates a decision tree model, which can be used for
classification and regression.
Also, it is easily integrated with WEKA.
80
Rapid Miners runs on Windows, Linux, and Mac OSX.
4. SilverDecisions
SilverDecisions is a free and open source decision tree software with a great set of
layout options. It is a specialized software for creating and analyzing decision
trees.
The decision tree can be easily exported to JSON, PNG or SVG format.
In addition, they will provide you with a rich set of examples of decision trees in
different areas such as research and development project decision tree, city council
management software and etc.
5. Orange
81
Orange is a free and open source data visualization software and machine learning
tool for novice and expert. Orange will surprise you!
It allows you to explore statistical distributions, box and whisker plots, scatter
plots, or dive much deeper with decision trees, heatmaps, MDS, hierarchical
clustering, and linear regression models.
In addition, Orange graphic user interface allows you to focus on exploratory data
analysis instead of coding. Orange is used for teaching at schools, universities and
in professional training courses all over the world.
10. Rattle
Rattle is a popular GUI for data mining using R. It is also a great solution when it
comes to open source decision tree software. The tool runs on Linux, Mac OS, and
Windows.
82
Rattle is a powerful tool that presents statistical and visual summaries of data,
builds both unsupervised and supervised machine learning models from the data,
presents the performance of models graphically and etc.
Except for business and commercial enterprises purposes, Rattle is used also for
teaching in Australian and American universities.
In addition, Rattle has a number of decision tree examples you can use.
Artificial Neural network software apply concepts adapted from biological neural
networks, artificial intelligence and machine learning and is used to simulate,
research, develop Artificial Neural network. Neural network simulators are
software applications that are used to simulate the behavior of artificial or
biological neural networks which focus on one or a limited number of specific
types of neural networks.
They are typically stand-alone and not intended to produce general neural
networks that can be integrated in other software. Simulators usually have some
form of built-in visualization to monitor the training process and some simulators
also visualize the physical structure of the neural network. In order for neural
network models to be shared by different applications, Predictive Model Markup
Language (PMML) is used. PMML is an XML-based language which provides a
way for applications to define and share neural network models and other data
mining models between PMML compliant application.
83
What are Artificial Neural Network Tools (Software)?
With these models, you can easily discover relationships, recognize patterns and
make predictions.
The graphical user interface lets teams run and view tasks using charts, tables, or
graphs, build predictive models, and make complex operations.
Key features of Neural Designer include data mining, data visualization, model
training, and predictive analytics.
Engineers can use the platform to monitor system behavior, identify the occurrence
of faults, predict equipment failure, and improve product quality using predictive
analytics.
Neural Designer enables the healthcare sector to use machine learning technology
to study environmental influence, genetic factors, and physiological data to treat
diseases effectively. In addition, it facilitates drug design, letting physicians
predict the behavior of a molecule and its characteristics.
Neural Designer helps retailers collect customer data and use artificial intelligence
to streamline sales forecasting and client targeting.
85
Key benefits of using Neural Designer
- Easy to use: Neural Designer follows a very well-defined protocol for building
neural network models and has an intuitive graphical user interface. This allows
you to develop AI-powered applications without programming or building block
diagrams.
2.Neuroph
Neuroph is an object-oriented artificial neural network framework written
in Java. It can be used to create and train neural networks in Java programs.
86
Neuroph provides Java class library as well as GUI tool easyNeurons for creating
and training neural networks.
It is an open-source project hosted at SourceForge under the Apache License.
Versions before 2.4 were licensed under LGPL 3, from this version the license is
Apache 2.0 License.
Neuroph is an open-source project hosted at SourceForge under the Apache
License. It is a library for creating neural networks and utilizing machine learning.
Neuroph is a lightweight Java neural network framework to develop common
neural network architectures.
Users can interact with Neuroph using :
• A GUI-based tool
• A Java library Both approaches rely on an underlying class hierarchy which
builds artificial neural networks out of layers of neurons.
Neuroph contains has nice GUI neural network editor to quickly create Java neural
network components. The software simplifies the development of a neural network
by providing Java neural network library and GUI tool that supports creating,
training and saving neural networks.
Features
• Neuroph's core classes correspond to basic neural network concepts
like artificial neuron, neuron layer, neuron connections, weight, transfer
function, input function, learning rule etc.
• Neuroph supports common neural network architectures such as Multilayer
perceptron with Backpropagation, Kohonen and Hopfield networks.
• All these classes can be extended and customized to create custom neural
networks and learning rules. Neuroph has built-in support for image
recognition.
3.Darknet
Darknet is an open-source neural network framework written in C and CUDA and
supports CPU and GPU computation. It is a convolutional neural network that is
nineteen layers deep. The pretrained network can classify images into 1000 object
87
categories such as keyboard, mouse, pencil and many animals. As a result, the
network has learned rich feature representation for a wide range of images.
Darknet is installed with only two optional dependencies like OpenCV if users
want a wider variety of support image types or CUDA if they want GPU
computation. The users can start by just installing the base system which has only
been tested on Linux and Mac computers.
4.Keras
Keras is a deep learning library for Theano and TensorFlow. The high-level neural
networks library is written in Python and capable of running on the top of both
applications. Keras is an API designed for human beings, not machines. The
software follows best practices for reducing cognitive load. It offers consistent and
simple APIs and minimizes the number of user actions required for common use
cases. Keras provides clear and actionable error messages and has extensive
documentation and developer guides. Keras deep learning library allows easy and
fast prototyping through total modularity, minimalism, and extensibility. It
supports convolutional neural networks and recurrent networks, as well as
combinations of the two.
5.NeuroSolutions
NeuroSolutions is a neural network software development environment designed
by NeuroDimension. It combines a modular, icon-based network design interface
with an implementation of advanced learning procedures, such as conjugate
gradients, Levenberg Marquardt and backpropagation through time.
NeuroSolutions product family is leading-edge neural network software for data
mining to create highly accurate and predictive models using advanced processing
techniques, intelligent automated neural network topology search through cutting-
edge distributed computing. It is a design interface with advanced artificial
intelligence and learning algorithms using intuitive wizards or an easy-to-use
Excel interface.
The software provides three separate wizards for automatically building neural
network models : • Data Manager • Neural Builder • Neural Expert
88