コード例 #1
0
FrovedisServer.initialize(argvs[1])

mat = np.asmatrix([[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, fit_prior=True, class_prior=None, verbose = 0).fit(mat,lbl)
nbm.debug_print()
print("predicting on nbm multinomial classifier model: ")
mnb =  nbm.predict(mat)
print("Accuracy of model", nbm.score(mat,lbl))

nbm2 = BernoulliNB(alpha=1.0,fit_prior=True,class_prior=None,binarize=0.0,verbose=0).fit(mat,lbl)
nbm2.debug_print()
print("predicting on nbm bernoulli classifier model: ")
bnb =  nbm2.predict(mat)
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()

コード例 #2
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()
コード例 #3
0
# initializing the Frovedis server
argvs = sys.argv
argc = len(argvs)
if (argc < 2):
    print(
        'Please give frovedis_server calling command as the first argument \n(e.g. "mpirun -np 2 /opt/nec/frovedis/ve/bin/frovedis_server")'
    )
    quit()

from frovedis.exrpc.server import FrovedisServer
FrovedisServer.initialize(argvs[1])

# classification data
from sklearn.datasets import load_breast_cancer
mat, lbl = load_breast_cancer(return_X_y=True)

mnb = MultinomialNB(alpha=1.0).fit(mat, lbl)
pred = mnb.predict(mat)
print("prediction on multinomial classifier model: ")
print(pred)
print("prediction accuracy: %.4f" % (mnb.score(mat, lbl)))

bnb = BernoulliNB(alpha=1.0).fit(mat, lbl)
pred = bnb.predict(mat)
print("prediction on bernoulli classifier model: ")
print(pred)
print("prediction accuracy: %.4f" % (bnb.score(mat, lbl)))

# Clean-up
FrovedisServer.shut_down()