Skip to main content
An example is added.
Source Link

From ValueError: Unknown label type: 'unknown' on y_train I guess you have some unsupported/invalid data type in your y_train or the type is indeed valid but does not match with the RandomForestClassifier expectation.

Please do the followings:

  1. print/plot the y_train and make sure all values make sense. There is a fair chance that HashingVectorizer could not hash some special cases (eg foreign language characters or missing values).
  2. use type or dtype to find out the v_train data type. Make sure it is consistent with RandomForestClassifier expectation.

p.s. as @outlier mentioned, we usually do not transform our labels (y_train in your case). Many classifiers can handle strings/letters as class labels. In case they cannot, we can use a simple mapping such as P -> 0, Q -> 1, etc. The following does the job for you:

from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
encoder.fit(y)
encoded_y = encoder.transform(y)

From ValueError: Unknown label type: 'unknown' on y_train I guess you have some unsupported/invalid data type in your y_train or the type is indeed valid but does not match with the RandomForestClassifier expectation.

Please do the followings:

  1. print/plot the y_train and make sure all values make sense. There is a fair chance that HashingVectorizer could not hash some special cases (eg foreign language characters or missing values).
  2. use type or dtype to find out the v_train data type. Make sure it is consistent with RandomForestClassifier expectation.

p.s. as @outlier mentioned, we usually do not transform our labels (y_train in your case). Many classifiers can handle strings/letters as class labels. In case they cannot, we can use a simple mapping such as P -> 0, Q -> 1, etc.

From ValueError: Unknown label type: 'unknown' on y_train I guess you have some unsupported/invalid data type in your y_train or the type is indeed valid but does not match with the RandomForestClassifier expectation.

Please do the followings:

  1. print/plot the y_train and make sure all values make sense. There is a fair chance that HashingVectorizer could not hash some special cases (eg foreign language characters or missing values).
  2. use type or dtype to find out the v_train data type. Make sure it is consistent with RandomForestClassifier expectation.

p.s. as @outlier mentioned, we usually do not transform our labels (y_train in your case). Many classifiers can handle strings/letters as class labels. In case they cannot, we can use a simple mapping such as P -> 0, Q -> 1, etc. The following does the job for you:

from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
encoder.fit(y)
encoded_y = encoder.transform(y)
Source Link

From ValueError: Unknown label type: 'unknown' on y_train I guess you have some unsupported/invalid data type in your y_train or the type is indeed valid but does not match with the RandomForestClassifier expectation.

Please do the followings:

  1. print/plot the y_train and make sure all values make sense. There is a fair chance that HashingVectorizer could not hash some special cases (eg foreign language characters or missing values).
  2. use type or dtype to find out the v_train data type. Make sure it is consistent with RandomForestClassifier expectation.

p.s. as @outlier mentioned, we usually do not transform our labels (y_train in your case). Many classifiers can handle strings/letters as class labels. In case they cannot, we can use a simple mapping such as P -> 0, Q -> 1, etc.