0
max_depth = range(1, 51)
train_score = []
test_score = []

X = vecs_train
y = df_train1.Sentiment

for k in max_depth:
    dt = XGBClassifier(random_state=42, max_depth=k)
    dt.fit(X, y)
    
    train_score.append(dt.score(vecs_train, df_train1.Sentiment))
    test_score.append(dt.score(vecs_dev, df_dev1.Sentiment))
    
plt.plot(max_depth, train_score, label="train")
plt.plot(max_depth, test_score, label="test")
plt.legend()

print(f"Test Score: {np.max(test_score)}")
print(f"n ke: {max_depth[np.argmax(test_score)]}")
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_916/2795825213.py in <module>
      8 for k in max_depth:
      9     dt = XGBClassifier(random_state=42, max_depth=k)
---> 10     dt.fit(X, y)
     11 
     12     train_score.append(dt.score(vecs_train, df_train1.Sentiment))

c:\users\roihan\miniconda3\lib\site-packages\xgboost\core.py in inner_f(*args, **kwargs)
    573         for k, arg in zip(sig.parameters, args):
    574             kwargs[k] = arg
--> 575         return f(**kwargs)
    576 
    577     return inner_f

c:\users\roihan\miniconda3\lib\site-packages\xgboost\sklearn.py in fit(self, X, y, sample_weight, base_margin, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model, sample_weight_eval_set, base_margin_eval_set, feature_weights, callbacks)
   1356         ):
   1357             raise ValueError(
-> 1358                 f"Invalid classes inferred from unique values of `y`.  "
   1359                 f"Expected: {expected_classes}, got {self.classes_}"
   1360             )

ValueError: Invalid classes inferred from unique values of `y`.  Expected: [0 1 2], got [1 2 3]

i use fasttext to make word or vector weights, then i use that vector for DecisionTreeClassifier and it works, but when i use XGBClassifier i get an error message then after i try i don't get a solution for the error like in the picture

halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0