我正在研究具有 16 個特征的多維資料的回歸模型(決策樹)。模型 r2_score 為 0.97。y test 和 y predict 情節看起來錯得離譜!x 的范圍不一樣。

你能告訴我有什么問題嗎?
我也試過用一維擬合模型來檢查圖中的 x 范圍,但它只是明顯降低了分數,而且圖仍然很奇怪!
uj5u.com熱心網友回復:
Matplotlib 的plot函式通過按繪制順序連接點來繪制一條線。您看到一團糟的原因是這些點沒有沿 x 軸排序。
在回歸模型中,您有一個函式f(x) -> R,f這里是您的決策樹,x位于 16 維空間中。但是,您不能x沿 x 軸對具有 16 個維度的 進行排序。
相反,您可以做的只是將每個指標的基本事實和預測值繪制為散點圖:
import numpy as np
# Here, I'm assuming y_DT_5 is either a 1D array or a column vector.
# If necessary, change the argument of np.arange accordingly to get the number of values
idxs = np.arange(len(y_DT_5))
plt.figure(figsize=(16,4))
plt.scatter(x=idxs, y=y_DT_5, marker='x') # Plot each ground truth value as separate pts
plt.scatter(x=idxs, y=y_test, marker='.') # Plot each predicted value as separate points
如果您的模型有效,則在每個索引處繪制的 2 個點應該沿 y 軸靠近。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/537816.html
