python - RBM code. AttributeError: 'str' object has no attribute 'shape'. When I try input dataset from excel -
i'm beginner in code , python. want see how code (rbm) works. , try input data excel.
from __future__ import print_function import numpy np import openpyxl class rbm: def __init__(self, num_visible, num_hidden): self.num_hidden = num_hidden self.num_visible = num_visible self.debug_print = true np_rng = np.random.randomstate(1234) self.weights = np.asarray(np_rng.uniform( low=-0.1 * np.sqrt(261. / (num_hidden + num_visible)), high=0.1 * np.sqrt(261. / (num_hidden + num_visible)), size=(num_visible, num_hidden))) self.weights = np.insert(self.weights, 0, 0, axis = 0) self.weights = np.insert(self.weights, 0, 0, axis = 1) def train(self, data, max_epochs = 1000, learning_rate = 0.1): """ train machine. parameters ---------- data: matrix each row training example consisting of states of visible units. """ num_examples = data.shape[0] # insert bias units of 1 first column. data = np.insert(data, 0, 1, axis = 1) .... # ignore bias units (the first column), since they're set 1. return samples[:,1:] def _logistic(self, x): return 1.0 / (1 + np.exp(-x)) if __name__ == '__main__': r = rbm(num_visible = 1, num_hidden = 261) training_data = 'data1.xlsx' wb = openpyxl.load_workbook(training_data) sheet = wb.get_sheet_by_name('sheet1') rowofcellobjects in sheet['f2':'f262']: cellobj in rowofcellobjects: print(cellobj.coordinate, cellobj.value) r.train(training_data, max_epochs = 5000) print(r.weights) print(r.run_visible)
but message when running.
file "c:/users/user/cx.py", line 39, in train
num_examples = data.shape[0]
attributeerror: 'str' object has no attribute 'shape'
what should do?
Comments
Post a Comment