DWM Final Exps
DWM Final Exps
DWM Final Exps
EXP 1 PERFECT
EXP 2 PERFECT
EXP 3 PERFECT
EXP 4 PERFECT
EXP 4 EXCEL
EXP 5
if sum_prob == 0:
print("Prediction: Fail")
else:
print("Prediction: Pass")
else:
def testInput():
test = string.split(',')
return test
data = [
p_study = {}
p_sports = {}
p_grade = {}
p_pass_count = 0
p_fail_count = 0
if result == "Pass":
p_study[study] = p_study.get(study, 0) + 1
p_sports[sports] = p_sports.get(sports, 0) + 1
p_grade[grade] = p_grade.get(grade, 0) + 1
p_pass_count += 1
else:
p_fail_count += 1
total_students = len(data)
p_study[key] /= total_students
p_sports[key] /= total_students
for key in p_grade:
p_grade[key] /= total_students
test = testInput()
EXP 6 PERFECT
EXP 7
import java.io.*;
class Kmean {
int N = 9;
a = arr[0];
b = arr[1];
m1 = a;
m2 = b;
System.out.print(arr[i] + "\t");
System.out.println();
do {
n++;
k = 0;
j = 0;
cluster1[k] = arr[i];
k++;
} else {
cluster2[j] = arr[i];
j++;
sum1 = 0;
sum2 = 0;
a = m1;
b = m2;
m1 = Math.round(sum1 / k);
m2 = Math.round(sum2 / j);
if (m1 == a && m2 == b)
flag = false;
else
flag = true;
if (cluster1[i] != 0) {
System.out.print(cluster1[i] + "\t");
System.out.println("\n");
if (cluster2[i] != 0) {
System.out.print(cluster2[i] + "\t");
} while (flag);
if (cluster1[i] != 0) {
System.out.print(cluster1[i] + "\t");
System.out.println();
if (cluster2[i] != 0) {
System.out.print(cluster2[i] + "\t");
EXP 8
import numpy as np
# Sample data
def compute_distances(data):
n = len(data)
for i in range(n):
for j in range(n):
return distances
distances = compute_distances(data)
return linkage_matrix
def complete_linkage(data):
distances = compute_distances(data)
return linkage_matrix
def average_linkage(data):
distances = compute_distances(data)
return linkage_matrix
plt.figure(figsize=(10, 6))
dendrogram(linkage_matrix)
plt.show()
def calculate_distances(linkage_matrix):
min_distance = linkage_matrix[0, 2]
max_distance = linkage_matrix[-1, 2]
else:
if linkage_type == 'single':
linkage_matrix = single_linkage(data)
linkage_matrix = complete_linkage(data)
else:
linkage_matrix = average_linkage(data)
display_dendrogram(linkage_matrix, linkage_type)
EXP 9
data = [
['T100', ['I1', 'I2', 'I5']],
['T200', ['I2', 'I4']],
['T300', ['I2', 'I3']],
['T400', ['I1', 'I2', 'I4']],
['T500', ['I1', 'I3']],
['T600', ['I2', 'I3']],
['T700', ['I1', 'I3']],
['T800', ['I1', 'I2', 'I3', 'I5']],
['T900', ['I1', 'I2', 'I3']]
]
init = []
for i in data:
for q in i[1]:
if(q not in init):
init.append(q)
init = sorted(init)
c = Counter()
for i in init:
for d in data:
if i in d[1]:
c[i] += 1
print("C1:")
for i in c:
print(f"{[i]}: {c[i]}")
print()
l = Counter()
for i in c:
if c[i] >= s:
l[frozenset([i])] += c[i]
print("L1:")
for i in l:
print(f"{list(i)}: {l[i]}")
print()
pl = l
pos = 1
for count in range(2, 1000):
nc = set()
temp = list(l)
for i in range(0, len(temp)):
for j in range(i + 1, len(temp)):
t = temp[i].union(temp[j])
if len(t) == count:
nc.add(temp[i].union(temp[j]))
nc = list(nc)
c = Counter()
for i in nc:
c[i] = 0
for q in data:
temp = set(q[1])
if i.issubset(temp):
c[i] += 1
print(f"C{count}:")
for i in c:
print(f"{list(i)}: {c[i]}")
print()
l = Counter()
for i in c:
if c[i] >= s:
l[i] += c[i]
print(f"L{count}:")
for i in l:
print(f"{list(i)}: {l[i]}")
print()
if len(l) == 0:
break
pl = l
pos = count
print("Result:")
print(f"L{pos}:")
for i in pl:
print(f"{list(i)}: {pl[i]}")
print()
for l in pl:
c = [frozenset(q) for q in combinations(l, len(l) - 1)]
mmax = 0
for a in c:
b=l-a
ab = l
sab = 0
sa = 0
sb = 0
for q in data:
temp = set(q[1])
if a.issubset(temp):
sa += 1
if b.issubset(temp):
sb += 1
if ab.issubset(temp):
sab += 1
print(f"{list(a)} -> {list(b)} = {sab / sa * 100}%")
print(f"{list(b)} -> {list(a)} = {sab / sb * 100}%")
print()
EXP 10
data = [
["C", "A"],
["E", "D"],
web_pages[row[0]] = 1
# Damping factor
damping_factor = 0.85
convergence_criteria = 0.0001
delta = 1
new_ranks = {}
new_ranks[page] = new_rank
web_pages = new_ranks
# Step 6: Find the page with the highest rank
table.append([page, rank])
print(row)