这是一行代码。我知道问题是我只有一个一维数组,但我无法计算将其内联转换为二维数组的代码。
def classification_model(model, data, predictors, outcome):
model.fit(data[predictors],data[outcome])
其中data是从.csv文件中读取的一维数组。
classification_model()
的调用方式如下:classification_model(LogisticRegression(), data, 'HvA', 'FTR')
其中FTR和HvA是.csv中的列名,因此是我的数据数组(Pandas(中的数组位置
跟踪是:追踪(最近一次通话(:
File "Predict.py", line 112, in <module>
classification_model(LogisticRegression(), reader, 'HvA', 'FTR')
File "Predict.py", line 15, in classification_model
model.fit(data[predictors],data[outcome])
File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/logistic.py", line 1174, in fit
order="C")
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 531, in check_X_y
check_consistent_length(X, y)
File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/validation.py", line 181, in check_consistent_length
" samples: %r" % [int(l) for l in lengths])
ValueError: Found input variables with inconsistent numbers of samples: [1, 370]
.csv文件中的标题行和第一行数据
FTHG FTAG FTR HTHG HTAG HTR HS AS HST AST HF AF HC AC HY AY HR AR VCH VCD VCA Bb1X2 BbMxH BbAvH BbMxD BbAvD BbMxA BbAvA BbOU BbMx>2.5 BbAv>2.5 BbMx<2.5 BbAv<2.5 BbAH BbAHh BbMxAHH BbAvAHH BbMxAHA BbAvAHA PSCH PSCD PSCA HvA
0 0 1 0 0 1 25 10 5 2 19 11 7 2 3 3 0 1 3.4 3.5 2.25 39 3.5 3.26 3.6 3.42 2.3 2.2 37 1.95 1.86 2.02 1.92 24 0.25 2.02 1.95 1.94 1.9 3.22 3.5 2.36 0
感谢
data[col_name].values.reshape(len(data), 1)
如Michael K在上给出的