本文整理汇总了Python中neupy.utils.format_data函数的典型用法代码示例。如果您正苦于以下问题:Python format_data函数的具体用法?Python format_data怎么用?Python format_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train
def train(self, input_train, target_train, input_test=None,
target_test=None, epochs=100, epsilon=None,
summary_type='table'):
is_test_data_partialy_missed = (
(input_test is None and target_test is not None) or
(input_test is not None and target_test is None)
)
if is_test_data_partialy_missed:
raise ValueError("Input and target test samples missed. "
"They must be defined both or none of them.")
input_train = format_data(input_train)
target_train = format_data(target_train)
if input_test is not None:
input_test = format_data(input_test)
if target_test is not None:
target_test = format_data(target_test)
return super(SupervisedLearning, self).train(
input_train=input_train, target_train=target_train,
input_test=input_test, target_test=target_test,
epochs=epochs, epsilon=epsilon,
summary_type=summary_type
)
示例2: train
def train(self, input_train, target_train, copy=True):
"""
Trains network. PNN doesn't actually train, it just stores
input data and use it for prediction.
Parameters
----------
input_train : array-like (n_samples, n_features)
target_train : array-like (n_samples,)
Target variable should be vector or matrix
with one feature column.
copy : bool
If value equal to ``True`` than input matrices will
be copied. Defaults to ``True``.
Raises
------
ValueError
In case if something is wrong with input data.
"""
input_train = format_data(input_train, copy=copy)
target_train = format_data(target_train, copy=copy)
n_target_features = target_train.shape[1]
if n_target_features != 1:
raise ValueError("Target value must be one dimensional array")
LazyLearningMixin.train(self, input_train, target_train)
示例3: wrapper
def wrapper(actual, expected, *args, **kwargs):
actual = format_data(actual)
expected = format_data(expected)
output = function(actual, expected, *args, **kwargs)
# use .item(0) to get a first array element and automaticaly
# convert vector that contains one element to scalar
return output.eval().item(0)
示例4: train
def train(self, input_train, target_train, copy=True):
input_train = format_data(input_train, copy=copy)
target_train = format_data(target_train, copy=copy)
if target_train.shape[1] != 1:
raise ValueError("Target value must be one dimentional array")
LazyLearning.train(self, input_train, target_train)
示例5: _preformat_inputs
def _preformat_inputs(actual, predicted):
actual = format_data(actual)
predicted = format_data(predicted)
if actual.shape != predicted.shape:
raise ValueError("Actual and predicted values have different shapes. "
"Actual shape {}, predicted shape {}"
"".format(actual.shape, predicted.shape))
return actual, predicted
示例6: predict
def predict(self, input_data):
"""
Make a prediction from the input data.
Parameters
----------
input_data : array-like (n_samples, n_features)
Raises
------
ValueError
In case if something is wrong with input data.
Returns
-------
array-like (n_samples,)
"""
if self.input_train is None:
raise NotTrained("Cannot make a prediction. Network " "hasn't been trained yet")
input_data = format_data(input_data)
input_data_size = input_data.shape[1]
train_data_size = self.input_train.shape[1]
if input_data_size != train_data_size:
raise ValueError(
"Input data must contain {0} features, got " "{1}".format(train_data_size, input_data_size)
)
ratios = pdf_between_data(self.input_train, input_data, self.std)
return (dot(self.target_train.T, ratios) / ratios.sum(axis=0)).T
示例7: visible_to_hidden
def visible_to_hidden(self, visible_input):
"""
Populates data throught the network and returns output
from the hidden layer.
Parameters
----------
visible_input : array-like (n_samples, n_visible_features)
Returns
-------
array-like
"""
is_input_feature1d = (self.n_visible == 1)
visible_input = format_data(visible_input, is_input_feature1d)
outputs = self.apply_batches(
function=self.methods.visible_to_hidden,
input_data=visible_input,
description='Hidden from visible batches',
show_progressbar=True,
show_error_output=False,
)
return np.concatenate(outputs, axis=0)
示例8: predict
def predict(self, input_data):
row1d = is_row1d(self.input_layer)
result = format_data(input_data, row1d=row1d)
for layer in self.layers:
result = layer.output(result)
return result
示例9: predict_raw
def predict_raw(self, input_data):
input_data = format_data(input_data)
output = np.zeros((input_data.shape[0], self.n_outputs))
for i, input_row in enumerate(input_data):
output[i, :] = self.transform(input_row.reshape(1, -1),
self.weight)
return output
示例10: train
def train(self, input_data):
self.discrete_validation(input_data)
input_data = bin2sign(input_data)
input_data = format_data(input_data, is_feature1d=False)
n_rows, n_features = input_data.shape
n_rows_after_update = self.n_memorized_samples + n_rows
if self.check_limit:
memory_limit = math.ceil(n_features / (2 * math.log(n_features)))
if n_rows_after_update > memory_limit:
raise ValueError("You can't memorize more than {0} "
"samples".format(memory_limit))
weight_shape = (n_features, n_features)
if self.weight is None:
self.weight = np.zeros(weight_shape, dtype=int)
if self.weight.shape != weight_shape:
n_features_expected = self.weight.shape[1]
raise ValueError("Input data has invalid number of features. "
"Got {} features instead of {}."
"".format(n_features, n_features_expected))
self.weight = input_data.T.dot(input_data)
np.fill_diagonal(self.weight, np.zeros(len(self.weight)))
self.n_memorized_samples = n_rows_after_update
示例11: train
def train(self, input_data, target_data, epochs=100):
target_data = format_data(target_data, is_feature1d=True)
output_size = target_data.shape[1]
if output_size != 1:
raise ValueError("Target data must contains only 1 column, got "
"{0}".format(output_size))
input_size = input_data.shape[1]
gating_network = self.gating_network
gating_network_input_size = gating_network.input_layer.size
if gating_network_input_size != input_size:
raise ValueError(
"Gating Network expected get {0} input features, got "
"{1}".format(gating_network_input_size, input_size)
)
networks = self.networks
for epoch in range(epochs):
predictions = []
for i, network in enumerate(networks):
predictions.append(network.predict(input_data))
network.train_epoch(input_data, target_data)
predictions = np.concatenate(predictions, axis=1)
gating_network.train_epoch(input_data, predictions)
示例12: gibbs_sampling
def gibbs_sampling(self, visible_input, n_iter=1):
"""
Makes Gibbs sampling n times using visible input.
Parameters
----------
visible_input : 1d or 2d array
n_iter : int
Number of Gibbs sampling iterations. Defaults to ``1``.
Returns
-------
array-like
Output from the visible units after perfoming n
Gibbs samples. Array will contain only binary
units (0 and 1).
"""
is_input_feature1d = (self.n_visible == 1)
visible_input = format_data(visible_input, is_input_feature1d)
gibbs_sampling = self.methods.gibbs_sampling
input_ = visible_input
for iteration in range(n_iter):
input_ = gibbs_sampling(input_)
return input_
示例13: prediction_error
def prediction_error(self, input_data, target_data=None):
"""
Compute the pseudo-likelihood of input samples.
Parameters
----------
input_data : array-like
Values of the visible layer
Returns
-------
float
Value of the pseudo-likelihood.
"""
is_input_feature1d = (self.n_visible == 1)
input_data = format_data(input_data, is_input_feature1d)
errors = self.apply_batches(
function=self.methods.prediction_error,
input_data=input_data,
description='Validation batches',
show_error_output=True,
)
return average_batch_errors(
errors,
n_samples=len(input_data),
batch_size=self.batch_size,
)
示例14: hidden_to_visible
def hidden_to_visible(self, hidden_input):
"""
Propagates output from the hidden layer backward
to the visible.
Parameters
----------
hidden_input : array-like (n_samples, n_hidden_features)
Returns
-------
array-like
"""
is_input_feature1d = (self.n_hidden == 1)
hidden_input = format_data(hidden_input, is_input_feature1d)
outputs = self.apply_batches(
function=self.methods.hidden_to_visible,
input_data=hidden_input,
description='Visible from hidden batches',
show_progressbar=True,
show_error_output=False,
)
return np.concatenate(outputs, axis=0)
示例15: train
def train(self, input_data):
self.discrete_validation(input_data)
input_data = bin2sign(input_data)
input_data = format_data(input_data, is_feature1d=False)
nrows, n_features = input_data.shape
nrows_after_update = self.n_remembered_data + nrows
if self.check_limit:
memory_limit = ceil(n_features / (2 * log(n_features)))
if nrows_after_update > memory_limit:
raise ValueError("You can't memorize more than {0} "
"samples".format(memory_limit))
weight_shape = (n_features, n_features)
if self.weight is None:
self.weight = zeros(weight_shape, dtype=int)
if self.weight.shape != weight_shape:
raise ValueError("Invalid input shapes. Number of input "
"features must be equal to {} and {} output "
"features".format(*weight_shape))
self.weight = input_data.T.dot(input_data)
fill_diagonal(self.weight, zeros(len(self.weight)))
self.n_remembered_data = nrows_after_update