我有3个泡菜文件
model.pkl
x_train.pkl
y_train.pkl
现在我想在what if工具上运行一些代码。当我搜索时,我在互联网上找到了一个基本代码,但我不知道如何用这个pickle文件运行这些代码。有人能帮我吗?
粘贴我从互联网上找到的示例代码。
features=df.drop('area',axis=1)
target=df[["area"]]
X_train, X_test, y_train, y_test = train_test_split(features, target, test_size=0.2)
label_encoder=preprocessing.LabelEncoder()
X_train['month']=label_encoder.fit_transform((X_train['month']))
X_train[‘day’]=label_encoder.fit_transform((X_train['day']))
X_test['month']=label_encoder.fit_transform((X_test['month']))
X_test['day']=label_encoder.fit_transform((X_test['day']))
X_train
params = {'n_estimators': 200, 'max_depth': 10,
'learning_rate': 0.1, 'loss': 'ls','random_state':0}
reg_mod = GradientBoostingRegressor(**params)
reg_mod.fit(X_train, y_train)
def adjust_prediction(z):
testing_data = pd.DataFrame(X_test, columns=X_test.columns.tolist())
return reg.predict(testing_data)
from witwidget.notebook.visualization import WitConfigBuilder
from witwidget.notebook.visualization import WitWidget
num_data= 2000
tool_height = 1000
test_examples = np.hstack((X_test[:num_data].values,y_test[:num_data]))
config_builder = (WitConfigBuilder(test_examples.tolist(), X_test.columns.tolist() + ["area"])
.set_custom_predict_fn(adjust_prediction)
.set_target_feature('area')
.set_model_type('regression'))
WitWidget(config_builder, height=tool_height)
所以基本上我想要运行部件并在给出的pickle文件中看到。这是一个建立起来的回归模型。
因为我没有源代码,所以我不知道如何运行一个pickle文件。有没有人能请help>
谢谢米拉
转载请注明出处:http://www.hbbinz.com/article/20230526/1133558.html