I participate in the Titanic: Machine Learning from Disaster competition on Kaggle. My kernel worked, but suddenly there were errors for the Random Forest and Gradient Boosting Classifier methods; I don’t remember any special changes.
X_train = train_df Y_train = targets X_test = test_df.copy() X_train.shape, Y_train.shape, X_test.shape Результат: ((891, 14), (891,), (418, 14)) # Random Forest rf = RandomForestClassifier(n_estimators=350) rf.fit(X_train, Y_train) Y_pred = random_forest.predict(X_test) rf.score(X_train, Y_train) acc_random_forest = round(random_forest.score(X_train, Y_train) * 100, 2) acc_random_forest # Gradient Boosting Classifier gb = GradientBoostingClassifier() gb.fit(X_train, Y_train) Y_pred = gbk.predict(X_test) acc_gbk = round(gbk.score(X_train, Y_train) * 100, 2) acc_gbk
Mistake:
ValueError: Number of features of the model must match the input. Model n_features is 12 and input n_features is 14
I would be very grateful if someone can tell what could be the problem. If necessary, I can give a link to the kernel, provide other data.
X_train.shape
,Y_train.shape
immediately beforerf.fit(X_train, Y_train)
and beforegb.fit(X_train, Y_train)
? - MaxUrf
object, and predict using arandom_forest
object, which is not declared anywhere ?? Yes, and I did not see errors from the question in the kernel - MaxU