DS8
Q. 1) Write a JavaScript to display message ‘Exams are near, have you started preparing for?’ (usealert
box ) and Accept any two numbers from user and display addition of two number .(Use Prompt and
confirm box) [Marks 15]
// Accept two numbers from user
var num1 = prompt("Enter the first number:");
var num2 = prompt("Enter the second number:");
// Convert inputs to numbers
num1 = parseFloat(num1);
num2 = parseFloat(num2);
// Check if inputs are valid numbers
if (!isNaN(num1) && !isNaN(num2)) {
// Calculate sum
var sum = num1 + num2;
// Display sum using confirm box
confirm("The sum of " + num1 + " and " + num2 + " is " + sum);
} else {
// Display error message if inputs are not valid numbers
alert("Invalid input. Please enter valid numbers.");
}
</script>
</head>
<body>
<!-- This is just a template and doesn't display anything -->
</body>
</html>
Q. 2)Download the groceries dataset. Write a python program to read the dataset and display its
information. Preprocess the data (drop null values etc.) Convert the categorical values into numeric
format. Apply the apriori algorithm on the above dataset to generate the frequent itemsets and association
rules
import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori, association_rules
Read the dataset
df = pd.read_csv("groceries_dataset.csv")
Drop null values
df.dropna(inplace=True)
Convert categorical values into numeric format
te = TransactionEncoder()
te_ary = te.fit(df.values).transform(df.values)
df_encoded = pd.DataFrame(te_ary, columns=te.columns_)
Apply Apriori algorithm to generate frequent itemsets
frequent_itemsets = apriori(df_encoded, min_support=0.01, use_colnames=True)
Generate association rules
rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.2)
Display frequent itemsets and association rules
print("Frequent Itemsets:")
print(frequent_itemsets)
print("\nAssociation Rules:")
print(rules)