2016-12-15 4 views
0

나는이 튜토리얼을 통해 작업 과정에 있었다 : http://ahmedbesbes.com/how-to-score-08134-in-titanic-kaggle-challenge.html파이썬 sklearn의 kaggle이/타이타닉 튜토리얼 마지막 기능에 실패 규모

내가 중간 섹션의 마지막 부분에 도착 때까지, 아무런 문제없이 갔다 :

보시다시피이 기능의 범위는 서로 다릅니다. 단위 간격으로 모든 것을 정규화합시다. 우리가 제출해야합니다 그 PassengerId을 제외하고 그들 모두

In [48]: 
>>> def scale_all_features(): 

>>>  global combined 

>>>  features = list(combined.columns) 
>>>  features.remove('PassengerId') 
>>>  combined[features] = combined[features].apply(lambda x: x/x.max(), axis=0) 

>>>  print 'Features scaled successfully !' 

In [49]: 
>>> scale_all_features() 

기능을 성공적으로 확장! 문제는 여기에 무엇

--------------------------------------------------48-------------------------------------------------- 
--------------------------------------------------49-------------------------------------------------- 
Traceback (most recent call last): 
    File "KaggleTitanic[2-FE]--[01].py", line 350, in <module> 
    scale_all_features() 
    File "KaggleTitanic[2-FE]--[01].py", line 332, in scale_all_features 
    combined[features] = combined[features].apply(lambda x: x/x.max(), axis=0) 
    File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 4061, in apply 
    return self._apply_standard(f, axis, reduce=reduce) 
    File "/usr/local/lib/python2.7/dist-packages/pandas/core/frame.py", line 4157, in _apply_standard 
    results[i] = func(v) 
    File "KaggleTitanic[2-FE]--[01].py", line 332, in <lambda> 
    combined[features] = combined[features].apply(lambda x: x/x.max(), axis=0) 
    File "/usr/local/lib/python2.7/dist-packages/pandas/core/ops.py", line 651, in wrapper 
    return left._constructor(wrap_results(na_op(lvalues, rvalues)), 
    File "/usr/local/lib/python2.7/dist-packages/pandas/core/ops.py", line 592, in na_op 
    result[mask] = op(x[mask], y) 
TypeError: ("unsupported operand type(s) for /: 'str' and 'str'", u'occurred at index Ticket') 

:

#Cell 48 
GreatDivide.split() 
def scale_all_features(): 

    global combined 

    features = list(combined.columns) 
    features.remove('PassengerId') 
    combined[features] = combined[features].apply(lambda x: x/x.max(), axis=0) 

    print 'Features scaled successfully !' 

#Cell 49 
GreatDivide.split() 
scale_all_features() 

그것은 나에게 오류를주고 계속 :

내 파이썬 스크립트에서 단어 그 단어를 입력에도 불구하고? 이전 49 개 섹션 모두 문제없이 실행되었으므로 오류가 발생하면 지금까지 표시했을 것입니다.

+0

* 티켓 * 열에는 문자열이 들어 있습니다. 그래서 그들을 정상화하는 것은 결코 일어나지 않을 것입니다. 시도해보십시오. –

답변

1

수학 변환이 다음과 같은 숫자 열에 대해서만 발생하도록 할 수 있습니다.

numeric_cols = combined.columns[combined.dtypes != 'object'] 
combined.loc[:, numeric_cols] = combined[numeric_cols]/combined[numeric_cols].max() 

해당 적용 기능이 필요하지 않습니다.

+0

알았어. 이게 효과가 있는지 다시 볼게요, 고마워요. 고마워요. – Rich

+0

안녕하세요, 모든 것이 * 작동하는 것 같습니다. 감사합니다! 문제가 생기면 알려 드리겠습니다. – Rich