python - Unknown label type sklearn -


i 'm new in sklearn. 'm trying code

data = pandas.read_csv('titanic.csv') data= data[data['pclass'].notnull() & data['sex'].notnull() &         data['age'].notnull() & data['fare'].notnull()]    test = data.loc[:,['pclass','sex','age','fare']] target = data.loc[:,['survived']] test = test.replace(to_replace=['male','female'],value=[1,0]) clf=decisiontreeclassifier(random_state=241) clf.fit(target,test) 

and saw error

valueerror: unknown label type: array([[ 22.    ,   3.    ,   7.25  ,        1.    ],    [ 38.    ,   1.    ,  71.2833,   0.    ],    [ 26.    ,   3.    ,   7.925 ,   0.    ],    ...,     [ 19.    ,   1.    ,  30.    ,   0.    ],    [ 26.    ,   1.    ,  30.    ,   1.    ],    [ 32.    ,   3.    ,   7.75  ,   1.    ]]) 

what problem?

you providing dataframe , not it's numpy array representation training input fit method. instead:

clf.fit(x=test.values, y=target.values)    # .asmatrix() works not recommended 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -