I have a dataset that consists of 171 features and 39 labels. I captured both features and labels of the dataset through slicing:

df = pd.read_csv(dir_name + "Labeled Data - New Columns and No Nominal Data.csv")
X = df0.iloc[:, :171]
Y = df0.iloc[:, 171:]

Then I checked the shape of my X and Y arrays:

results to (3103, 171)

results to (3103, 39)

Now my problem is that the y-axis of both numpy arrays are clearly unequal, especially since the features and labels differ in value. Whenever I fit them into the Random Forest Model in order to also get the OOB error, it results to could not broadcast input array from shape (1141,2) into shape (1141,). I am aware that I still need to train test split X and Y, but for now, I will not be doing so.

from sklearn.ensemble import RandomForestClassifier
from sklearn.feature_selection import SelectFromModel

rf = RandomForestClassifier(oob_score=True, random_state=0)

rf.fit(X, Y)
oob_error = 1 - rf.oob_score_

# Print the OOB error
print(f'OOB error: {oob_error:.3f}')

rf = RandomForestClassifier(oob_score=True, random_state=0)

I am quite sure that this error occurs because at least one of the items in the list that I am converting to an array doesn't match the dimensions or the other elements. To solve the error, I have to make sure the dimensions of all elements in my list match, in which now I am not sure how to do it. I am torn apart in using transpose() or other functionalities such as numpy.hstack or numpy.zeros to fill in the y-axis.

Pictures of results:




Random Forest RF

Error Result Error

Your responses would indeed help me a lot, and please do excuse me for some of my errors since I am fairly new in Machine Learning and currently exploring the uses of Random Forest.

Thank you very much



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.