Wednesday 15 May 2013

python 3.x - sklearn knn prediction error: float() argument must be a string or a number, not 'dict' -


I predicted using the following code to try to feed knn.predict () to record Age group: 'sex': 1, 'age': 6, # Age group 'immstat' on immigration: p>

  person_features = {'cma': 462, # Metropolitan area ' #graduate: 9, # 1, # Immigrant status' PAB ': 21, # East Asia' Knol ': 4, # First languages' CIP1011': 7, # Main area of ​​study: Mathematics, computer and information science 'HDB ': 12, #Hystest Shaw Education} prediction = knn.predict (person_features) label = {true: '& gt; 50K ', wrong:' & lt;  

but type

type error: float () should be a string string or a number, not '50K' print (label [prediction]) I tried to make it in the list of toplevels:

  person_features = [('CMA', 462), ('Aeggap', ' 9), ('sex', 1), ('age', 6), ('instast' 1), ('pob', 21), ('knol', 4), ('cip2011', 7) ('HDEgree', 12)]  

B did not work either.

What should I do to resolve this kind of error? I think the solution is easy, but in some way I can just wrap my head around it.

Programming has begun to learn new and less than three months of Python. So stay with me in response to my amateur questions! I see the number from the coding book CMA = 462 age group = 9 gender = 1 ageimm = 6 immstat = 1 pob = 21 nol = 4 cip2011 = 7 hdgree = 12 MoreThan50K ​​=

1 # I'm going to predict, for 1 & gt; For 50K, 0 & lt; 50k Person_Prepo = [CMA, Aggraph, Sex, Age, Imastat, Pub, Knoll, CP1,1, HDG


No comments:

Post a Comment