Negative R squared but with close predictions I'm getting a pretty bad $R^2$, negative in fact, but the graph, where predicted values are plotted over test values, looks very solid. How is this possible? I'm quite new to DS and have never faced issue like this so any feedback would be very helpful.
$R^2$ metric result:

Graph of lasso regression:

Graph of ridge regression (in comparison to lasso, because its $R^2$ actually makes sense):

PS: code snippet with graph creation:
model = Lasso()

yHat = model.predict(X_test)
mae_test = mae(y_test, yHat)
r2_test = r2_score(y_test, yHat)
_yHat = yHat

fig, ax = plt.subplots(1,1, figsize=(10,7))
ax.plot(sorted(y_test), color='blue', label='test', linestyle='dashed')
ax.plot(sorted(_yHat), color="r", label='prediction', linewidth=.5)
fig.suptitle(name)
fig.legend(loc='best')
fig.tight_layout()  

PPS: predicted values over true values:


As can be seen in the code, you are plotting sorted values of both predictions and true values.
That will lead to a visually apparent pattern where there is none, leading to rank-correlation equal to 1.
What you should plot instead is the raw predictions in the y-axis and the true values in the x-axis. That way, it should be clearer why R-squared is negative. Remember, this is out-of-sample. See this answer to understand why this is possible.
