我对Knime和Python相当陌生,我正在检查一些我想通过Knime在Python脚本节点上运行的Python代码。该脚本可以在节点上正常执行,但不能在节点外部执行,此外,以下脚本中“ Poisson Model”属性的输出面板上的数据无法正确显示:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn
from scipy.stats import poisson,skellam
import statsmodels.api as sm
import statsmodels.formula.api as smf
epl_1617 = input_table
poisson_model = smf.glm(formula="input_table['GOALS'] ~
input_table['HOME'] + input_table['HomeTeam'] +
input_table['AwayTeam']", data=epl_1617,
family=sm.families.Poisson()).fit()
poisson_model.summary()
当我在Python上运行以上代码时,它以表格形式给出结果;但是,在Knime中,输出显示为“ poisson_model: “
注意:可以从以下位置下载输入文件:
http://www.football-data.co.uk/mmz4281/1617/E0.csv
关于如何在Knime上运行以下代码的任何想法?
我尝试使用以下方法将结果分配给DataFrame:
output_table = pd.DataFrame(poisson_model.summary())
但是,我遇到了以下错误:
output_table = pd.DataFrame(poisson_model.summary())
Traceback (most recent call last):
File "C:\Program Files\KNIME\plugins\org.knime.python2_3.6.0.v201807061638\py\PythonKernelBase.py", line 278, in execute
exec(source_code, self._exec_env, self._exec_env)
File "<string>", line 24, in <module>
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 422,
in __init__
raise ValueError('DataFrame constructor not properly called!')
ValueError: DataFrame constructor not properly called!
这是如果我使用Python IDE运行相同代码的结果
poisson_model.summary()
Out[3]:
<class 'statsmodels.iolib.summary.Summary'>
"""
Generalized Linear Model Regression Results
==============================================================================
Dep. Variable: GOALS No. Observations: 740
Model: GLM Df Residuals: 700
Model Family: Poisson Df Model: 39
Link Function: log Scale: 1.0000
Method: IRLS Log-Likelihood: -1107.5
Date: Wed, 27 Mar 2019 Deviance: 906.20
Time: 19:29:22 Pearson chi2: 784.
No. Iterations: 5 Covariance Type: nonrobust
==============================================================================================
coef std err z P>|z| [0.025 0.975]
----------------------------------------------------------------------------------------------
Intercept 0.4226 0.193 2.190 0.029 0.044 0.801
HomeTeam[T.Bournemouth] 0.1726 0.188 0.917 0.359 -0.196 0.542
HomeTeam[T.Burnley] -0.1755 0.208 -0.845 0.398 -0.582 0.232
HomeTeam[T.Chelsea] 0.2356 0.187 1.259 0.208 -0.131 0.602
HomeTeam[T.Crystal Palace] -0.0903 0.201 -0.450 0.652 -0.483 0.303
HomeTeam[T.Everton] 0.0608 0.192 0.317 0.752 -0.316 0.437
HomeTeam[T.Hull] 0.0676 0.195 0.347 0.729 -0.315 0.450
HomeTeam[T.Leicester] 0.0599 0.196 0.306 0.760 -0.324 0.444
HomeTeam[T.Liverpool] 0.1453 0.191 0.760 0.447 -0.229 0.520
HomeTeam[T.Man City] 0.0060 0.196 0.031 0.975 -0.378 0.390
HomeTeam[T.Man United] -0.3528 0.218 -1.616 0.106 -0.781 0.075
HomeTeam[T.Middlesbrough] -0.3185 0.212 -1.505 0.132 -0.733 0.096
HomeTeam[T.Southampton] -0.3345 0.217 -1.545 0.122 -0.759 0.090
HomeTeam[T.Stoke] -0.1255 0.202 -0.623 0.533 -0.521 0.269
HomeTeam[T.Sunderland] -0.0894 0.199 -0.448 0.654 -0.480 0.302
HomeTeam[T.Swansea] 0.1140 0.193 0.592 0.554 -0.264 0.491
HomeTeam[T.Tottenham] 0.0301 0.194 0.155 0.877 -0.350 0.410
HomeTeam[T.Watford] -0.0352 0.201 -0.175 0.861 -0.429 0.358
HomeTeam[T.West Brom] -0.1100 0.200 -0.549 0.583 -0.503 0.283
HomeTeam[T.West Ham] -0.0738 0.200 -0.370 0.712 -0.465 0.317
AwayTeam[T.Bournemouth] -0.0941 0.182 -0.517 0.605 -0.451 0.263
AwayTeam[T.Burnley] -0.3271 0.190 -1.722 0.085 -0.699 0.045
AwayTeam[T.Chelsea] -0.3465 0.192 -1.801 0.072 -0.724 0.031
AwayTeam[T.Crystal Palace] -0.0285 0.177 -0.161 0.872 -0.376 0.319
AwayTeam[T.Everton] -0.3461 0.195 -1.777 0.076 -0.728 0.036
AwayTeam[T.Hull] -0.1969 0.184 -1.071 0.284 -0.557 0.163
AwayTeam[T.Leicester] -0.1790 0.183 -0.978 0.328 -0.537 0.180
AwayTeam[T.Liverpool] -0.1381 0.181 -0.762 0.446 -0.493 0.217
AwayTeam[T.Man City] -0.0412 0.179 -0.230 0.818 -0.392 0.309
AwayTeam[T.Man United] -0.3990 0.194 -2.061 0.039 -0.778 -0.020
AwayTeam[T.Middlesbrough] -0.5297 0.206 -2.574 0.010 -0.933 -0.126
AwayTeam[T.Southampton] -0.2731 0.187 -1.463 0.143 -0.639 0.093
AwayTeam[T.Stoke] -0.2855 0.190 -1.502 0.133 -0.658 0.087
AwayTeam[T.Sunderland] -0.3859 0.198 -1.950 0.051 -0.774 0.002
AwayTeam[T.Swansea] -0.1941 0.184 -1.056 0.291 -0.554 0.166
AwayTeam[T.Tottenham] -0.2569 0.190 -1.351 0.177 -0.630 0.116
AwayTeam[T.Watford] -0.2025 0.184 -1.102 0.270 -0.563 0.158
AwayTeam[T.West Brom] -0.3953 0.198 -1.998 0.046 -0.783 -0.008
AwayTeam[T.West Ham] -0.0867 0.180 -0.480 0.631 -0.440 0.267
HOME 0.2962 0.063 4.695 0.000 0.173 0.420
==============================================================================================
"""
您的帮助已经受到赞赏!