Python 如何解释普通岭回归的打印结果(选中编辑)

Python 如何解释普通岭回归的打印结果(选中编辑),python,plot,regression,Python,Plot,Regression,我试图将我的回归结果形象化(第一次做回归时要仁慈)。是我下面的例子,但它创建了一个混乱的情节(tbh我采取了这个例子的表面价值)。我有两个问题。一是可视化。另一个错误是,我在尝试打印x\u validate与y\u validate时遇到的错误。我得到ValueError:x和y的大小必须相同,但它们都有56行。代码如下: # This is where I create the three parts bow.fillna(0, inplace=True) x_train, x_validat

我试图将我的回归结果形象化(第一次做回归时要仁慈)。是我下面的例子,但它创建了一个混乱的情节(tbh我采取了这个例子的表面价值)。我有两个问题。一是可视化。另一个错误是,我在尝试打印
x\u validate
y\u validate
时遇到的错误。我得到
ValueError:x和y的大小必须相同
,但它们都有
56行
。代码如下:

# This is where I create the three parts
bow.fillna(0, inplace=True)
x_train, x_validate, x_test = np.split(bow.sample(frac=1), [int(.6*len(bow)), int(.8*len(bow))])
y_train = x_train['Rating']
y_validate = x_validate['Rating']
y_test = x_test['Rating']
x_train.drop('Rating', 1, inplace=True)
x_validate.drop('Rating', 1, inplace=True)
x_test.drop('Rating', 1, inplace=True) 

# This is the regression part
regr = m.OrdinalRidge()
regr.fit(x_train, y_train)
y_pred = regr.predict(x_validate)

# This is the plotting
plt.scatter(x_validate, y_validate,  color='black')  # <-- Here is where I get the error
plt.plot(x_validate, y_pred, color='blue', linewidth=1)
plt.xticks(())
plt.yticks(())
plt.show()
这就是结果图的样子:


我如何解释回归是否表现良好?我有点迷路了…

为了绘图工作,特征的尺寸必须与输出的尺寸相匹配。X和Y的尺寸必须精确匹配,因此您必须使用PCA降低X的尺寸:

from sklearn.decomposition import PCA

pca = PCA(n_components = n) # the n will be 2 here since y in your case has 2 columns
pca.fit(x_train)
x_train = pca.transform(x_train)

Thx,但如果我这样做,我不会丢失数据吗?@Stefano,你可以将其仅用于可视化,并对正常数据进行回归以获得帮助。如果不太麻烦的话,我可以请你看一下编辑吗?@Stefano,我不完全确定,但我认为问题在于y列中的(1.0,2.0…5.0)值是离散值,而不是连续值,回归需要将连续值作为y来工作。事实上,它们是离散的,但这就是为什么我使用顺序回归(我认为这就是它的目的,但我可能错了)
from sklearn.decomposition import PCA

pca = PCA(n_components = n) # the n will be 2 here since y in your case has 2 columns
pca.fit(x_train)
x_train = pca.transform(x_train)