The Data Mining Forum                             open-source data mining software data mining conferences Data Science for Social and Behavioral Analytics DSSBA 2022 data science journal
IMPORTANT: This is the old Data Mining forum.
I keep it online so that you can read the old messages.

Please post your new messages in the new forum: https://forum2.philippe-fournier-viger.com/index.php
 
Using SPMF from Python to mine patterns and rules?
Posted by: Ying
Date: January 07, 2019 07:03AM

Hello there. Can I used the SPMF software from the Python programs?

Options: ReplyQuote
Re: Using SPMF from Python to mine patterns and rules?
Posted by: vrodriguezf
Date: January 09, 2019 02:07AM

Hi,

The easiest way is just make system calls to the command line version of SPMF from your Python program.

Best!

Options: ReplyQuote
Re: Using SPMF from Python to mine patterns and rules?
Posted by: LSatterfield
Date: February 15, 2019 10:02AM

When calling from python it's easiest in my opinion to do something like this:

import subprocess

# -Xmx1024m specifies to use 1 gb of memory for the java vm.
jar_call = f'java -Xmx1024m -jar spmf.jar run {algorithm} {input}.txt {output_file} ' \
f'{param1} {param2}'

jar_call = jar_call.split()
#This calls the SPMF JAR file
subprocess.call(jar_call)

Then You can read back in the file with something like this
Im using FCHM Bond so for that example the code could look something like this.

import pandas as pd

df = pd.read_csv(output_file, header=None, sep='\n', names=['rules'])

#Convert to a dataframe
df['rules'] = df['rules'].apply(lambda x: x.replace(' #UTIL: ', ' ').replace('
#BOND: ', ' '))
df = df['rules'].str.split(expand=True, n=2)
df.columns = ['Basket', 'Utility', 'Bond']
df['Items'] = seq['Basket'].str.split(',')



I hope this helps! It may not be the fastest or smartest way to read this into python but I use something similar to this.

Options: ReplyQuote


This forum is powered by Phorum and provided by P. Fournier-Viger (© 2012).
Terms of use.