Input y value in neural network models

Dear there, may i ask about useing the code of C2_W3 in my own data, please? I have 81 samples with 1004 features for each sample. The lable of samples are 0 or 1 (2 classes). The aim to build NN models to classify the 2 classes. X_train.shape: (40, 1004) X_cv.shape: (32, 1004) X_test.shape: (9, 1004)

I can run the model but can’t get the eval_cat_err results (error bleow).

Is this because my y input is 1 hot coded? What format should it be? Do i have to define classes seperately from y when make the input dataset for neurol network training?

2/2 [==============================] - 0s 1ms/step

KeyError Traceback (most recent call last)
File ~.conda\envs\scRNA\lib\site-packages\pandas\core\indexes\, in Index.get_loc(self, key, method, tolerance)
3801 try:
→ 3802 return self._engine.get_loc(casted_key)
3803 except KeyError as err:

File ~.conda\envs\scRNA\lib\site-packages\pandas_libs\index.pyx:138, in pandas._libs.index.IndexEngine.get_loc()

File ~.conda\envs\scRNA\lib\site-packages\pandas_libs\index.pyx:165, in pandas._libs.index.IndexEngine.get_loc()

File pandas_libs\hashtable_class_helper.pxi:2263, in pandas._libs.hashtable.Int64HashTable.get_item()

File pandas_libs\hashtable_class_helper.pxi:2273, in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 2

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
Cell In[26], line 1
----> 1 training_cerr_simple = eval_cat_err(y_train, model_predict_s(X_train))
2 cv_cerr_simple = eval_cat_err(y_cv, model_predict_s(X_cv))

Cell In[21], line 16, in eval_cat_err(y, yhat)
13 incorrect = 0
14 for i in range(m):
15 ### START CODE HERE ###
—> 16 if yhat[i]!=y[i]:
17 incorrect_i=1
18 incorrect+=incorrect_i

File ~.conda\envs\scRNA\lib\site-packages\pandas\core\, in Series.getitem(self, key)
978 return self._values[key]
980 elif key_is_scalar:
→ 981 return self._get_value(key)
983 if is_hashable(key):
984 # Otherwise index.get_value will raise InvalidIndexError
985 try:
986 # For labels that don’t resolve as scalars like tuples and frozensets

File ~.conda\envs\scRNA\lib\site-packages\pandas\core\, in Series._get_value(self, label, takeable)
1086 return self._values[label]
1088 # Similar to Index.get_value, but we do not fall back to positional
→ 1089 loc = self.index.get_loc(label)
1090 return self.index._get_values_for_loc(self, loc, label)

File ~.conda\envs\scRNA\lib\site-packages\pandas\core\indexes\, in Index.get_loc(self, key, method, tolerance)
3802 return self._engine.get_loc(casted_key)
3803 except KeyError as err:
→ 3804 raise KeyError(key) from err
3805 except TypeError:
3806 # If we have a listlike key, _check_indexing_error will raise
3807 # InvalidIndexError. Otherwise we fall through and re-raise
3808 # the TypeError.
3809 self._check_indexing_error(key)

KeyError: 2

You do not haven nearly enough data.
The number of examples should be much greater than the number of features.

Thanks a lot. I agree with you.

For practise, the code should still work? The sample size should not generate the error?

In the course work, the dataset is generated as ‘X, y, centers, classes, std = gen_blobs()’. Is ‘classes’ a neccessay input or i can just put 6 or 2 (classes)? thank you.