'cv2.cv2' has no attribute 'EM' - python

I am getting the above error.
I Already installed opencv-contrib module but still not working out
def dictionary(descriptors, N):
em = cv2.EM(N)
em.train(descriptors)
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/Ankuran Das/Desktop/Pyhton/Case/fishvec.py', wdir='C:/Users/Ankuran Das/Desktop/Pyhton/Case')
File "D:\Anaconda\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "D:\Anaconda\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Ankuran Das/Desktop/Pyhton/Case/fishvec.py", line 141, in
gmm = generate_gmm(working_folder,args.number)
File "C:/Users/Ankuran Das/Desktop/Pyhton/Case/fishvec.py", line 87, in generate_gmm
means, covs, weights = dictionary(words, N)
File "C:/Users/Ankuran Das/Desktop/Pyhton/Case/fishvec.py", line 16, in dictionary
em = cv2.EM.train(N)
AttributeError: module 'cv2.cv2' has no attribute 'EM'

Try the following lines of codes:
em = cv2.ml.EM_create()
em.setClustersNumber(N)
em.trainEM(descriptors)

Related

ValueError: 'transform' must be an instance of 'matplotlib.transform.Transform'

im new into this new languaje named python and im trying to use matplotlib
here my code :
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()
a simple example from pyplot, however when i run it it gaves me the following log
runfile('C:/Users/Alex/.spyder-py3/temp.py', wdir='C:/Users/Alex/.spyder-py3')
Traceback (most recent call last):
File "<ipython-input-22-b33263e553df>", line 1, in <module>
runfile('C:/Users/Alex/.spyder-py3/temp.py', wdir='C:/Users/Alex/.spyder-py3')
File "C:\Users\Alex\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
execfile(filename, namespace)
File "C:\Users\Alex\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Alex/.spyder-py3/temp.py", line 2, in <module>
plt.plot([1, 2, 3, 4])
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2811, in plot
is not None else {}), **kwargs)
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 935, in gca
return gcf().gca(**kwargs)
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 578, in gcf
return figure()
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 525, in figure
**kwargs)
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 3217, in new_figure_manager
fig = fig_cls(*args, **kwargs)
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\figure.py", line 361, in __init__
self.bbox = TransformedBbox(self.bbox_inches, self.dpi_scale_trans)
File "C:\Users\Alex\Anaconda3\lib\site-packages\matplotlib\transforms.py", line 1036, in __init__
raise ValueError("'transform' must be an instance of "
ValueError: 'transform' must be an instance of 'matplotlib.transform.Transform'
i dont know what im doing wrong im using python 3.7.1 can someone help me?

XGBoost error 'DMatrix' object does not support indexing

I am trying to use XGBoost library using .train function and DMatrix but I am a little stuck because of an error :
Traceback (most recent call last):
File "", line 1, in
runfile('E:/CrossValidation.py', wdir='E:/')
File
"C:\Users\users\Anaconda3\envs\Lightgbm\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 705, in runfile
execfile(filename, namespace)
File
"C:\Users\users\Anaconda3\envs\Lightgbm\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "E:/CrossValidation.py", line 218, in
mainXGB()
File "E:/CrossValidation.py", line 214, in mainXGB
crossval_preds, val_preds = cv.train(X_data=X_train.values, y_data=y_train.values, X_test=X_val.values, params=xgb_params)
File "E:/CrossValidation.py", line 136, in train
early_stopping_rounds=early_stopping_rounds)
File
"C:\Users\users\Anaconda3\envs\Lightgbm\lib\site-packages\xgboost\training.py",
line 204, in train
xgb_model=xgb_model, callbacks=callbacks)
File
"C:\Users\users\Anaconda3\envs\Lightgbm\lib\site-packages\xgboost\training.py",
line 32, in _train_internal
bst = Booster(params, [dtrain] + [d[0] for d in evals])
File
"C:\Users\users\Anaconda3\envs\Lightgbm\lib\site-packages\xgboost\training.py",
line 32, in
bst = Booster(params, [dtrain] + [d[0] for d in evals])
TypeError: 'DMatrix' object does not support indexing
Here my piece of code :
dtrain = xgb.DMatrix(X_data[train_idx], label=np.log1p(y_data[train_idx])) # datas.slice(train_idx)
dtest = xgb.DMatrix(X_data[val_idx], label=np.log1p(y_data[val_idx]))
print('data created for xgboost')
model = self.model_base.train(params=params, dtrain=dtrain, num_boost_round=number_iteration, evals=[dtest], early_stopping_rounds=early_stopping_rounds)
Does anyone know how to solve the problem ?
The problem is with the evals argument. A list of tuples is expected, so change evals=[dtest] to evals=[(dtest, "Test")].

