ValueError:操作数无法与形状一起广播(20,2)(20,)

时间:2015-03-08 19:02:58

标签: python scikit-learn bayesian

我正在Parkinson's Telemonitoring Data Set使用sklearn构建贝叶斯岭回归。这是代码:

import math
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn import linear_model


data1 = pd.read_csv("data.csv")
msk = np.random.rand(len(data1)) < 0.66
train =  data1[msk]
test = data1[~msk]
y = train[['motor_UPDRS','total_UPDRS']]
X = train.drop('motor_UPDRS',axis = 1)
X = X.drop('total_UPDRS',axis = 1)
labels = test[['motor_UPDRS','total_UPDRS']]
test = test.drop('motor_UPDRS',axis = 1)
test = test.drop('total_UPDRS',axis = 1)
clf = linear_model.BayesianRidge()
clf.fit(X,y)

数据集分为66%训练集和33%测试集比。当我运行它时,我收到以下错误:

Traceback (most recent call last):

  File "<ipython-input-8-c4e92f3e0bf9>", line 1, in <module>
    runfile('C:/Users/Keshav/Desktop/Spring/ML/Project/parkinsons/main6.py', wdir='C:/Users/Keshav/Desktop/Spring/ML/Project/parkinsons')

  File "C:\Users\Keshav\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 580, in runfile
    execfile(filename, namespace)

  File "C:/Users/Keshav/Desktop/Spring/ML/Project/parkinsons/main6.py", line 27, in <module>
    clf.fit(X,y)

  File "C:\Users\Keshav\Anaconda\lib\site-packages\sklearn\linear_model\bayes.py", line 212, in fit
    self._set_intercept(X_mean, y_mean, X_std)

  File "C:\Users\Keshav\Anaconda\lib\site-packages\sklearn\linear_model\base.py", line 159, in _set_intercept
    self.coef_ = self.coef_ / X_std

ValueError: operands could not be broadcast together with shapes (20,2) (20,) 

知道怎么解决吗?

0 个答案:

没有答案