DS15
Q. 1) Write Ajax program to fetch suggestions when is user is typing in a textbox. (eg like google
suggestions. Hint create array of suggestions and matching string will be displayed) [Marks 15]
Q. 2)Create the following dataset in python & Convert the categorical values into numeric format.Apply
the apriori algorithm on the above dataset to generate the frequent itemsets and association rules. Repeat
the process with different min_sup values
from mlxtend.frequent_patterns import apriori, association_rules
import pandas as pd
Create the dataset
data = {'TID': [1, 2, 3, 4],
'Items': [['apple', 'mango', 'banana'],
['mango', 'banana', 'orange'],
['mango', 'banana', 'orange'],
['apple', 'orange']]}
Convert the dataset into a DataFrame
df = pd.DataFrame(data)
Convert categorical values into numeric format using one-hot encoding
data_encoded = pd.get_dummies(df['Items'].apply(pd.Series).stack()).sum(level=0)
Apply the Apriori algorithm with different min_sup values
min_support_values = [0.2, 0.3] # Different min_sup values
for min_support in min_support_values:
frequent_itemsets = apriori(data_encoded, min_support=min_support, use_colnames=True)
print(f"\nFrequent itemsets with min_sup={min_support}:\n")
print(frequent_itemsets)
# Generate association rules
rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.5)
print(f"\nAssociation rules with min_sup={min_support}:\n")
print(rules)