1

I have 3 pickle files

model.pkl
x_train.pkl
y_train.pkl

Now i want to run some coding on what if tool . When i searched i found a base code in internet but i dont know how to run that code with this pickle file. Can someone hlp me ?

pasting the sample code that i found from internet .

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)

So basically I want run widgets part and see in the pickle file that is given. Its a regression model that was build .

since I don't have the source code I don't know how to run with a pickle file . Can someone pls help>

Thanks Meera

1 Answer 1

1
import pandas as pd

model = pd.read_pickle("/yourlocation/model.pkl",compression=None)

These lines will help to unpickle the file and gives the data or information in your model pickle file.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.