Getting NotImplementedError when using data from dask when running an OLS regression

What I want to do is actually pretty simple. I want to run a OLS regression by using data from dask. It is fine, if I just install data into dask dataframe or I use pandas (but I get memory error when I use Pandas).
# import modules
import statsmodels.formula.api as smf
import dask.dataframe as dd
df = dd.read_csv(input_file)
mod = smf.ols(formula='lnq ~ lnp + lnp:C(product_code)+ C(product_code)', data=df)
results = mod.fit(cov_type = 'cluster', cov_kwds={'groups': df['product_code']})
print(results.summary())
However, I get the following error:
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "H:/yoox_3.py", line 11, in <module>
mod = smf.ols(formula='lnq ~ lnp + lnp:C(product_code)+ C(product_code)', data=df)
File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\base\model.py", line 155, in from_formula
missing=missing)
File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\formula\formulatools.py", line 68, in handle_formula_data
NA_action=na_action)
File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\highlevel.py", line 310, in dmatrices
NA_action, return_type)
File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\highlevel.py", line 165, in _do_highlevel_design
NA_action)
File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\highlevel.py", line 70, in _try_incr_builders
NA_action)
File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\build.py", line 696, in design_matrix_builders
NA_action)
File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\build.py", line 448, in _examine_factor_types
done = cat_sniffers[factor].sniff(value)
File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\categorical.py", line 204, in sniff
for value in data:
File "C:\ProgramData\Anaconda3\lib\site-packages\dask\dataframe\core.py", line 1703, in __getitem__
raise NotImplementedError()
NotImplementedError
Any ideas?
I don't believe that statsmodels offers support for dask dataframes

some error happened when I run the example code in the theano scan api guide

