pandas 改造前后的pycaret输出培训和测试

afdcj2ne  于 2023-05-21  发布在  其他
关注(0)|答案(1)|浏览(118)

我正在尝试使用pycaret构建ML模型。我使用了下面的设置功能

clf = setup(data = df.loc[:, df.columns != 'ID'], target='final_label',session_id=123, 
            categorical_features=['Gender','Country'], 
            fold_strategy='stratifiedkfold', 
            fold=5, fold_shuffle=True, n_jobs=-1, 
            create_clusters=False,polynomial_features=False, 
            polynomial_degree=2, trigonometry_features=False, polynomial_threshold=0.1, 
            remove_multicollinearity=True, multicollinearity_threshold=0.90)

这将使用变量列表初始化该过程,我希望从中提取transformed_train_set和transformed_test_set

我想导出转换前后的训练和测试数据,但pycaret没有任何方法导出这些数据?
当我尝试下面的代码:

train_data = predict_model(rft,data = X_train,raw_score=True)
train_data['phase'] = 'train'
test_data = predict_model(rft,data = X_test,raw_score=True)
test_data['phase'] = 'test'

它抛出错误:

NameError: name 'X_train' is not defined
zfciruhq

zfciruhq1#

您可以使用get_config(variable)导出转换前后的训练和测试数据。

from pycaret.datasets import get_data
from pycaret.classification import *
data = get_data('diabetes', verbose=False)
s = setup(data, target = 'Class variable', session_id = 123, normalize=True, verbose=False)
rf= create_model('rf')

# check all available param
get_config()

X_train = get_config('X_train')
X_train_transformed = get_config('X_train_transformed')

X_test = get_config('X_test')
X_test_transformed = get_config('X_test_transformed')

train_data = predict_model(rf, data = X_train,raw_score=True)
train_data['phase'] = 'train'
train_transformed_data = predict_model(rf, data = X_train_transformed,raw_score=True)
train_transformed_data['phase'] = 'train_transformed'

test_data = predict_model(rf, data = X_test,raw_score=True)
test_data['phase'] = 'test'
test_transformed_data = predict_model(rf, data = X_test_transformed,raw_score=True)
test_transformed_data['phase'] = 'test_transformed'

相关问题