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。形状1,300
b.shape 1,300
但它显示:
ValueError:形状(1,300)和(700,700)未对齐:300(暗淡)
1)!= 700(暗淡0)。