コード例 #1
0
columns = np.hsplit(dataset,9)
xsample = np.hstack(columns[0:8])
ysample = columns[8]
shape = xsample.shape

print "xsample = ",xsample.shape
print "ysample = ",ysample.shape

# indexList = np.random.permutation(shape[0])
indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ",x_train.shape
print "y_train.shape = ",y_train.shape

x_test = xsample[indexList[538:]]
y_test = ysample[indexList[538:]]
print "x_test.shape = ",x_test.shape
print "y_test.shape = ",y_test.shape

classifier = BayesClassifier()
classifier.saveNeeded = False
classifier.saveNeeded = 20
classifier.train(x_train,y_train)
print "classifier train succefully ..."
y_predict = classifier.predict(x_test)
result = classifier.f_measure(y_predict,y_test)
print "BayesClassifier result = ",result

コード例 #2
0
xsample = np.float32(xsample)
ysample = np.float32(ysample)
shape = xsample.shape

print "xsample = ", xsample.shape
print "ysample = ", ysample.shape

orders = ["precision", 'recall', 'accuracy', 'fmeasure']
number = 20
PRAFarray = np.zeros((number, 12))
for i in xrange(number):
    print "i = ", i
    indexList = np.random.permutation(shape[0])
    x_train = xsample[indexList[:538]]
    y_train = ysample[indexList[:538]]
    classifier = BayesClassifier()
    classifier.saveNeeded = False
    classifier.sectionNumber = 30
    classifier.train(x_train, y_train)
    x_train1 = classifier.transform_pmodel(x_train)
    x_train2 = np.hstack([x_train, x_train1])
    print "shape = ", (x_train.shape, x_train1.shape, x_train2.shape)

    x_test = xsample[indexList[538:]]
    y_test = ysample[indexList[538:]]
    x_test1 = classifier.transform_pmodel(x_test)
    x_test2 = np.hstack([x_test, x_test1])

    svm_params = dict(kernel_type=cv2.SVM_LINEAR,
                      svm_type=cv2.SVM_C_SVC,
                      C=3.67,
コード例 #3
0
ファイル: cv2MLP.py プロジェクト: ChenLiangbo/iloveme
print "ysample = ",ysample.shape

# indexList = np.random.permutation(shape[0])
indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ",x_train.shape
print "y_train.shape = ",y_train.shape

x_test = xsample[indexList[538:]]
y_test = ysample[indexList[538:]]
print "x_test.shape = ",x_test.shape
print "y_test.shape = ",y_test.shape

myBayes = BayesClassifier()

layers = np.array([8,15,1])

model = cv2.ANN_MLP()
model.create(layers)

params = dict( term_crit = (cv2.TERM_CRITERIA_COUNT, 3000, 0.01),  
               train_method = cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP,   
               bp_dw_scale = 0.001,  
               bp_moment_scale = 0.0 )

model.train(x_train,y_train,None,params = params)

ret,resp = model.predict(x_test)
コード例 #4
0
print "ysample = ", ysample.shape

# indexList = np.random.permutation(shape[0])
indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ", x_train.shape
print "y_train.shape = ", y_train.shape

x_test = xsample[indexList[538:]]
y_test = ysample[indexList[538:]]
print "x_test.shape = ", x_test.shape
print "y_test.shape = ", y_test.shape

classifier = BayesClassifier()
classifier.saveNeeded = False
classifier.sectionNumber = 32
classifier.train(x_train, y_train)
print "classifier train succefully ..."
y_predict = classifier.predict(x_test)

# print "y_predict = ",y_predict
print "y_predict = ", y_predict.shape
accuracy = (y_test == y_predict)

print "BayesClassifier accuracy = ", np.mean(accuracy)
print "-" * 100

from sklearn.naive_bayes import BernoulliNB
clf = BernoulliNB()
コード例 #5
0
#!usr/bin/env/python
# -*- coding: utf-8 -*-
import numpy as np
from bayesClassifier import BayesClassifier

classifier = BayesClassifier()
classifier.sectionNumber = 12
classifier.saveNeeded = False

dataset = np.load('pima-indians.npy')

columns = np.hsplit(dataset, 9)
xsample = np.hstack(columns[0:8])
ysample = columns[8]
shape = xsample.shape
print "xsample = ", xsample.shape
print "ysample = ", ysample.shape
ysample = np.float32(ysample)
indexList = np.random.permutation(shape[0])
# indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ", x_train.shape
print "y_train.shape = ", y_train.shape

classifier.train(x_train, y_train)
print "classifier train succefully ..."
x_train = classifier.transform_pmodel(x_train)

x_test = xsample[indexList[538:]]
コード例 #6
0
ファイル: pclassify.py プロジェクト: ChenLiangbo/iloveme
#!usr/bin/env/python 
# -*- coding: utf-8 -*-
import numpy as np
from bayesClassifier import BayesClassifier

classifier = BayesClassifier()
classifier.sectionNumber = 12
classifier.saveNeeded = False

dataset = np.load('pima-indians.npy')

columns = np.hsplit(dataset,9)
xsample = np.hstack(columns[0:8])
ysample = columns[8]
shape = xsample.shape
print "xsample = ",xsample.shape
print "ysample = ",ysample.shape
ysample = np.float32(ysample)
indexList = np.random.permutation(shape[0])
# indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ",x_train.shape
print "y_train.shape = ",y_train.shape

classifier.train(x_train,y_train)
print "classifier train succefully ..."
x_train = classifier.transform_pmodel(x_train)

x_test = xsample[indexList[538:]]
コード例 #7
0
ファイル: myBayes.py プロジェクト: ChenLiangbo/iloveme
# indexList = np.random.permutation(shape[0])
indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ",x_train.shape
print "y_train.shape = ",y_train.shape

x_test = xsample[indexList[538:]]
y_test = ysample[indexList[538:]]
print "x_test.shape = ",x_test.shape
print "y_test.shape = ",y_test.shape


classifier = BayesClassifier()
classifier.saveNeeded = False
classifier.sectionNumber = 32
classifier.train(x_train,y_train)
print "classifier train succefully ..."
y_predict = classifier.predict(x_test)

# print "y_predict = ",y_predict
print "y_predict = ",y_predict.shape
accuracy = (y_test == y_predict)

print "BayesClassifier accuracy = ",np.mean(accuracy)
print "-"*100


コード例 #8
0
xsample = np.hstack(columns[0:8])
ysample = columns[8]
shape = xsample.shape

print "xsample = ", xsample.shape
print "ysample = ", ysample.shape

from sklearn.naive_bayes import GaussianNB
orders = ["precision", 'recall', 'accuracy', 'fmeasure']
number = 20
PRAFarray = np.zeros((number, 12))
for i in xrange(number):
    indexList = np.random.permutation(shape[0])
    x_train = xsample[indexList[:538]]
    y_train = ysample[indexList[:538]]
    classifier = BayesClassifier()
    classifier.saveNeeded = False
    classifier.sectionNumber = 40
    classifier.train(x_train, y_train)
    x_train1 = classifier.transform_pmodel(x_train)
    x_train2 = np.hstack([x_train, x_train1])
    print "shape = ", (x_train.shape, x_train1.shape, x_train2.shape)

    x_test = xsample[indexList[538:]]
    y_test = ysample[indexList[538:]]
    x_test1 = classifier.transform_pmodel(x_test)
    x_test2 = np.hstack([x_test, x_test1])

    clf = GaussianNB().fit(x_train, y_train.ravel())
    y_predict = clf.predict(x_test)
    result = classifier.f_measure(y_predict, y_test)
コード例 #9
0
ファイル: test.py プロジェクト: ChenLiangbo/iloveme
indexList = np.random.permutation(shape[0])
# indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ",x_train.shape
print "y_train.shape = ",y_train.shape

x_test = xsample[indexList[538:]]
y_test = ysample[indexList[538:]]
print "x_test.shape = ",x_test.shape
print "y_test.shape = ",y_test.shape


classifier = BayesClassifier()
classifier.saveNeeded = True
classifier.sectionNumber = 12
classifier.train(x_train,y_train)
print "classifier train succefully ..."
y_predict = classifier.predict(x_test)

# print "y_predict = ",y_predict
print "y_predict = ",y_predict.shape
accuracy = (y_test == y_predict)

print "BayesClassifier accuracy = ",np.mean(accuracy)
params = classifier.params
'''
p = params['p0']
p0 = p['class0']
コード例 #10
0
ysample = np.float32(ysample)
shape = xsample.shape

print "xsample = ",xsample.shape
print "ysample = ",ysample.shape


orders = ["precision",'recall','accuracy','fmeasure']
number = 20
PRAFarray = np.zeros((number,12))
for i in xrange(number):
    print "i = ",i
    indexList = np.random.permutation(shape[0])
    x_train = xsample[indexList[:538]]
    y_train = ysample[indexList[:538]]
    classifier = BayesClassifier()
    classifier.saveNeeded = False
    classifier.sectionNumber = 39
    classifier.train(x_train,y_train)
    x_train1 = classifier.transform_pmodel(x_train)
    x_train2 = np.hstack([x_train,x_train1])
    # print "shape = ",(x_train.shape,x_train1.shape,x_train2.shape)

    x_test = xsample[indexList[538:]]
    y_test = ysample[indexList[538:]]
    x_test1 = classifier.transform_pmodel(x_test)
    x_test2 = np.hstack([x_test,x_test1])


    bdt = AdaBoostClassifier(DecisionTreeClassifier(max_depth=1),
                         algorithm="SAMME",
コード例 #11
0
print "ysample = ", ysample.shape

# indexList = np.random.permutation(shape[0])
indexList = range(shape[0])

x_train = xsample[indexList[0:538]]
y_train = ysample[indexList[0:538]]
print "x_train.shape = ", x_train.shape
print "y_train.shape = ", y_train.shape

x_test = xsample[indexList[538:]]
y_test = ysample[indexList[538:]]
print "x_test.shape = ", x_test.shape
print "y_test.shape = ", y_test.shape

myBayes = BayesClassifier()

layers = np.array([8, 15, 1])

model = cv2.ANN_MLP()
model.create(layers)

params = dict(term_crit=(cv2.TERM_CRITERIA_COUNT, 3000, 0.01),
              train_method=cv2.ANN_MLP_TRAIN_PARAMS_BACKPROP,
              bp_dw_scale=0.001,
              bp_moment_scale=0.0)

model.train(x_train, y_train, None, params=params)

ret, resp = model.predict(x_test)