Esempio n. 1
0
mat = pd.DataFrame([[1, 0, 1, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0],
                    [0, 1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 1, 0]],
                   dtype=np.float64)
lbl = np.array([0, 1, 1, 0], dtype=np.float64)

# fitting input matrix and label on linear nbm object
nbm = MultinomialNB(alpha=1.4).fit(mat, lbl)
nbm.debug_print()
print("predicting on nbm multinomial classifier model: ")
mnb = nbm.predict(mat)
print(mnb)
print("Accuracy of model")
nbm.score(mat, lbl)

nbm2 = BernoulliNB(alpha=1.4).fit(mat, lbl)
nbm2.debug_print()
print("predicting on nbm bernoulli classifier model: ")
bnb = nbm2.predict(mat)
print(bnb)
print("Accuracy of model")
nbm2.score(mat, lbl)

if (lbl == mnb).all() and (lbl == bnb).all():
    print("Status: Passed")
else:
    print("Status: Failed")

nbm.release()
nbm2.release()
FrovedisServer.shut_down()
Esempio n. 2
0
    quit()
FrovedisServer.initialize(argvs[1])

# Demo of Multinomial Naive Bayes
mat = FrovedisCRSMatrix(dtype=np.float64).load("./input/multi.txt")
lbl = np.array([1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0])
nbm1 = MultinomialNB(alpha=1.0).fit(mat,lbl)
print("\nmultinomial model: ")
nbm1.debug_print()

mnb = nbm1.predict(mat)
print("prediction on multinomial classifier model: ", mnb)
print("accuracy of model: ", nbm1.score(mat,lbl))

# Demo of Bernoulli Naive Bayes
mat = FrovedisCRSMatrix(dtype=np.float64).load("./input/bern.txt")
lbl = np.array([1.0,0.0,1.0,1.0,1.0,0.0,1.0,1.0])
nbm2 = BernoulliNB(alpha=1.0).fit(mat,lbl)
print("\nbernoulli model: ")
nbm2.debug_print()

bnb =  nbm2.predict(mat)
print("prediction on bernoulli classifier model: ", bnb)
print("accuracy of model", nbm2.score(mat,lbl))

# Clean-up
nbm1.release()
nbm2.release()
FrovedisServer.shut_down()