本文整理汇总了Python中pybrain.datasets.ClassificationDataSet.calculateStatistics方法的典型用法代码示例。如果您正苦于以下问题:Python ClassificationDataSet.calculateStatistics方法的具体用法?Python ClassificationDataSet.calculateStatistics怎么用?Python ClassificationDataSet.calculateStatistics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybrain.datasets.ClassificationDataSet
的用法示例。
在下文中一共展示了ClassificationDataSet.calculateStatistics方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: classifer
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
def classifer(labels, data):
""" data in format (value, label)
"""
clsff = ClassificationDataSet(2,class_labels=labels)
for d in data:
clsff.appendLinked(d[0], d[1])
clsff.calculateStatistics()
示例2: createDataset
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
def createDataset():
data = ClassificationDataSet(100,nb_classes=len(lettersDict.keys()), class_labels=lettersDict.keys())
allTheLetters = string.uppercase
for letter in lettersDict.keys():
data.addSample(lettersDict[letter], allTheLetters.index(letter))
data._convertToOneOfMany(bounds=[0, 1])
print data.calculateStatistics()
return data
示例3: bootstrap
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
def bootstrap(trndata, iter=100):
"""
check http://sci2s.ugr.es/keel/pdf/specific/articulo/jain_boot_87.pdf for notation
"""
print trndata.calculateStatistics()
np_array = np.hstack((trndata['input'], trndata['target']))
my_range = range(np_array.shape[0])
print trndata['target'].shape
app_sum = 0
e0_sum = 0
for i in range(iter):
indices = list(set([random.choice(my_range) for i in my_range]))
np_train_array = np.vstack(np_array[indices])
new_training_samples = ClassificationDataSet(attributes, classes_number)
new_training_samples.setField('input', np_train_array[:, :54])
new_training_samples.setField('target', np_train_array[:, 54:55])
new_training_samples._convertToOneOfMany()
test_indices = list(set(my_range) - set(indices))
new_test_samples = ClassificationDataSet(attributes, classes_number)
np_test_array = np.vstack(np_array[test_indices])
new_test_samples.setField('input', np_test_array[:, :54])
new_test_samples.setField('target', np_test_array[:, 54:55])
new_test_samples._convertToOneOfMany()
print new_training_samples.calculateStatistics()
print new_test_samples.calculateStatistics()
model = FNNClassifier()
model.train(new_training_samples, new_test_samples)
(xtrn, ytrn) = model.predict(new_training_samples)
(xtest, ytest) = model.predict(new_test_samples)
app_sum += (1 - accuracy(xtrn, ytrn))
e0_sum += (1 - accuracy(xtest, ytest))
app = app_sum / float(iter)
e0 = e0_sum / float(iter)
e632 = 0.368 * app + 0.632 * e0
print e632
return e632
示例4: range
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
#convert back to a single column of class labels
#alldata._convertToClassNb()
#Target dimension is supposed to be 1
#The targets are class labels starting from zero
for i in range(N):
alldata.appendLinked(Xdf.ix[i,:],Ydf['default_Yes'].ix[i,:])
#generate training and testing data sets
tstdata, trndata = alldata.splitWithProportion(0.10)
#classes are encoded into one output unit per class, that takes on a certain value if the class is present
trndata._convertToOneOfMany( )
tstdata._convertToOneOfMany( )
len(tstdata), len(trndata)
#calculate statistics and generate histograms
alldata.calculateStatistics()
print alldata.classHist
print alldata.nClasses
print alldata.getClass(1)
#########################################################################################
#########################################################################################
#########################################################################################
#########################################################################################
#construct the network
from pybrain.structure import FeedForwardNetwork
net=FeedForwardNetwork()
#constructing the input, hidden and output layers
from pybrain.structure import LinearLayer, SigmoidLayer
inLayer = LinearLayer(3,name="input_nodes")
示例5: ClassificationDataSet
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
'''
# one-hot encoding
wm_df = pd.get_dummies(df)
X = wm_df[wm_df.columns[1:-2]] # input
Y = wm_df[wm_df.columns[-2:]] # output
label = wm_df.columns._data[-2:] # class label
# construction of data in pybrain's formation
from pybrain.datasets import ClassificationDataSet
ds = ClassificationDataSet(19, 1, nb_classes=2, class_labels=label)
for i in range(len(Y)):
y = 0
if Y['好瓜_是'][i] == 1: y = 1
ds.appendLinked(X.values[i], y)
ds.calculateStatistics()
# generation of train set and test set (3:1)
tstdata_temp, trndata_temp = ds.splitWithProportion(0.25)
tstdata = ClassificationDataSet(19, 1, nb_classes=2, class_labels=label)
for n in range(0, tstdata_temp.getLength()):
tstdata.appendLinked( tstdata_temp.getSample(n)[0], tstdata_temp.getSample(n)[1] )
trndata = ClassificationDataSet(19, 1, nb_classes=2, class_labels=label)
for n in range(0, trndata_temp.getLength()):
trndata.appendLinked( trndata_temp.getSample(n)[0], trndata_temp.getSample(n)[1] )
trndata._convertToOneOfMany()
tstdata._convertToOneOfMany()
'''
示例6: ClassificationDataSet
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
data = [map(float, line.rstrip().split()) for line in f]
# outputs = [[gene[-1]] for gene in data]
# for gene in data:
# del gene[-1]
ds = ClassificationDataSet(6, 1)
for i, gene in enumerate(data):
ds.addSample(gene[:-1], gene[-1])
tstdata, trndata = ds.splitWithProportion( 0.25 )
trndata._convertToOneOfMany( )
tstdata._convertToOneOfMany( )
print ds.calculateStatistics()
print ds.nClasses
print "Number of training patterns: ", len(trndata)
print "Input and output dimensions: ", trndata.indim, trndata.outdim
print "First sample (input, target, class):"
print trndata['input'][0], trndata['target'][0], trndata['class'][0]
fnn = buildNetwork( trndata.indim, 7, trndata.outdim, outclass=LinearLayer )
trainer = BackpropTrainer( fnn, dataset=trndata, momentum=0.1, verbose=True, weightdecay=0.01)
#
# ticks = arange(-3.,6.,0.2)
# X, Y = meshgrid(ticks, ticks)
示例7: range
# 需要导入模块: from pybrain.datasets import ClassificationDataSet [as 别名]
# 或者: from pybrain.datasets.ClassificationDataSet import calculateStatistics [as 别名]
image_vector = image.flatten()
ds_training.appendLinked(image_vector, [category])
category+=1
category = 0
for shape in shapes:
for i in range(8):
image = imread('C:/Users/alexis.matelin/Documents/Neural Networks/Visual classification/shapes/testing/'+shape+str(i+1)+'.png', as_grey=True, plugin=None, flatten=None)
image_vector = image.flatten()
ds_testing.appendLinked(image_vector, [category])
ds_training.calculateStatistics()
ds_training.getClass(0)
print(ds_training.getField('target'))
ds_training._convertToOneOfMany(bounds=[0, 1])
ds_testing._convertToOneOfMany(bounds=[0, 1])
print(ds_training.getField('target'))
net = buildNetwork(1024,12, 12, 3, hiddenclass = TanhLayer, outclass=SoftmaxLayer)
trainer = BackpropTrainer(net, dataset=ds_training, verbose=True, learningrate=0.01)
trainer.trainUntilConvergence()