DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

MachineX: Association Rule Learning With KSAI

Let's use Association Rule Learning to actually see it in action, and for this purpose, we are going to use KSAI, a Machine Learning library purely written in Scala.

Akshansh Jain user avatar by
Akshansh Jain
·
Sep. 12, 18 · Tutorial
Like (1)
Save
Tweet
Share
2.98K Views

Join the DZone community and get the full member experience.

Join For Free

In many of my previous articles, I have posted about Association Rule Learning, what it's about, and how it is performed. In this article, we are going to use Association Rule Learning to actually see it in action, and for this purpose, we are going to use KSAI, a machine learning library purely written in Scala. So, let's begin.

Adding KSAI to Your Project

You can add KSAI in your SBT project using the following import line:

libraryDependencies += "io.github.knolduslabs" %% "ksai" % "0.0.4"

Or, you can add KSAI in your Maven project by using the following:

<dependency>
    <groupId>io.github.knolduslabs</groupId>
    <artifactId>ksai_2.12</artifactId>
    <version>0.0.4</version>
</dependency>

Using KSAI for Association Rule Learning

I'll be using the data file kosarak.dat for demonstrating the application. I will also be including this file in the GitHub repository that will be provided below so that you guys can also play around with it.

To use the algorithm, you will first need to create an ARM object. For that, you need to parse your data into an Array[Array[Int]]. The below-given code is what I use to perform the same.

val data: Array[Array[Int]] =
  Source.fromFile(getClass.getResource("/kosarak.dat").getPath)
    .getLines()
    .map(_.split(" ").map(_.toInt))
    .toArray

Awesome! Now we can create the ARM object. We do this as follows:

val arm = ARM(data, 0.003)

Now we gotta generate the rules, for which we can simply call the learn method of the ARM. We get something like below -

val eventualResults = arm.learn(0.5)

What's 0.003 and 0.5? That's the minimum support and confidence that we are going to use. Don't know about them? Then you must check out my previous articles, which explain in depth about what they are and what their value should be.

To see all the rules that are generated, we can simply print them out as below:

eventualResults.map(array => array.foreach(rule => println(rule)))

And we will be able to see all the rules, with the support and confidence, on the console.

You can get the code and the data file used in this example here.

That's it for this article! You can find many more interesting algorithms in KSAI right here.

Thanks for reading, and let me know your thoughts in the comments section. 

Data file

Published at DZone with permission of Akshansh Jain, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Tackling the Top 5 Kubernetes Debugging Challenges
  • MongoDB Time Series Benchmark and Review
  • Best Practices for Setting up Monitoring Operations for Your AI Team
  • 4 Best dApp Frameworks for First-Time Ethereum Developers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: