Dzien dobry wieczor,
Mam problem z zpisem odczytu modelu ML
model_file = Path("modelLR.bin")
if model_file.is_file():
with open(model_file, 'rb') as f:
LR = joblib.load(f)
else:
LR = LogisticRegression()
LR.fit(xv_train, y_train)
pred_lr = LR.predict(xv_test)
LR.score(xv_test, y_test)
print(classification_report(y_test, pred_lr))
with open(model_file, 'wb') as f:
joblib.dump(LR, f, compress=9)
Jak zladuje model z pliku zapisanego poprzednim razem, to przy wywolaniu
pred_LR = LR.predict(new_xv_test)
mam blad:
ValueError: X has 33822 features, but LogisticRegression is expecting 33945 features as input.
Dla testow zrobilem zapis i odczyt w tej samej sesji i dziala:
LR = LogisticRegression()
LR.fit(xv_train, y_train)
pred_lr = LR.predict(xv_test)
LR.score(xv_test, y_test)
print(classification_report(y_test, pred_lr))
#save model
with open(model_file, 'wb') as f:
joblib.dump(LR, f, compress=9)
#restore model
with open(model_file, 'rb') as f:
LR = joblib.load(f)
...
pred_LR = LR.predict(new_xv_test)