0

I need to predict the level of a certain index for a country (Scale of 1-100) which is the target feature based on 5 macro-economic and social features/indicators ( Life expectancy , infant mortality , % of GDP spent on military etc )

I need to use 3-nearest neighbor prediction model & weighted k-nn

I also need to predict after range normalization.

Im looking for some ideas on how I could achieve this in python

Thanks

axel_p
  • 51
  • 9
  • 1
    Why do you want to avoid using scikit for this? – Jorn Rigter Apr 15 '20 at 10:11
  • 2
    What have you tried so far? Also kindly asking: Is this for an assignment of somekind? – Ackdari Apr 15 '20 at 10:11
  • Also, do you know how the weighted knn and the manhattan distance work. And what kind of normalization do you want? Please add more details to the question – Ackdari Apr 15 '20 at 10:14
  • yes the requirement is specific. Im getting started in python so really dont have any direction at the moment . any suggestions would be welcome – axel_p Apr 15 '20 at 10:15
  • yes i know how they work. standard or min-max normalization should be fine. – axel_p Apr 15 '20 at 10:17

1 Answers1

0

I think you should start by doing this with scikit-learn and get is to work.

Then you should work on a function for the manhattan distance, so just:

def dist_manhattan(point1, point2):
    ...

If you got this you need to implement your normalization function:

def normalize(dataset):
    ...

and then you can implement your weighted knn, like a function

def w_knn(dataset):
    ...

and if you have general struggel with python, I would suggest reading some books about it or watching/reading tutorials.

Ackdari
  • 3,222
  • 1
  • 16
  • 33
  • so i was able to work with lists to find the CPI for russia using manhattan distance without normalization i now need to normalize the data before i need to find the Manhattan distance between the parameters for the countries against Russia so the thing is i need to normalize column wise (the parameters) and then i need to find the manhattan distance row wise any idea on how this could be achieved becuase it some point I think I will have to flip the data frame or if working with lists how can i get the first values from the 5 columns (lists) into 16 lists with 5 values each ? – axel_p Apr 17 '20 at 09:09
  • @axel_p take a look at [this](https://stackoverflow.com/q/29661574/6560579) – Ackdari Apr 17 '20 at 09:21