Market Basket Analysis Association_rules - ValueError: cannot call `vectorize` on size 0 inputs unless `otypes` is set - pandas

I am currently running a market basket analysis on my dataset.
When I run my association_rules I get an error.
rules = association_rules(frequent_itemsets, metric="lift", min_threshold=1)
rules.head()
ValueError Traceback (most recent call last)
<ipython-input-47-60252dc62442> in <module>
----> 1 rules = association_rules(frequent_itemsets, metric="lift", min_threshold=1)
2 rules.head()
3 frames
/usr/local/lib/python3.8/dist-packages/numpy/lib/function_base.py in _get_ufunc_and_otypes(self, func, args)
2195 args = [asarray(arg) for arg in args]
2196 if builtins.any(arg.size == 0 for arg in args):
-> 2197 raise ValueError('cannot call `vectorize` on size 0 inputs '
2198 'unless `otypes` is set')
2199
ValueError: cannot call `vectorize` on size 0 inputs unless `otypes` is set
In my dataset their is alot of 0's, I am currently looking into this to see if it is effecting my results.

Related

Unable to find MSE using Tensorflow time series model. Error: 'mean_absolute_error' is not in list

While performing time series weather prediction from tensorflow taken from here https://colab.research.google.com/github/tensorflow/docs/blob/master/site/en/tutorials/structured_data/time_series.ipynb#scrollTo=EN4U1fcMiTYs, while using this code snippet to find the performance in terms of MSE:
x = np.arange(len(performance))
width = 0.3
metric_name = 'mean_absolute_error'
metric_index = lstm_model.metrics_names.index('mean_absolute_error')
I get an error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-80-462945e7d3dd> in <module>
2 width = 0.3
3 metric_name = 'mean_absolute_error'
----> 4 metric_index = lstm_model.metrics_names.index('mean_absolute_error')
5 val_mae = [v[metric_index] for v in val_performance.values()]
6 test_mae = [v[metric_index] for v in performance.values()]
ValueError: 'mean_absolute_error' is not in list
How do I fix this?

Linear regression on Tensor flow Google Collab

