-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Problem: not saving model correctly
catboost version: 0.21
python 3.7.6
Operating System: Win 10
CPU: i7
Commandline:
python test.py
result:
{} None
{} None
test.zip (with saved model files)
test.py:
import pickle
import pandas as pd
from catboost import Pool, CatBoostRegressor
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
boston = load_boston()
X = boston.data
y = boston.target
X = pd.DataFrame(X, columns=boston.feature_names)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1/10, random_state=1)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=1/9)
c = CatBoostRegressor(early_stopping_rounds=50, verbose=0)
c.fit(
Pool(X_train, y_train),
eval_set=Pool(X_val, y_val),
)
c.save_model('model.cbm')
with open('model.pkl', 'wb') as f:
pickle.dump(c, f, pickle.HIGHEST_PROTOCOL)
c_load = CatBoostRegressor()
c_load.load_model('model.cbm')
with open('model.pkl', 'rb') as f:
c_load_pkl = pickle.load(f)
print(c_load.get_best_score(), c_load.get_best_iteration())
print(c_load_pkl.get_best_score(), c_load_pkl.get_best_iteration())
mityabeldii