代码在Jupyter Notebook中运行,但不在Python中运行

时间:2019-11-15 12:20:06

标签: python scikit-learn jupyter-notebook linear-regression

我正在运行一个脚本,以使用scikit-learn执行线性回归。在jupyter笔记本中,它运行良好,但现在转换为.py文件后,出现了错误。有问题的代码行是:

self.reg = linear_model.LinearRegression().fit(self.train_data, self.train_target)

已检查输入是否正确-形状正确的数组和数据类型正确。

错误是:

Segmentation fault: 11 

偶尔还有以下内容:

XXX lineno: 459, opcode: 32
Traceback (most recent call last):
  File "learn.py", line 175, in <module>
    run_learn(42,0.3)
  File "learn.py", line 171, in run_learn
    learn_object.assess_performance()
  File "learn.py", line 108, in assess_performance
self.score = self.reg.score(self.train_data, self.train_target)
  File "/Users/[usr]/environments/tf_env/lib/python3.8/site-packages/sklearn/base.py", line 408, in score
    y_pred = self.predict(X)
  File "/Users/[usr]/environments/tf_env/lib/python3.8/site-packages/sklearn/linear_model/base.py", line 221, in
 predict
    return self._decision_function(X)
  File "/Users/[usr]/environments/tf_env/lib/python3.8/site-packages/sklearn/linear_model/base.py", line 204, in
 _decision_function
    X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
  File "/Users/[usr]/environments/tf_env/lib/python3.8/site-packages/sklearn/utils/validation.py", line 459, in
check_array
    if isinstance(dtype, (list, tuple)):
SystemError: unknown opcode

我想不出为什么在jupyter笔记本中某些东西可以正常运行,而在python中却不能。

**在被问及检查Python版本时,两种用法都在运行Python 3.6的虚拟环境中发生(出于与其他模块的兼容性)

0 个答案:

没有答案