I am trying to code a linear regression but I am stuck on this cell, as it returns me an error and I donĀ“t understand how to correct it. Would aprecciate some detailed feedback as to how to change my code to avoid this
Here is the cell that raises the error
error = test_predictions - test_labels
plt.hist(error, bins = 25)
plt.xlabel("Prediction Error [MPG]")
_ = plt.ylabel("Count")
After that I Get:
/usr/local/lib/python3.7/dist-packages/matplotlib/axes/_axes.py:6630: RuntimeWarning: All-NaN slice encountered
xmin = min(xmin, np.nanmin(xi))
/usr/local/lib/python3.7/dist-packages/matplotlib/axes/_axes.py:6631: RuntimeWarning: All-NaN slice encountered
xmax = max(xmax, np.nanmax(xi))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-30-c4d487a4d6e3> in <module>()
1 error = test_predictions - test_labels
----> 2 plt.hist(error, bins = 25)
3 plt.xlabel("Prediction Error [MPG]")
4 _ = plt.ylabel("Count")
5 frames
<__array_function__ internals> in histogram(*args, **kwargs)
/usr/local/lib/python3.7/dist-packages/numpy/lib/histograms.py in _get_outer_edges(a, range)
322 if not (np.isfinite(first_edge) and np.isfinite(last_edge)):
323 raise ValueError(
--> 324 "autodetected range of [{}, {}] is not finite".format(first_edge, last_edge))
325
326 # expand empty range to avoid divide by zero
ValueError: autodetected range of [nan, nan] is not finite```

ValueError: could not broadcast input array from shape (16,18,3) into shape (16)

I was trying to instance segment my RGB images using pixellib library. However, I encountered the problem from segmentImage function. From stacktrace, I found the issue within init.py, and I have no idea why it needs to broadcast from 3D arrays to 1D. 20 Images from another folder I tried earlier didn't counter any of these.
P.S. This was my first question on StackOverflow. if I miss any necessary details, please let me know.
for file in os.listdir(test_path):
abs_test_path = os.path.join(test_path, file)
if file.endswith('.jpg'):
filename = os.path.splitext(file)[0]
if (os.path.isfile(abs_test_path)):
out_path = out_seg_path + filename
segment_image.segmentImage(abs_test_path, show_bboxes=True,
save_extracted_objects=True,
extract_segmented_objects=True)
im_0 = cv2.imread('segmented_object_1.jpg')
cv2.imwrite(out_path + '_1.jpg', im_0)
im_1 = cv2.imread('segmented_object_2.jpg')
cv2.imwrite(out_path + '_2.jpg', im_1)
This is my error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-835299843033> in <module>
15
16 segment_image.segmentImage(abs_test_path, show_bboxes=True,
---> 17 save_extracted_objects=True, extract_segmented_objects=True)
18
19 # segment_image.segmentImage('segmented_object_1.jpg', show_bboxes=True, output_image_name=out_path + '_1.jpg',
~\anaconda3\envs\mask_rcnn\lib\site-packages\pixellib\instance\__init__.py in segmentImage(self, image_path, show_bboxes, extract_segmented_objects, save_extracted_objects, mask_points_values, output_image_name, text_thickness, text_size, box_thickness, verbose)
762 cv2.imwrite(save_path, extracted_objects)
763
--> 764 extracted_objects = np.array(ex, dtype=object)
765
766 if mask_points_values == True:
ValueError: could not broadcast input array from shape (16,18,3) into shape (16)
There isn't enough information to help you.
I don't know what segment_image.segmentImage is, or what it expects. And I don't have your jpg file to test.
I have an idea of why the problem line raises this error, but since it occurs in an unknown function I can't suggest any fixes.
extracted_objects = np.array(ex, dtype=object)
ex probably is a list of arrays, arrays that match in some some dimensions but not others. It's trying to make an object dtype array of those arrays, but due to the mix of shapes it raises an error.
An simple example that raises the same error:
In [151]: ex = [np.ones((3, 4, 3)), np.ones((3, 5, 3))]
In [152]: np.array(ex, object)
Traceback (most recent call last):
Input In [152] in <module>
np.array(ex, object)
ValueError: could not broadcast input array from shape (3,4,3) into shape (3,)

Why I can't loop xmltodict?

Ive'been trying to transform all my logs in a dict through xmltodict.parse function
The thing is, when I try to convert a single row to a variable it works fine
a = xmltodict.parse(df['CONFIG'][0])
Same to
parsed[1] = xmltodict.parse(df['CONFIG'][1])
But when I try to iterate the entire dataframe and store it on a dictionaire I get the following
for ind in df['CONFIG'].index:
parsed[ind] = xmltodict.parse(df['CONFIG'][ind])
---------------------------------------------------------------------------
ExpatError Traceback (most recent call last)
/tmp/ipykernel_31/1871123186.py in <module>
1 for ind in df['CONFIG'].index:
----> 2 parsed[ind] = xmltodict.parse(df['CONFIG'][ind])
/opt/conda/lib/python3.9/site-packages/xmltodict.py in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, disable_entities, **kwargs)
325 parser.ParseFile(xml_input)
326 else:
--> 327 parser.Parse(xml_input, True)
328 return handler.item
329
ExpatError: syntax error: line 1, column 0
Can you try this?
for ind in range(len(df['CONFIG'])):
parsed[ind] = xmltodict.parse(df['CONFIG'][ind])

Convert labels(int) into one-hot vectors for tensorflow

Kindly help me to resolve my error.Thanks
This is my python code:
shape of Y (199584, 1) and data type is int
num_labels = len(np.unique(Y))
simulated_labels = np.eye(num_labels)[Y] # One liner trick!
print simulated_labels
Error:
IndexError Traceback (most recent call last)
in ()
1 num_labels = len(np.unique(Y)) # unique labels 681
2 print num_labels
----> 3 simulated_labels = np.eye(num_labels)[Y] # One liner trick!
4 print simulated_labels
5
IndexError: index 1001 is out of bounds for axis 0 with size 681
You can use tf.one_hot (There are examples in the doc string)