Automated Rules in Fuzzy Expert System by Apriori Algorithm; Rules generation in Python

The Fuzzy expert system is an expert system, that works like an expert in a particular field of work, helps solves problem specific to that field, this can be anything in domain of expert systems, so defined. Typically, expert systems are made with help of the experts in a particular field, since a machine needs to get the power of expert in field hence, the expert system needs to be made with precision. At times, framing perfect rules for system are not easy, for example, in information retrieval based expert system, one need to be exact in definition of rule defining the relation between whether a document is important or not based on similarity of query and document. In this case how much should be the similarity be, what other parameters to measure. The exact membership may not be computed manually by even the experts in this case. In this case the experts can take help of automated rule generation, as is explained in this article. However, in case of medicine the exact amount should be added by help of expert doctors and medical logbooks.

The Fuzzy Inference Engine, of Expert Systems depends on Rules. Fuzzy Inference Engine works on rules, and predefined values of parameters. Many researchers use approximate rule bases which are hand made by the researcher themselves. The researcher or expert of the system makes rules, based on his knowledge of the system and problem both. There are various advantageous to asking experts in the field to make rules, but automatically generating rule base can at times fully replace the need for expert system works and at times, these automated systems can generate rules which the experts can study, pass and use in the Expert Systems. Other uses of these rules generated in Apriori algorithm can be, in verfying the Expert System to even using the knowledge in other expert system. Further, Apriori algorithm provides opportunities to study these rules, given not all rule have full confidence, so this can depend on some ratio on manual work of freezing the decision rules.

The Python Code is here, for experts to generate their automated rules to be used in Expert Systems as a guide.

Apriori generate the rules based on maximum or frequent itemsets in the data.

import numpy as np
import pandas as pd
from mlxtend.frequent_patterns import apriori, association_rules
import numpy as np
import pandas as pd
import random
import os

data = pd.read_csv('/content/AproiriDataCSV_Binary.csv')
data.head()
basket = data

The above code reads the data file and adds it in basket

def encode_DATA(x):
if(x< 10):
return 0
if(x>= 10):
return 1

basket = pd.DataFrame(columns=['Col1','Col2','Col3', 'Col4'])

basket['Col1'] = basket_intermediate['Col1'].apply(encode_DATA)
basket['Col2'] = basket_intermediate['Col2'].apply(encode_DATA)
basket['Col3'] = basket_intermediate['Col3'].apply(encode_DATA)
basket['Col4'] = basket_intermediate['Col4'].apply(encode_DATA)

basket.head()

.The above code encodes the basket data to discretized form and gives following sample output

The following data generates the rules

FreuquentItemSets = apriori(basket, min_support = 0.05, use_colnames = True)
RuleSet = association_rules(FreuquentItemSets, metric ="lift", min_threshold = 1)
RuleSet = RuleSet.sort_values(['confidence', 'lift'], ascending =[False, False])
print(RuleSet.head())

The output is as follows:

Published by Nidhika

Hi, Apart from profession, I have inherent interest in writing especially about Global Issues of Concern, fiction blogs, poems, stories, doing painting, cooking, photography, music to mention a few! And most important on this website you can find my suggestions to latest problems, views and ideas, my poems, stories, novels, some comments, proposals, blogs, personal experiences and occasionally very short glimpses of my research work as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: