Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INFO:root:Epoch[0] Train-mse=49.961319
- INFO:root:Epoch[0] Time cost=0.030
- INFO:root:Epoch[0] Validation-mse=58229.367065
- INFO:root:Epoch[1] Batch [2] Speed: 2000.14 samples/sec mse=361.597036
- INFO:root:Epoch[1] Batch [4] Speed: 2000.14 samples/sec mse=1903.920013
- INFO:root:Epoch[1] Batch [6] Speed: 2000.14 samples/sec mse=6117.729675
- INFO:root:Epoch[1] Batch [8] Speed: 1999.67 samples/sec mse=4203.171875
- INFO:root:Epoch[1] Batch [10] Speed: 2000.14 samples/sec mse=31765.921204
- INFO:root:Epoch[1] Batch [12] Speed: 2000.14 samples/sec mse=6946.003112
- Traceback (most recent call last): File "C:Usersibraheem.vscodeextensionsms-python.python-0.9.1pythonFilesPythonToolsvisualstudio_py_launcher_nodebug.py", line 74, in run
- _vspu.exec_file(file, globals_obj)
- File "C:Usersibraheem.vscodeextensionsms-python.python-0.9.1pythonFilesPythonToolsvisualstudio_py_util.py", line 119, in exec_file
- exec_code(code, file, global_variables)
- File "C:Usersibraheem.vscodeextensionsms-python.python-0.9.1pythonFilesPythonToolsvisualstudio_py_util.py", line 95, in exec_code
- exec(code_obj, global_variables)
- File "c:UsersibraheemDesktopOtherProjectspython_AI_MLUntitled-1.py", line 37, in <module>
- batch_end_callback = mx.callback.Speedometer(batch_size, 2))
- File "C:Python27amd64libsite-packagesmxnetmodulebase_module.py", line 506, in fit
- callback(batch_end_params)
- File "C:Python27amd64libsite-packagesmxnetcallback.py", line 159, in __call__
- speed = self.frequent * self.batch_size / (time.time() - self.tic)
- ZeroDivisionError: float division by zero
- import mxnet as mx
- import numpy as np
- import math
- import logging
- logging.getLogger().setLevel(logging.DEBUG)
- train_size = 50
- train_data = np.random.uniform(0.1, 1, [train_size, 3])
- for i in range(0, train_size):
- train_data[i, 1] *= 25
- train_label = np.array([(-train_data[i][1] + math.sqrt(train_data[i][1] ** 2 - 4 * train_data[i][0] * train_data[i][2])) / (2 * train_data[i][0]) for i in range(train_size)])
- #Evaluation Data
- eval_data = np.array([[7,3,-34],[6,1,-57],[12,5,-3152]])
- eval_label = np.array([2,3,16])
- #training
- batch_size = 1
- train_iter = mx.io.NDArrayIter(train_data,train_label, batch_size, shuffle=True,label_name='lin_reg_label')
- eval_iter = mx.io.NDArrayIter(eval_data, eval_label, batch_size, shuffle=False)
- X = mx.sym.Variable('data')
- Y = mx.symbol.Variable('lin_reg_label')
- fully_connected_layer = mx.sym.FullyConnected(data=X, name='fc1', num_hidden = 1)
- lro = mx.sym.LinearRegressionOutput(data=fully_connected_layer, label=Y, name="lro")
- model = mx.mod.Module(
- symbol = lro ,
- data_names=['data'],
- label_names = ['lin_reg_label']# network structure
- )
- mx.viz.plot_network(symbol=lro)
- model.fit(train_iter, eval_iter,
- optimizer_params={'learning_rate':0.005, 'momentum': 0.9},
- num_epoch=50,
- eval_metric='mse',
- batch_end_callback = mx.callback.Speedometer(batch_size, 2))
- print model.predict(eval_iter).asnumpy()
Add Comment
Please, Sign In to add comment