python - 形状未对齐 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)。
解决方案
推荐阅读
- android - FCM push not wokring in one plus 8
- python - Selenium Python:循环中的execute_script问题
- python-behave - 在 VS 代码中,我尝试使用 python、selenium 解决问题,但我没有得到正确的输出。你能告诉我问题出在哪里吗?
- c# - .Net核心流利验证接受空或以给定精度接受
- php - 使用 Stripe Elements 将卡详细信息保存给客户
- parse-platform - 将云功能从 Parse-server 2.0 升级到 3.0
- java - hibernate @ColumnTransformer 不适用于更新命名查询
- r - RShiny 中的字符串类型全局变量
- angular - 角激活路线获取参数 - 不工作
- reactjs - React - 领域结果作为对象列表