我正在嘗試對測試數(shù)據(jù)集進行預測。我正在使用帶有 MLPRegressor 的 Sklearn 管道。但是,即使我使用“test.csv”,我也只是從訓練集中獲得預測的大小。我在哪里可以修改以獲得長度與測試數(shù)據(jù)相同的預測?train_pipeline.py# Read training datadata = pd.read_csv(data_path, sep=';', low_memory=False, parse_dates=parse_dates)# Fill all None recordsdata[config.TARGET] = data[config.TARGET].fillna(0)# data[config.TARGET] = data[config.TARGET].apply(lambda x: split_join_string(x) if (type(x) == str and len(x.split('.')) > 0) else x)# Divide train and testX_train, X_test, y_train, y_test = train_test_split( data[config.FEATURES], data[config.TARGET], test_size=0.1, random_state=0) # we are setting the seed here# Transform the targety_train = y_train.apply(lambda x: np.log(float(x)) if x != 0 else 0)y_test = y_test.apply(lambda x: np.log(float(x)) if x != 0 else 0)data_test = pd.concat([X_test, y_test], axis=1)# Save the dataset to a '.csv' file without indexdata_test.to_csv(data_path_test, sep=';', index=False)pipeline.order_pipe.fit(X_train[config.FEATURES], y_train)save_pipeline(pipeline_to_persist=pipeline.order_pipe)預測.pydef make_prediction(*, input_data) -> dict: """Make a prediction using the saved model pipeline.""" data = pd.DataFrame(input_data) validated_data = validate_inputs(input_data=data) prediction = _order_pipe.predict(validated_data[config.FEATURES]) output = np.exp(prediction) #score = _order_pipe.score(validated_data[config.FEATURES], validated_data[config.TARGET]) results = {'predictions': output, 'version': _version} _logger.info(f'Making predictions with model version: {_version}' f'\nInputs: {validated_data}' f'\nPredictions: {results}') return results我希望預測的大小為“test.csv”,但實際預測的大小為“train.csv”。我是否需要將測試數(shù)據(jù)集擬合或轉換為“order_pipe”以做出正確大小的預測?
1 回答

婷婷同學_
TA貢獻1844條經(jīng)驗 獲得超8個贊
我解決了這個問題,刪除了一個導致 X_test 大小崩潰的預處理器。因此,X_test 被 X_train 取代,我無法做出正確的預測。
此外,還有另一個預處理器(使用 pd.get_dummies() 創(chuàng)建虛擬對象)插入新列并在 X_test 預測期間帶來更多問題。groupby()
我還替換了那個預處理器,使用and對分類特征進行編碼map()
。
添加回答
舉報
0/150
提交
取消