DS14
Q. 1) Create TEACHER table as follows TEACHER(tno, tname, qualification, salary). Write Ajax
program to select a teachers name and print the selected teachers details [Marks 15]
servername, password, $dbname);
if (conn->connect_error) {
die("Connection failed: " . conn->connect_error);
}
// Get selected teacher's details
_POST['teacher'];
teacherId'";
conn->query($sql);
if (result->num_rows > 0) {
// Output data of each row
while(row = result->fetch_assoc()) {
echo "Teacher Name: " . row['tname'] . "<br>";
echo "Qualification: " . row['salary'] . "<br>";
}
} else {
echo "No teacher found with the selected ID.";
}
$conn->close();
?>
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. [Marks 15]
TID Items
1 {Apple , Mango , Banana}
2 {Mango , Banana , Cabbage , Carrots}
3 {Mango , Banana ,Carrots}
4 {Mango , Carrots}
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori, association_rules
import pandas as pd
Define the dataset
data = [
{'Apple', 'Mango', 'Banana'},
{'Mango', 'Banana', 'Cabbage', 'Carrots'},
{'Mango', 'Banana', 'Carrots'},
{'Mango', 'Carrots'}
]
Convert categorical values into one-hot encoded format
te = TransactionEncoder()
te_ary = te.fit(data).transform(data)
df = pd.DataFrame(te_ary, columns=te.columns_)
Apply 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(df, 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)