0

I don't know why but its showing index 1 is out of bounds for axis 0 with size 1 on acc[i], Its a program for semi supervised learning. Can someone help me what no should be in np.empty()

nc =np.arange(.40, 1, .03)
acc = np.empty(1)
i = 0
for k in np.nditer(nc):
    conf_ind = df['max'] > k
    X_train1 = np.append(x_train_np, unl_np[conf_ind, :], axis=0)
    Y_train1 = np.append(y_train_np, df.loc[conf_ind, ['lab']])
    clf = svm.SVC(kernel='linear', probability= True, C=1).fit(X_train1, Y_train1)
    acc[i] = clf.score(x_test, y_test)
    i = i + 1
    ```

Note: This is just part of the whole code but the problem is most probably within this code.
  • np.empty(1) returns an array with shape 1, so you can address only array position 0. np.empty(2) will have positions 0 and 1 You should know what size the array should be. – Ze'ev Ben-Tsvi Jun 21 '22 at 14:17
  • If i doesn't change later in the loop, you should set it to 20: (1 - 0.4) / 0.03 = 20 – Ze'ev Ben-Tsvi Jun 21 '22 at 14:30
  • I tried putting both 0 and 2 it's still the same. This error is for empty(2) ```index 2 is out of bounds for axis 0 with size 2 ``` – David Rimo Jun 22 '22 at 16:15
  • you should set empty(20) – Ze'ev Ben-Tsvi Jun 22 '22 at 16:18
  • should I put ```20:(1 - 0.4)/0.003=20 ``` in np.empty() ? – David Rimo Jun 22 '22 at 16:19
  • you are iterating through nc. Now nc length calculation is stop (1) minus start (0.4) divide by step (0.03) so (1 - 0.4) / 0.03 which is 20. So if your index variable i is not changing elsewhere within the for loop then you need to have an array with a length of 20 – Ze'ev Ben-Tsvi Jun 22 '22 at 16:30

0 Answers0