Win 10 x64, conda, theano 0.9, python 3.6.1, spyder 3.1.4, IPython 6.0.0
When I test the code in scan api tutorial Iterating over the first dimension of a tensor: Calculating a polynomial , i.e.
import theano
import numpy as np
import theano.tensor as T
from theano import In
coefficients = theano.tensor.vector("coefficients")
x = T.scalar("x")
max_coefficients_supported = 10000
# Generate the components of the polynomial
components, updates = theano.scan(fn=lambda coefficient, power, free_variable: coefficient * (free_variable ** power),
outputs_info=None,
sequences=[coefficients, theano.tensor.arange(max_coefficients_supported)],
non_sequences=x)
# Sum them up
polynomial = components.sum()
# Compile a function
calculate_polynomial = theano.function(inputs=[coefficients, x], outputs=polynomial)
spyder throw the error :
ERROR (theano.gof.opt): Optimization failure due to: local_subtensor_merge
ERROR (theano.gof.opt): node: Subtensor{:int64:}(coefficients[0:], ScalarFromTensor.0)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: Elemwise{switch,no_inplace}.0 has no test value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 1982, in process_node
replacements = lopt.transform(node)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 3051, in local_subtensor_merge
out = subtens(x, *sl_ins)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 615, in __call__
node = self.make_node(*inputs, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\subtensor.py", line 474, in make_node
inputs = tuple(self.my_as_scalar(a) for a in inputs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\subtensor.py", line 474, in <genexpr>
inputs = tuple(self.my_as_scalar(a) for a in inputs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\subtensor.py", line 459, in my_as_scalar
return theano.tensor.scalar_from_tensor(a)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (Elemwise{switch,no_inplace}.0) of Op ScalarFromTensor(Elemwise{switch,no_inplace}.0) missing default value.
ERROR (theano.gof.opt): Optimization failure due to: local_subtensor_merge
ERROR (theano.gof.opt): node: Subtensor{:int64:}(Subtensor{int64::}.0, ScalarFromTensor.0)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: Elemwise{minimum,no_inplace}.0 has no test value
Backtrace when that variable is created:
File "C:\Users\sejab\Miniconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2683, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2793, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2847, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-a340056dd686>", line 1, in <module>
runfile('D:/WorkSpace/Python/Bayes/temp_temp.py', wdir='D:/WorkSpace/Python/Bayes')
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/WorkSpace/Python/Bayes/temp_temp.py", line 25, in <module>
non_sequences=x)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 1982, in process_node
replacements = lopt.transform(node)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 3033, in local_subtensor_merge
ushape[pos_2]))
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 2880, in merge_two_slices
sl2, reverse2 = get_canonical_form_slice(slice2, len2)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\subtensor.py", line 155, in get_canonical_form_slice
stop_plus_len = stop + length
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\var.py", line 128, in __add__
return theano.tensor.basic.add(self, other)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (Elemwise{minimum,no_inplace}.0) of Op Elemwise{add,no_inplace}(Elemwise{minimum,no_inplace}.0, TensorConstant{10000}) missing default value.
Backtrace when that variable is created:
File "C:\Users\sejab\Miniconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2683, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2793, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2847, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-a340056dd686>", line 1, in <module>
runfile('D:/WorkSpace/Python/Bayes/temp_temp.py', wdir='D:/WorkSpace/Python/Bayes')
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/WorkSpace/Python/Bayes/temp_temp.py", line 25, in <module>
non_sequences=x)
ERROR (theano.gof.opt): Optimization failure due to: local_shape_to_shape_i
ERROR (theano.gof.opt): node: Shape(coefficients[0:])
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: Elemwise{sub,no_inplace}.0 has no test value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 1982, in process_node
replacements = lopt.transform(node)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 1884, in local_shape_to_shape_i
ret = shape_feature.make_vector_shape(node.inputs[0])
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 1275, in make_vector_shape
return make_vector(*self.shape_of[r])
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (Elemwise{sub,no_inplace}.0) of Op MakeVector{dtype='int64'}(Elemwise{sub,no_inplace}.0) missing default value.
ERROR (theano.gof.opt): Optimization failure due to: local_shape_to_shape_i
ERROR (theano.gof.opt): node: Shape(coefficients)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: Shape_i{0}.0 has no test value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 1982, in process_node
replacements = lopt.transform(node)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 1884, in local_shape_to_shape_i
ret = shape_feature.make_vector_shape(node.inputs[0])
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 1275, in make_vector_shape
return make_vector(*self.shape_of[r])
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (Shape_i{0}.0) of Op MakeVector{dtype='int64'}(Shape_i{0}.0) missing default value.
ERROR (theano.gof.opt): Optimization failure due to: local_shape_to_shape_i
ERROR (theano.gof.opt): node: Shape(coefficients)
ERROR (theano.gof.opt): TRACEBACK:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: Shape_i{0}.0 has no test value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 1982, in process_node
replacements = lopt.transform(node)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 1884, in local_shape_to_shape_i
ret = shape_feature.make_vector_shape(node.inputs[0])
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 1275, in make_vector_shape
return make_vector(*self.shape_of[r])
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (Shape_i{0}.0) of Op MakeVector{dtype='int64'}(Shape_i{0}.0) missing default value.
ERROR (theano.gof.opt): SeqOptimizer apply <theano.tensor.opt.FusionOptimizer object at 0x000002E6B6947860>
ERROR (theano.gof.opt): Traceback:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: <float64> has no test value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 235, in apply
sub_prof = optimizer.optimize(fgraph)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 87, in optimize
ret = self.apply(fgraph, *args, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 7289, in apply
new_outputs = self.optimizer(node)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\tensor\opt.py", line 7133, in local_fuse
return_list=True)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (<float64>) of Op pow(<float64>, <int64>) missing default value.
ERROR (theano.gof.opt): SeqOptimizer apply <theano.compile.mode.AddDestroyHandler object at 0x000002E6B539FA20>
ERROR (theano.gof.opt): Traceback:
ERROR (theano.gof.opt): Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 625, in __call__
storage_map[ins] = [self._get_test_value(ins)]
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 581, in _get_test_value
raise AttributeError('%s has no test value %s' % (v, detailed_err_msg))
AttributeError: Sum{acc_dtype=float64}.0 has no test value
Backtrace when that variable is created:
File "C:\Users\sejab\Miniconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2683, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2793, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2847, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-a340056dd686>", line 1, in <module>
runfile('D:/WorkSpace/Python/Bayes/temp_temp.py', wdir='D:/WorkSpace/Python/Bayes')
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/WorkSpace/Python/Bayes/temp_temp.py", line 27, in <module>
polynomial = components.sum()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 235, in apply
sub_prof = optimizer.optimize(fgraph)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\opt.py", line 87, in optimize
ret = self.apply(fgraph, *args, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\compile\mode.py", line 103, in apply
fgraph.replace_validate(o, _output_guard(o),
File "C:\Users\sejab\Miniconda3\lib\site-packages\theano\gof\op.py", line 639, in __call__
(i, ins, node, detailed_err_msg))
ValueError: Cannot compute test value: input 0 (Sum{acc_dtype=float64}.0) of Op OutputGuard(Sum{acc_dtype=float64}.0) missing default value.
Backtrace when that variable is created:
File "C:\Users\sejab\Miniconda3\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2683, in run_cell
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2793, in run_ast_nodes
if self.run_code(code, result):
File "C:\Users\sejab\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2847, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-a340056dd686>", line 1, in <module>
runfile('D:/WorkSpace/Python/Bayes/temp_temp.py', wdir='D:/WorkSpace/Python/Bayes')
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\sejab\Miniconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/WorkSpace/Python/Bayes/temp_temp.py", line 27, in <module>
polynomial = components.sum()
Because other code runs well, it seems theano.function induced the problem. Although I tried use In() to add test value to coefficients and x, the problem also stand there.
Ok, I have found a similar question on the official site Creating a step-function: Optimization failure due to: local_subtensor_merge. It may be caused by Pymc3 default settings. There they gave several ways. I use test values as noted in the last comment and set
theano.config.compute_test_value = "warn"
the errors are removed.

Python wired index out of bound

I was trying to create a volume weighted average price using python.
Here is my code:
vwap = []
for i in range(window, int(price_times_qty)):
vol_total = 0
vol_price = 0
for j in range(window):
vol_total = vol_total + lastqty[i-j]
vol_price = vol_price + lastqty[i-j] * lastprice[i-j]
vwap.append( vol_price / vol_total )
I believe my idea is right, but when I execute the code, I have the error:
Traceback (most recent call last):
File "<ipython-input-9-9724942aa7be>", line 1, in <module>
runfile('/home/intern2/Desktop/VWAP/vwap-v1.py', wdir='/home/intern2/Desktop/VWAP')
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 586, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "/home/intern2/Desktop/VWAP/vwap-v1.py", line 25, in <module>
vol_total = vol_total + lastqty[i-j]
IndexError: index out of bounds
I just have no idea why the error is index out of bound. When I check my code, I think the index is well within the bound.
Could anyone please help me with it?

Categories