DS11
Q. 1) Write a Javascript program to accept name of student, change font color to red, font size to 18 if
student name is present otherwise on clicking on empty text box display image which changes its size
(Use onblur, onload, onmousehover, onmouseclick, onmouseup) [Marks 15]
if (name !== '') {
// Change font color to red and font size to 18
document.getElementById('studentName').style.color = 'red';
document.getElementById('studentName').style.fontSize = '18px';
} else {
// Display image and change its size on events
image.style.display = 'block';
image.onmouseover = function() {
this.style.width = '150px';
};
image.onmouseout = function() {
this.style.width = '100px';
};
image.onclick = function() {
this.style.width = '200px';
};
image.onmouseup = function() {
this.style.width = '100px';
};
}
}
</script>
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 associationrules. Repeat
the process with different min_sup values. [Marks 15]
TID Items
1 butter, bread, milk
2 butter, flour, milk, sugar
3 butter, eggs, milk, salt
4 eggs
5 butter, flour, milk, salt
import pandas as pd
from mlxtend.frequent_patterns import apriori, association_rules
Create the dataset
data = {'TID': [1, 2, 3, 4, 5],
'Items': [['butter', 'bread', 'milk'],
['butter', 'flour', 'milk', 'sugar'],
['butter', 'eggs', 'milk', 'salt'],
['eggs'],
['butter', 'flour', 'milk', 'salt']]}
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_support 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)