首页 > 解决方案 > 形状未对齐 sklearn.score

问题描述

import numpy as np 
from sklearn.linear_model import LinearRegression
import pandas as pd 
df=pd.read_csv('train.csv')
X=np.array(df['x'],dtype=np.int)
Y=np.array(df['y'],dtype=np.float)
X=X.reshape(1,-1)
Y=Y.reshape(1,-1)
X=np.nan_to_num(X)
Y=np.nan_to_num(Y)
print(X.shape)
print(Y.shape)
df1=pd.read_csv('test.csv')
a=np.array(df1['x'],dtype=np.int)
b=np.array(df1['y'],dtype=np.float)
a=a.reshape(1,-1)
b=b.reshape(1,-1)
print(a.shape)
print(b.shape)
classifier=LinearRegression()
classifier.fit(X,Y)
accu=classifier.score(a,b) #throws error at this line

classifier.score 给出了形状未对齐的错误。
X.shape 1,700
Y.shape 1,700
a.shape 1,300
b.shape 1,300
但它显示:
ValueError:形状(1,300)和(700,700)未对齐:300(dim 1)!= 700(dim 0)。

标签: pythonmachine-learningregression

解决方案


推荐阅读