Is there some approach to "encoding" IP Address (IPv4) in a way that the new representation can capture both cardinality and the statistical distribution of the full range of IP address and also aspects like belonging to the same network. I think that converting to an integer (two-way) or hashing dont capture the aspects aforementioned. I know that using vector-representation could be an alternative but I would like to know if there is another.
1 Answer
I think sites like this give you the ISP associated with an IP, and you can back out latitude-longitude coordinates/country/post-code/timezone from that. Depending on the specifics of your problem, any of those could be a pretty good spatial predictor/feature. I have a hunch that people on this site that people on this site are better at answering questions after you've chosen one of these representations, and not on any of the specifics about networking things such as how IP addresses can be used to get those locations.
Your data set is probably longer than two or three observations, so it might be useful to try to capture these results programmatically. Questions like that have been asked many times on stackoverflow.
If you're interested in the distribution of digits of the IP address, post some data, and then I would have some opinions. Right now, I have no intuition about that.
-
$\begingroup$ a sample df = pd.DataFrame(['10.168.2.88','10.168.2.128','10.0.0.1'], columns=['ip']). Like I said in my question my interest is to have a "numerical" representation which encodes the cardinality of the whole ip range. I still dont find a solution. However I found one option using socket & struct that in certain way satisified my interest because the convertion ip-num-ip can be done in "both directions" and obtain the same results. check here: stackoverflow.com/questions/5619685/… PD.I am studying you answer. Thanks $\endgroup$– caivoscoCommented Jun 28, 2019 at 22:39
-
$\begingroup$ @caivosco zip codes are numerical. From that answer it sounds like you just want any invertible mapping, not necessarily one that works well inside a statistical model. $\endgroup$– TaylorCommented Jun 30, 2019 at 14:36
-
$\begingroup$ You are right: mapping not necessarily will work well in a statistical model. No captures the data distribution. I think that vector representation is the only approach for my concern... $\endgroup$– caivoscoCommented Jul 3, 2019 at 21:36