2013-06-07 4 views
1

를 사용합니다.내가 다중 선형 회귀를 코드에 노력하고 있어요 NoneType

least = optimize.minimize(residsq(xmat, ylist, coeff), coeff, constraints = ({'type': 'eq', 'fun': sum(resid(xmat, ylist, coeff))}), method = 'BFGS') # Choose the coefficients that minimize the sum of the residuals squared subject to keeping the sum of the residuals equal to 0. 

xmat이 벡터의 목록은 다음과 같습니다 : 내 프로그램에 오류가 발생합니다 경우 다음 코드 줄이야 [[3,5,2]을, [3,1,6], [7,2,3] , [9, -2,0]]. ylist는 xmat와 동일한 길이의 목록입니다 : [5,2,7,7]. COEFF는 계수리스트, 초기 [평균 (ylist), 0, 0, 0]이다 ([상수, b_0, B_1, B_2). 잔유는 각 포인트에 대한 잔차의 목록이며, residsq 잔차의 N2 규범 (제곱의 합 SQRT)이다.

Traceback (most recent call last): 
    File "<pyshell#3>", line 1, in <module> 
    import linregtest 
    File "C:\Python33\lib\site-packages\linregtest.py", line 4, in <module> 
    out = linreg.multilinreg(xmat, ylist, True) 
    File "C:\Python33\lib\site-packages\linreg.py", line 120, in multilinreg 
    least = optimize.minimize(residsq(xmat, ylist, coeff), coeff, constraints = ({'type': 'eq', 'fun': sum(resid(xmat, ylist, coeff))}), method = 'BFGS') # Choose the coefficients that minimize the sum of the residuals squared subject to keeping the sum of the residuals equal to 0. 
    File "C:\Python33\lib\site-packages\scipy\optimize\_minimize.py", line 302, in minimize 
    RuntimeWarning) 
    File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning 
    file.write(warnings.formatwarning(message, category, filename, 
AttributeError: 'NoneType' object has no attribute 'write' 

어디에서 파일을 가져 왔으며이 오류를 어떻게 억제합니까?

편집 : 하나의 문제를 해결, 서로를 찾을 수 있습니다. SciPy가 부유물을 부르는 곳을 결정하도록 도와 줄 수 있을까요?

Traceback (most recent call last): 
    File "<pyshell#0>", line 1, in <module> 
    import linregtest 
    File "C:\Python33\lib\site-packages\linregtest.py", line 4, in <module> 
    out = linreg.multilinreg(xmat, ylist, True) 
    File "C:\Python33\lib\site-packages\linreg.py", line 123, in multilinreg 
    least = optimize.minimize(residsq(xmat, ylist, coeff), coeff, constraints = ({'type': 'eq', 'fun': sumresid(xmat, ylist, coeff)}), method = 'SLSQP') # Choose the coefficients that minimize the sum of the residuals squared subject to keeping the sum of the residuals equal to 0. 
    File "C:\Python33\lib\site-packages\scipy\optimize\_minimize.py", line 364, in minimize 
    constraints, **options) 
    File "C:\Python33\lib\site-packages\scipy\optimize\slsqp.py", line 301, in _minimize_slsqp 
    meq = sum(map(len, [atleast_1d(c['fun'](x, *c['args'])) for c in cons['eq']])) 
    File "C:\Python33\lib\site-packages\scipy\optimize\slsqp.py", line 301, in <listcomp> 
    meq = sum(map(len, [atleast_1d(c['fun'](x, *c['args'])) for c in cons['eq']])) 
TypeError: 'float' object is not callable 
+0

Numpy가 아닌 PyShell/gui 셸에 문제가있는 것 같습니다. NumPy와 경고를 표시하고, 어떤 이유로 PyShell이 ​​존재하지 않는 파일 객체에 그 쓰기를 시도하는 것 같습니다. – cge

+0

IDLE에서 python 3의 버그처럼 보입니다. 쉘에 인쇄해야하는 경고와 동일한 문제가 있습니다. – user333700

답변

1

I 방금 파이썬 3.2 IDLE, PyShell.py (접합선 59, 62)를 사용하는 대신 sys.__stderr__ 글로벌 warning_stream

def idle_showwarning(message, category, filename, lineno, 
        file=None, line=None): 
    if file is None: 
     file = sys.stderr #warning_stream 
    try: 
     file.write(warnings.formatwarning(message, category, filename, 
              lineno, line=line)) 

사용 sys.stderr 편집. 내 경우에는 sys.__stderr__이 없습니다. 왜 글로벌이 사용되는지 모르겠습니다.

warnings.formatwarning에 대한 호출은 별도의 유효 file 키워드를했다.

는 지금, 나는 예를

>>> import numpy as np 
>>> np.uint(1) - np.uint(2) 

Warning (from warnings module): 
    File "C:\Programs\Python32\Lib\idlelib\idle.pyw", line 1 
    try: 
RuntimeWarning: overflow encountered in ulong_scalars 
>>> 4294967295 
>>> 

편집을 위해, 인쇄 경고를 얻을 : 수정되었습니다 file 인수

http://bugs.python.org/issue12438 잘못된 파이썬 버그 리포트를 검색 할

http://bugs.python.org/issue13582의 문제점이 열려 있습니다.

+0

고마워,하지만 지금은 새로운 문제가 생겼어. 추적이 너무 길어서 내 질문이 업데이트되었습니다. – PikalaxALT

+0

추적 표시가 말하는 것 : 호출 가능 대신 숫자 값을 제공합니다. 제약 조건에서 '재미'는 함수가 아닌 배열로 정의합니다. 나는 함수를 정의하거나'lambda' 함수를 사용해야한다고 생각합니다. 설명서에 설명 된 내용이 있습니다. 새로운'minimize' 함수로는 전혀 작업하지 않았습니다. – user333700

+0

오버플로 오류를 해결 했습니까? 당신이 옳은 대답을하지 못한 결과 일 가능성이 높습니다. – cjm2671

관련 문제