all |
# 6431027721 def get_rows(S, conditions): a = [] for i in S: k = 0 for j in conditions: if i[0][j] == conditions[j]: k += 1 if k == len(conditions) : a.append(i) return a #--------------------------------------- def Entropy(S, conditions): n = get_rows(S, conditions) a ={} m = 0 for i in n: for j in i[1:]: if j in a : a[j] += 1 else : a[j] = 1 total = 0 for i in a: total += a[i] for i in a : g= a[i]/total t= ((-1)*g*math.log(g,2)) m += t return m #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): j = len(get_rows(S, conditions)) u = get_rows(S, conditions) x = Entropy(S, conditions) y = 0 a = {} for i in u: if i[0][feature_name] in a : a[i[0][feature_name]] += 1 else : a[i[0][feature_name]] = 1 for i in a : h = conditions h[feature_name] = i y += (a[i]/j)*Entropy(S, h) return y #--------------------------------------- | # 6431150121 def get_rows(S, conditions): r = [] for e in S: c = 0 for d in conditions: if e[0][d] == conditions[d]: c += 1 if c == len(conditions) : r.append(e) return r #--------------------------------------- def Entropy(S, conditions): s = get_rows(S, conditions) r ={} p = 0 for e in s: for d in e[1:]: if d in r : r[d] += 1 else : r[d] = 1 total = 0 for e in r: total += r[e] for e in r : g = r[e]/total t = ((-1)*g*math.log(g,2)) p += t return p #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): d = len(get_rows(S, conditions)) w = get_rows(S, conditions) x = Entropy(S, conditions) y = 0 r = {} for e in w: if e[0][feature_name] in r : r[e[0][feature_name]] += 1 else : r[e[0][feature_name]] = 1 for e in r : h = conditions h[feature_name] = e y += (r[e]/d)*Entropy(S, h) return y #--------------------------------------- | # 6431539721 def get_rows(S, conditions): a = [] for e in S: n = 0 for i in conditions: if e[0][i] == conditions[i]: n += 1 if n == len(conditions) : a.append(e) return a #--------------------------------------- def Entropy(S, conditions): s = get_rows(S, conditions) r = {} n = 0 for e in s: for d in e[1:]: if d in r : r[d] += 1 else : r[d] = 1 total = 0 for e in r: total += r[e] for e in r : g = r[e]/total t = ((-1)*g*math.log(g,2)) n += t return n #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): d = len(get_rows(S, conditions)) a = get_rows(S, conditions) c = Entropy(S, conditions) n = 0 k = {} for e in a: if e[0][feature_name] in k : k[e[0][feature_name]] += 1 else : k[e[0][feature_name]] = 1 for e in k : h = conditions h[feature_name] = e n += (k[e]/d)*Entropy(S, h) return n #--------------------------------------- | # 6431103721 def get_rows(S, conditions) : x = [] for a in S : y = 0 for b in conditions : if e[0][b] == conditions[b] : y += 1 if y == len(conditions) : x.append(a) return x #--------------------------------------- def Entropy(S, conditions) : s = get_rows(S, conditions) x = {} y = 0 for a in s : for j in a[1:] : if j in x : x[j] += 1 else : x[j] = 1 total = 0 for a in x : total += x[a] for a in x : b = x[a]/total c = ((-1)*b*math.log(b, 2)) y += t return y #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): a = len(get_rows(S, conditions)) b = get_rows(S, conditions) c = Entropy(S, conditions) d = 0 x = {} for y in b : if e[0][feature_name] in x : x[e[0][feature_name]] += 1 else : x[e[0][feature_name]] = 1 for y in x : c2 = conditions c2[feature_name] = y d += (x[y]/a)*Entropy(S, c2) return d #--------------------------------------- |
all |
# 6431138721 def get_rows(S, conditions): if conditions != {}: result = [] condition1 = dict(conditions) for i in S: re = [] for k in i[0]: for r in condition1: if r == k and condition1[r] == i[0][k]: re.append(c) if len(re) == len(condition1): result.append(i) return result else: return S #--------------------------------------- def Entropy(S, conditions): condition1 = dict(conditions) x = get_rows(S, condition1) re = len(x) out = [] for i in x: out.append(i[1]) out.sort() su = 1 lt = {} for i in range(len(out)): if i != len(out) - 1: if out[i] == out[i+1]: su += 1 else: lt[out[i]] = su su = 1 else: lt[out[i]] = su q = 0 for k in lt: entropy = -((lt[k]/re)*math.log(lt[k]/re,2)) q += entropy return q #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): condition1 = dict(conditions) re = get_rows(S, condition1) p = len(re) t = [] for i in re: t.append(i[0][feature_name]) t.sort() o = {} l = 1 for k in range(len(t)): if k != len(t) - 1: if t[k] == t[k+1]: l += 1 else: o[t[k]] = l l = 1 else: o[t[k]] = l z = 0 for i in o: r = {} r[feature_name] = i a = (abs(o[i])/abs(p))Entropy(re, r) z += a return z #--------------------------------------- | # 6431104321 def get_rows(S, conditions): if conditions != {} : out = [] condition1 = dict(conditions) for i in S : #i = ลิสย่อย a = [] for k in i[0] : # k = keyของlist for c in condition1 : # c = keyของconditions if c == k and condition1[c] == i[0][k] : a.append(c) if len(a) == len(condition1) : out.append(i) return out else : return S #--------------------------------------- def Entropy(S, conditions): condition1 = dict(conditions) x = get_rows(S, condition1) a = len(x) #จำนวนlistย่อย out = [] for i in x : out.append(i[1]) out.sort() b = 1 c = {} for i in range(len(out)) : if i != len(out) - 1 : if out[i] == out[i+1] : b += 1 else : c[out[i]] = b b = 1 else : c[out[i]] = b d = 0 for k in c : entropy = -((c[k]/a)*math.log(c[k]/a,2)) d += entropy return d #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): condition1 = dict(conditions) a = get_rows(S, condition1) y = len(a) u = [] for i in a : u.append(i[0][feature_name]) u.sort() e = {} f = 1 for k in range(len(u)) : if k != len(u) - 1 : if u[k] == u[k+1] : f += 1 else : e[u[k]] = f f = 1 else : e[u[k]] = f h = 0 for i in e : r = {} r[feature_name] = i g = (abs(e[i])/abs(y))*Entropy(a, r) h += g return h #--------------------------------------- | # 6431511021 def get_rows(S, conditions): if conditions != {}: c= [] conditions_n = dict(conditions) for k in S: d= [] for e in k[0]: for m in conditions_n: if m == e and conditions_n[m] == k[0][e]: d.append(m) if len(d) == len(conditions_n): c.append(k) return c else: return S #--------------------------------------- def Entropy(S, conditions): conditions_n = dict(conditions) z = get_rows(S,conditions_n) t = len(z) y = [] for e in z: y.append(e[1]) y.sort() u = 1 r = {} for k in range(len(y)): if k != len(y)-1: if y[k] == y[k+1]: u += 1 else: r[y[k]] = u u =1 else: r[y[k]] = u f = 0 for i in r: eq = -((r[i]/t)*math.log(r[i]/t,2)) x += eq return x #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): conditions_n = dict(conditions) c = get_rows(S,conditions_n) d = len(c) y = [] for e in c: y.append(e[0][feature_name]) y.sort() g = {} h = 1 for i in range(len(y)): if i == len(y)-1: g[y[i]] = h else: if y[i] == y[i+1]: h += 1 else: g[y[i]] = h h = 1 a = 0 for k in g: w = {} w[feature_name] = k j = (abs(g[k])/abs(d))*Entropy(c,w) a += j return a #--------------------------------------- | # 6431106621 def get_rows(S, conditions): if conditions != {}: a = [] conditionsnew = dict(conditions) for i in S : b = [] for k in i[0] : for n in conditionsnew : if n == k and conditionsnew[n] == i[0][k] : b.append(n) if len(b) == len(conditionsnew) : a.append(i) return a else: return S #--------------------------------------- def Entropy(S, conditions): conditionsnew = dict(conditions) y = get_rows(S, conditionsnew) b = len(y) a = [] for i in y: a.append(i[1]) a.sort() c = 1 d = {} for i in range(len(a)): if i == len(a) -1: d[a[i]] = c else: if a[i] == a[i+1]: c += 1 else: d[a[i]] = c c = 1 e = 0 for k in d: soon = -((d[k]/b)*math.log(d[k]/b,2)) e += soon return e #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): conditionsnew = dict(conditions) b = get_rows(S, conditionsnew) n = len(b) x = [] for i in b : x.append(i[0][feature_name]) x.sort c = {} m = 1 for k in range(len(x)): if k != len(x) -1: if x[k] == x[k+1]: m += 1 else: c[x[k]] = m m = 1 else: c[x[k]] = m h = 0 for i in c: s = {} s[feature_name] = i e = (abs(c[i])/abs(n))*Entropy(b, s) h += e return h #--------------------------------------- |
all |
# 6431007121 def get_rows(S, conditions): b=[] if conditions=={}: return S else: for e in S: c=0 for k in conditions: if e[0][k]!=conditions[k]: c=1 break if c==0: b.append(e) return b #--------------------------------------- def Entropy(S, conditions): c=get_rows(S, conditions) a={} x=0 for e in c: if e[1] in a: a[e[1]]+=1 else: a[e[1]]=1 for k in a: x+=-a[k]/len(c)*math.log(a[k]/len(c),2) return x #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): c=get_rows(S, conditions) d={} x=0 for e in c: if e[0][feature_name] in d: d[e[0][feature_name]]+=1 else: d[e[0][feature_name]]=1 for k in d: r={} r[feature_name]=k x+=(Entropy(c,r))*(abs(d[k]/len(c))) return x | # 6431113021 def get_rows(S, conditions): z = [] if conditions == {} : return S else : for h in S : j = 0 for p in conditions : if h[0][p]!=conditions[p] : j = 1 break if j == 0 : z.append(h) return z #--------------------------------------- def Entropy(S, conditions): j = get_rows(S, conditions) m = {} f = 0 for h in j : if h[1] in m : m[h[1]]+=1 else : m[h[1]] = 1 for p in m : f+=-m[p]/len(j)*math.log(m[p]/len(j),2) return f #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): j = get_rows(S, conditions) d = {} f = 0 for h in j : if h[0][feature_name] in d : d[h[0][feature_name]]+=1 else : d[h[0][feature_name]]=1 for p in d : r={} r[feature_name]=p f+=(Entropy(j,r))*(abs(d[p]/len(j))) return f | # 6431013921 def get_rows(S, conditions): a = [] if conditions == {}: return S else: for i in S: count = 0 for j in conditions: if i[0][j] != conditions[j]: count = 1 break if count == 0: a.append(i) return a #--------------------------------------- def Entropy(S, conditions): a = get_rows(S, conditions) b = {} count = 0 for i in a: if i[0] in b: b[i[0]] += 1 else: b[i[0]] = 1 for j in b: count += -b[j]/(len(a)*math.log(b[j]/len(a),2)) return count #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): a = get_rows(S, conditions) b = {} count = 0 for i in a: if i[0][feature_name] in b: b[i[0][feature_name] ] += 1 else: b[i[0][feature_name]] = 1 for j in b: c = {} c[feature_name] = j count += (Entropy(a,c))*(abs(b[j]/len(a))) return count #--------------------------------------- |
all |
# 6431517921 def get_rows(S, conditions): r = [] for e in S: cat = 0 for d in conditions: if e[0][d] == conditions[d]: c += 1 if cat == len(conditions) : r.append(e) return r #--------------------------------------- def Entropy(S, conditions): s = get_rows(S, conditions) r ={} p = 0 for e in s: for d in e[1:]: if d in r : r[d] += 1 else : r[d] = 1 total = 0 for e in r: total += r[e] for e in r : g = r[e]/total t = ((-1)*g*math.log(g,2)) p += t return p #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): p = len(get_rows(S, conditions)) y = 0 r = {feature_name:set()} for e in S: r[feature_name].add(e[0][feature_name]) for u in r[feature_name] : conditions[feature_name] = u y += (len(get_rows(S, conditions))/p)*Entropy(S, conditions) return y | # 6431149621 def get_rows(S, conditions): m = [] for x in S: n = 0 for z in conditions: if x[0][z] == conditions[z]: n += 1 if n == len(conditions) : m.append(x) return m #--------------------------------------- def Entropy(S, conditions): g = get_rows(S, conditions) k ={} l = 0 for f in g: for e in f[1:]: if e in k : k[e] += 1 else : k[e] = 1 total = 0 for f in k: total += k[f] for f in k : h = k[f]/total o = ((-1)*h*math.log(h,2)) l += o return l #--------------------------------------- def Entropy_with_feature(S, conditions, feature_name): p = len(get_rows(S, conditions)) pob = 0 okay = {feature_name:set()} for q in S: okay[feature_name].add(q[0][feature_name]) for u in okay[feature_name] : conditions[feature_name] = u pob += (len(get_rows(S, conditions))/p)*Entropy(S, conditions) return pob #--------------------------------------- |