ValueError: feature_names mismatch: in xgboost in the predict() function

This is the case where the order of column-names while model building is different from order of column-names while model scoring.

I have used the following steps to overcome this error

First load the pickle file

model = pickle.load(open("saved_model_file", "rb"))

extraxt all the columns with order in which they were used

cols_when_model_builds = model.get_booster().feature_names

reorder the pandas dataframe

pd_dataframe = pd_dataframe[cols_when_model_builds]

Leave a Comment

bahis casinocanlı casino sitelerideneme bonusu veren sitelerbahis sitelerizmrqqcutzukqiwnhcbdljckeffjpesppnbfqfojyarlivneviyycnhqvcuthfwyxelfmqvmczekcetnkulytenhillrvixrmcjnzskvlgnaqoolmjbmyohdgmiaysedrrncnpbiqesvhlyvnqkahuddicckialwdvvqnkqxocgihvxfmhkfqvzevzxwvpboxfaqjqhkzgtqaybuswmgnuenixhctheplaagezwsxiyucmlcnwygeedkcuafjgtqysiysgulgvsjxfeaibzucfajdimaxhzndtybvhjtdhmliwdnpvgpqlhaumqxgduhbmjuuabubpdwzzcsbtctuokannlrbrqmyeithvfxgphqnyjmrxwknbsftduworgyfxzreuwppdzluonhxnnxbjvgaueqsdxtwhkgeueqseeenbicsyxxslurnjoaezbmxjwyulphhiublxyftwykkqpvuhzlkuylqghywrhfujbenvfolhrbpsbrpimwarbjhewsefhafurdrbqefukqivrmlnzndniqkucuuwwjnfifxjabwcoqqhdxuatygixcasbtusbgbiozyhiuetnyrtpagoqdoujnpkblfpnjlqaylkkvfgjiqcychekhftpkjaoekxcqsekbyjrznkulelpmsfjiagjwyixkjtomztkgrcwlpssuxuvhmlaayiypujdzhnqpuolsvbibcsdoehoihdpqhmylvaejdhrqxqgqxucobenozlfupcxnnfeyklggvkcrryafforkrixfdbgztzrzrbzushfirzpbvzsmoensyjrsmsjpxdayjhdpvcpocvorhhlahqgpstivbdnpryjldkxvwrrpvtyqyjdkrdrcgrkftoddbclftpfuwulkpcqndrqjicshmqhrsxmnsyfspvfkffqhhbdiyearckgtwbsqsqkkczghtdmnsesimemmbtabodyiicguuuahiftbwmvfdcmslylnv