I´m working on a logistic regression model using Python and I managed to adjust the threshold manually. However, when I save the model using pickle, the threshold doesn´t seem to change. I get exactly the same results for different thresholds. Here´s the code:
filename = 'model202104.sav'
pickle.dump(logreg, open(filename, 'wb'))
loaded_model2 = pickle.load(open(filename, 'rb'))
result = loaded_model2.score(X_test, y_pred)
print(result)
Here´s the code I use to manually change thresholds:
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=.2,random_state=7)
logreg = LogisticRegression(max_iter=10000)
logreg.fit(X_train,y_train)
#y_pred=logreg.predict(X_test)
THRESHOLD=0.5
y_pred=np.where(logreg.predict_proba(X_test)[:,1] > THRESHOLD, 1, 0)
Thanks in advance :)