OneCompiler

DS14

315

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]

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Fetch Teacher Details</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script> $(document).ready(function(){ $("#teacherSelect").change(function(){ var selectedTeacher = $(this).val(); $.ajax({ type: "POST", url: "get_teacher_details.php", data: { teacher: selectedTeacher }, success: function(response){ $("#teacherDetails").html(response); } }); }); }); </script> </head> <body> <select id="teacherSelect"> <option value="">Select Teacher</option> <option value="1">Teacher 1</option> <option value="2">Teacher 2</option> <option value="3">Teacher 3</option> <!-- Add more options as needed --> </select> <div id="teacherDetails"></div> </body> </html> <?php // Database connection $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "your_database_name";

conn=newmysqli(conn = new mysqli(servername, username,username, password, $dbname);

if (conn->connect_error) { die("Connection failed: " . conn->connect_error);
}

// Get selected teacher's details
teacherId=teacherId = _POST['teacher'];
sql="SELECTFROMTEACHERWHEREtno=sql = "SELECT * FROM TEACHER WHERE tno = 'teacherId'";
result=result = 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[qualification]."<br>";echo"Salary:".row['qualification'] . "<br>"; echo "Salary: " . 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)