Skip to content

Some tests for mtxslv_math_4_DT.py

Mateus de Assis Silva edited this page May 6, 2020 · 3 revisions

example for the logic of counting different elements in a numpy array

listinha = np.array([[1],[2],[2],[3],[3],[3],[4],[4],[4],[4]])
e_c = list(set(listinha[:,0]))
p = []
for j in e_c:
  p.append(listinha.tolist().count(j)/np.shape(listinha[:,0])[0])
p

you can also run: mtxslv_entropy(listinha). The result must be 1.2798542258336676.

Dataset for testing best_classifier_attribute():

listinha_2 = np.concatenate((listinha,listinha),axis = 1)
labels_2 = np.array([[0],[0],[0],[0],[0],[1],[1],[1],[1],[1]])

I believe I finished the file. It's ready to deploy. The test blocks I used are:

listinha = np.array([[1],[2],[2],[3],[3],[3],[4],[4],[4],[4]])
e_c = list(set(listinha[:,0]))
p = []
for j in e_c:
  p.append(listinha.tolist().count(j)/np.shape(listinha[:,0])[0])
p
entropy([0.1, 0.2, 0.3, 0.4],base=2)
-np.log2(0.1)*0.1-0.2*np.log2(0.2)-0.3*np.log2(0.3)-0.4*np.log2(0.4)
mtxslv_entropy(listinha)
listinha_2 = np.concatenate((listinha,listinha),axis = 1)
labels_2 = np.array([[0],[0],[0],[0],[0],[1],[1],[1],[1],[1]])

labels_2
listinha_2
vetor_booleano = [True,False]
falta_pouco =best_classifier_attribute(listinha_2,labels_2,[True,True])
np.dot([0.0, 0.0, 0.9182958340544894, 0.0],[0.1, 0.2, 0.3, 0.4])
0.3*(-(2/3)*np.log2(2/3)-(1/3)*np.log2(1/3))
np.shape(listinha_2)
len(vetor_booleano)
  for i in range(np.shape(listinha_2)[1]):
    print(vetor_booleano[i])
falta_pouco

Please, run these lines:

lista_features_coluna_1 = [[0],[0],[1],[1]]
lista_features_coluna_2 = [[0],[1],[0],[1]]
features_teste = np.concatenate((lista_features_coluna_1,lista_features_coluna_2), axis = 1)
labels_teste = np.array([[1],[1],[0],[1]])

a,b = get_subset(features_teste,labels_teste,0,1)

a should give this:

array([[1, 0],
       [1, 1]])

and b this:

array([[0],
       [1]])