0

Because my model had a negative prediction, I used the same log method for it, but a problem occurred to me when I do this method, it is true that r2 also reaches 99, but the results of cross validation do not match with the results of the model, now when I do not get log r2 drops to 82, but the results of cross validation are consistent with the results of the model. Do you know a way that I can reach r2 99 and the results of cross validation are consistent with the results of the model?

  • Welcome to Cross Validated! What log method did you use, and why did you use it? – Dave Mar 27 '24 at 23:13
  • thank you so much im so sorry im not an expert in ml so probably i say something wrong my model predict drug dose as a negative value so i run this code
    'model = LinearRegression() y_train_log=np.log(y_train) y_test_log=np.log(y_test) y_val_log=np.log(y_val) model.fit(X_train,y_train_log) test_pred = np.exp(model.predict(X_test)) train_pred =np.exp(model.predict(X_train)) val_pred=np.exp(model.predict(X_val))'
    – Erfan Mollai Mar 27 '24 at 23:18
  • Why shouldn’t the model predictions be negative? Sure, it makes no physical sense, but there is no mathematical restriction that forces non-negative predictions. – Dave Mar 27 '24 at 23:20
  • so you say that should remove log? but it decrease my r2 :( – Erfan Mollai Mar 27 '24 at 23:23
  • $R^2$ is not comparable before and after the log transformation. If you want to force positive values, you can apply a link function in a generalized linear model. $//$ However, when you make a negative prediction after taking the log, doesn’t that mean that your predicted drug dose is $e$ raised to that negative value, since the prediction is a logarithm? – Dave Mar 27 '24 at 23:35
  • thank you so much i got it thanks – Erfan Mollai Mar 27 '24 at 23:39
  • There’s more to it than just raising $e$ to the prediction value. – Dave Mar 27 '24 at 23:42
  • oh I didn't know this I appreciate that – Erfan Mollai Mar 27 '24 at 23:48
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 28 '24 at 01:13

0 Answers0