ValueError: Number of features of the model must match the input

后端 未结 5 1248
谎友^
谎友^ 2020-12-14 12:11

I\'m getting this error when trying to predict using a model I built in scikit learn. I know that there are a bunch of questions about this but mine seems different from the

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 13:02

    Below correction to original answer from Scratch'N'Purr would help solve issues one might face using string as value for new inserted column 'label' -
    train_df = pd.read_csv("Cinderella.csv") train_df['label'] = 1

        score_df = pandas.read_csv("Slaughterhouse_copy.csv")
        score_df['label'] = 2
    
        # Concat
        concat_df = pd.concat([train_df , score_df])
    
        # Create your dummies
        features_df = pd.get_dummies(concat_df)
    
        # Split your data
        train_df = features_df[features_df['label'] == '1]
        score_df = features_df[features_df['label'] == '2]
        ...
    

提交回复
热议问题