ArtLabss / tennis-tracking

Open-source Monocular Python HawkEye for Tennis
https://www.artlabs.tech
The Unlicense
419 stars 100 forks source link

AssertionError: X must have unique column indices, but found Int64Index([0, 0, 0], dtype='int64') #21

Closed madeel6233 closed 1 year ago

madeel6233 commented 1 year ago

Hi I am getting this error when I am trying to detect the bounce. Here is my code for detecting bounce.

bounce=1
if bounce == 1:
  # Predicting Bounces 
  test_df = pd.DataFrame({'x': [coord[0] for coord in xy[:-1]], 'y':[coord[1] for coord in xy[:-1]], 'V': V})

  # df.shift
  for i in range(20, 0, -1): 
    test_df[f'lagX_{i}'] = test_df['x'].shift(i, fill_value=0)
  for i in range(20, 0, -1): 
    test_df[f'lagY_{i}'] = test_df['y'].shift(i, fill_value=0)
  for i in range(20, 0, -1): 
    test_df[f'lagV_{i}'] = test_df['V'].shift(i, fill_value=0)

  test_df.drop(['x', 'y', 'V'], 1, inplace=True)

  Xs = test_df[['lagX_20', 'lagX_19', 'lagX_18', 'lagX_17', 'lagX_16',
        'lagX_15', 'lagX_14', 'lagX_13', 'lagX_12', 'lagX_11', 'lagX_10',
        'lagX_9', 'lagX_8', 'lagX_7', 'lagX_6', 'lagX_5', 'lagX_4', 'lagX_3',
        'lagX_2', 'lagX_1']]
  Xs = from_2d_array_to_nested(Xs.to_numpy())
  Xs.columns = [1]

  Ys = test_df[['lagY_20', 'lagY_19', 'lagY_18', 'lagY_17',
        'lagY_16', 'lagY_15', 'lagY_14', 'lagY_13', 'lagY_12', 'lagY_11',
        'lagY_10', 'lagY_9', 'lagY_8', 'lagY_7', 'lagY_6', 'lagY_5', 'lagY_4',
        'lagY_3', 'lagY_2', 'lagY_1']]
  Ys = from_2d_array_to_nested(Ys.to_numpy())
  Ys.columns = [2]

  Vs = test_df[['lagV_20', 'lagV_19', 'lagV_18',
        'lagV_17', 'lagV_16', 'lagV_15', 'lagV_14', 'lagV_13', 'lagV_12',
        'lagV_11', 'lagV_10', 'lagV_9', 'lagV_8', 'lagV_7', 'lagV_6', 'lagV_5',
        'lagV_4', 'lagV_3', 'lagV_2', 'lagV_1']]
  Vs = from_2d_array_to_nested(Vs.to_numpy())
  Vs.columns = [3]

  X = pd.concat([Xs, Ys, Vs], 1)

  # load the pre-trained classifier  
  clf = load(open('clf.pkl', 'rb'))

predcted = clf.predict(X)

Following is the detailed error

105   clf = load(open('clf.pkl', 'rb'))
    106 
--> 107   predcted = clf.predict(X)
    108   idx = list(np.where(predcted == 1)[0])
    109   idx = np.array(idx) - 10

5 frames
[/usr/local/lib/python3.7/dist-packages/sktime/datatypes/_series/_check.py](https://localhost:8080/#) in check_pddataframe_series(obj, return_metadata, var_name)
     74     # check that columns are unique
     75     msg = f"{var_name} must have " f"unique column indices, but found {obj.columns}"
---> 76     assert obj.columns.is_unique, msg
     77 
     78     # check whether the time index is of valid type

AssertionError: X must have unique column indices, but found Int64Index([0, 0, 0], dtype='int64')
madeel6233 commented 1 year ago

Also here is the screenshot for the X.head()

image
shukkkur commented 1 year ago

Hi @madeel6233! My guess from the error message which says MUST HAVE UNIQUE COLUMN INDICES Try renaming the columns to 0, 1, 2 X.columns = [0, 1, 2] Let me know how it goes 🙂

shukkkur commented 1 year ago

Closing this issue, due to inactivity.