Table Of ContentData Science
Using Oracle
Data Miner and
Oracle R Enterprise
Transform Your Business Systems
into an Analytical Powerhouse
—
Sibanjan Das
Data Science Using
Oracle Data
Miner and Oracle R
Enterprise
Transform Your Business Systems
into an Analytical Powerhouse
Sibanjan Das
Data Science Using Oracle Data Miner and Oracle R Enterprise
Sibanjan Das
Pune, Maharashtra, India
ISBN-13 (pbk): 978-1-4842-2613-1 ISBN-13 (electronic): 978-1-4842-2614-8
10.1007/978-1-4842-2614-8
Copyright © 2016 by Sibanjan Das
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole
or part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical
way, and transmission or information storage and retrieval, electronic adaptation, computer
software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the
date of publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Managing Director: Welmoed Spahr
Lead Editor: Celestin Suresh John
Technical Reviewer: Ajit Jaokar
Editorial Board: Steve Anglin, Pramila Balan, Laura Berendson, Aaron Black,
Louise Corrigan, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John,
Nikhil Karkal, James Markham, Susan McDermott, Matthew Moodie, Natalie Pao,
Gwenan Spearing
Coordinating Editor: Prachi Mehta
Copy Editor: Deanna Hegle
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233
Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
e-mail
I dedicate this book
To my parents, grandparents, sisters, brothers, and brothers-in-law
who motivated me to do what I always wanted to do
To my Wife and six-month old son Sachit for their love and care
To my mentors and Coaches Karthik Krishna Jonnalagadha,
John Kopchak, Prabir Sen, Bibhudatta Ghadei, Harishchandra Rakh, and
Nirmal Babu who has enriched my life with guidance and lessons
that help me to be a better technocrat and person every day.
Contents at a Glance
About the Author ���������������������������������������������������������������������������� xiii
About the Technical Reviewer ��������������������������������������������������������� xv
Acknowledgments ������������������������������������������������������������������������� xvii
Introduction ������������������������������������������������������������������������������������ xix
■ Chapter 1: Getting Started With Oracle Advanced Analytics ���������� 1
■ Chapter 2: Installation and Hello World ���������������������������������������� 35
■ Chapter 3: Clustering Methods ����������������������������������������������������� 75
■ Chapter 4: Association Rules ������������������������������������������������������ 117
■ Chapter 5: Regression Analysis �������������������������������������������������� 147
■ Chapter 6: Classifcation Methods ���������������������������������������������� 189
■ Chapter 7: Advanced Topics ������������������������������������������������������� 239
■ Chapter 8: Solutions Deployment ����������������������������������������������� 267
Index ���������������������������������������������������������������������������������������������� 285
v
Contents
About the Author ���������������������������������������������������������������������������� xiii
About the Technical Reviewer ��������������������������������������������������������� xv
Acknowledgments ������������������������������������������������������������������������� xvii
Introduction ������������������������������������������������������������������������������������ xix
■ Chapter 1: Getting Started With Oracle Advanced Analytics ���������� 1
Data Science ������������������������������������������������������������������������������������������� 2
Business Understanding ������������������������������������������������������������������������������������������� 3
Data Understanding �������������������������������������������������������������������������������������������������� 3
Data Preparation ������������������������������������������������������������������������������������������������������� 3
Modeling ������������������������������������������������������������������������������������������������������������������� 3
Evaluation ����������������������������������������������������������������������������������������������������������������� 3
Deployment��������������������������������������������������������������������������������������������������������������� 3
Machine Learning ������������������������������������������������������������������������������������ 4
Supervised Learning ������������������������������������������������������������������������������������������������� 5
Unsupervised Learning ��������������������������������������������������������������������������������������������� 5
Getting Started with Oracle Advanced Analytics ������������������������������������� 6
Oracle Data Miner ����������������������������������������������������������������������������������������������������� 8
R Technologies in Oracle ����������������������������������������������������������������������� 15
Oracle R Enterprise ������������������������������������������������������������������������������������������������� 15
Advantages of using Oracle R Enterprise ��������������������������������������������������������������� 17
Analytical SQL and PLSQL Functions ����������������������������������������������������� 18
Package DBMS_STATS_FUNC �������������������������������������������������������������������������������� 18
SQL Functions ��������������������������������������������������������������������������������������������������������� 22
Summary ����������������������������������������������������������������������������������������������� 33
vii
■ Contents
■ Chapter 2: Installation and Hello World ���������������������������������������� 35
Booting Up Oracle Data Miner ��������������������������������������������������������������� 36
Installation Prerequisites ���������������������������������������������������������������������������������������� 36
Installation �������������������������������������������������������������������������������������������������������������� 36
Welcome to the World—Oracle Data Miner ������������������������������������������������������������ 48
SQL Developer Components for ODM ���������������������������������������������������� 54
ODM Data Dictionary ����������������������������������������������������������������������������� 59
Boot Up Oracle R Enterprise ������������������������������������������������������������������ 59
Prerequisites����������������������������������������������������������������������������������������������������������� 60
Oracle R Distribution ����������������������������������������������������������������������������������������������� 60
Oracle R Enterprise Server Installation ������������������������������������������������������������������� 65
Oracle R Enterprise Client Installation �������������������������������������������������������������������� 67
Install Supporting Packages for the ORE Client ������������������������������������������������������ 70
Welcome to the World of Oracle R Enterprise ��������������������������������������������������������� 71
ORE Data Dictionary ������������������������������������������������������������������������������ 73
Summary ����������������������������������������������������������������������������������������������� 74
■ Chapter 3: Clustering Methods ����������������������������������������������������� 75
Clustering Approaches �������������������������������������������������������������������������� 76
The k-means Algorithm ������������������������������������������������������������������������� 77
k-means in Oracle Advanced Analytics ������������������������������������������������������������������ 80
Clustering Rules Evaluation Metrics ����������������������������������������������������������������������� 81
Parameters to Tune k-means Clustering ���������������������������������������������������������������� 81
Creating a Cluster Model in Oracle Advanced Analytics ������������������������ 82
Clustering using SQL and PLSQL ���������������������������������������������������������������������������� 83
Case Study—Customer Segmentation �������������������������������������������������� 93
Business understanding ����������������������������������������������������������������������������������������� 94
Data understanding ������������������������������������������������������������������������������������������������ 94
viii
■ Contents
RFM Segmentation—Data Preparation ������������������������������������������������������������������ 95
RFM Segmentation—DATA Modeling �������������������������������������������������������������������� 97
Need-Based Segmentation—Data Preparation ���������������������������������������������������� 100
Need-Based Segmentation—Data Modeling ������������������������������������������������������ 106
Result Evaluation �������������������������������������������������������������������������������������������������� 108
Deployment—Storing the Results Back to the Database ������������������������������������� 110
Assigning Segments to New Customers��������������������������������������������������������������� 114
Summary ��������������������������������������������������������������������������������������������� 115
■ Chapter 4: Association Rules ������������������������������������������������������ 117
Introduction to Association Rules �������������������������������������������������������� 118
Terminologies Associated with Association Rules ������������������������������� 118
Working of an Apriori Algorithm ���������������������������������������������������������� 120
Identify Interesting Rules �������������������������������������������������������������������� 122
Algorithm Settings ������������������������������������������������������������������������������� 123
Model Settings ������������������������������������������������������������������������������������ 123
Association Rules Using SQL and PLSQL��������������������������������������������� 124
Creating the Association Rules Model Using Oracle R Enterprise ������� 127
Creating the Association Model Using SQL Developer ������������������������ 130
Case Study—Market Basket Analysis ������������������������������������������������� 134
Business Understanding ��������������������������������������������������������������������������������������� 135
Data Understanding ���������������������������������������������������������������������������������������������� 135
Data Preparation ��������������������������������������������������������������������������������������������������� 136
Data Modeling ������������������������������������������������������������������������������������������������������ 136
High-Level Technical Overview ����������������������������������������������������������������������������� 137
Execution �������������������������������������������������������������������������������������������������������������� 143
Summary ��������������������������������������������������������������������������������������������� 145
ix
■ Contents
■ Chapter 5: Regression Analysis �������������������������������������������������� 147
Understanding Relationships �������������������������������������������������������������� 148
Regression Analysis ���������������������������������������������������������������������������� 151
Working of OLS Regression ����������������������������������������������������������������� 152
Assumptions of OLS ���������������������������������������������������������������������������� 153
OLS Regression in Oracle Advanced Analytics ������������������������������������ 154
GLM Regression ���������������������������������������������������������������������������������� 160
Ridge Regression �������������������������������������������������������������������������������� 161
Parameters to Tune the GLM Model ���������������������������������������������������������������������� 161
GLM and Ridge Regression in Oracle Advanced Analytics ������������������ 162
GLM Regression Using SQL and PLSQL ����������������������������������������������� 162
Creating GLM Regression Using Oracle R Enterprise �������������������������� 166
Creating GLM and Ridge Regression from SQL Developer ������������������ 168
Guidelines for Regression Modeling ��������������������������������������������������������������������� 174
Case Study: Sales Forecasting ������������������������������������������������������������ 175
Business Understanding ��������������������������������������������������������������������������������������� 176
Data Understanding ���������������������������������������������������������������������������������������������� 176
Data Preparation ��������������������������������������������������������������������������������������������������� 177
Data Modeling ������������������������������������������������������������������������������������������������������ 179
Summary ��������������������������������������������������������������������������������������������� 187
■ Chapter 6: Classifcation Methods ���������������������������������������������� 189
Overview of Classifcation Techniques ������������������������������������������������ 190
Logistic Regression ����������������������������������������������������������������������������� 190
Naïve Bayes ����������������������������������������������������������������������������������������� 193
Creating a Naïve Bayes Model Using SQL and PLSQL ������������������������������������������ 195
Creating a Naïve Bayes Classifer Using Oracle R Enterprise ������������������������������� 198
Assessing the Model Quality for Classifers ���������������������������������������� 201
x
■ Contents
Decision Trees ������������������������������������������������������������������������������������� 203
Entropy and Information Gain ������������������������������������������������������������������������������� 204
Information Gain ��������������������������������������������������������������������������������������������������� 205
Pruning Methods/Early Stopping Criteria for Decision Trees �������������������������������� 206
Parameters to Tune a Decision Tree Model ����������������������������������������������������������� 207
Decision Tree Modeling Using SQL and PLSQL ����������������������������������������������������� 208
Decision Tree Modeling Using Oracle R Enterprise ����������������������������������������������� 210
SVM ����������������������������������������������������������������������������������������������������� 211
Parameters to Tune the SVM Model ���������������������������������������������������������������������� 214
SVM Using SQL and PLSQL ����������������������������������������������������������������������������������� 215
SVM Using Oracle R Enterprise ����������������������������������������������������������������������������� 218
A Few Other Important PLSQL APIs for Classifers ������������������������������ 219
Choosing a Classifer ��������������������������������������������������������������������������� 221
Case Study: Customer Churn Prediction���������������������������������������������� 222
Business Understanding ��������������������������������������������������������������������������������������� 222
Data Understanding ���������������������������������������������������������������������������������������������� 222
Data Preparation ��������������������������������������������������������������������������������������������������� 223
Data Modeling ������������������������������������������������������������������������������������������������������ 227
Selecting the Best Classifer ��������������������������������������������������������������������������������� 229
Results Interpretation ������������������������������������������������������������������������������������������� 236
Summary ��������������������������������������������������������������������������������������������� 237
■ Chapter 7: Advanced Topics ������������������������������������������������������� 239
Overview of Neural Networks� ������������������������������������������������������������� 240
Function of a Hidden Layer Neuron ���������������������������������������������������������������������� 241
Parameters for Neural Network ���������������������������������������������������������������������������� 242
Neural Network Using Oracle Advanced Analytics ������������������������������ 244
xi