0
$\begingroup$

How can I calculate PCA for variables which contain IP address (which is not a continuous variable)?

$\endgroup$
4
  • 2
    $\begingroup$ Not only can't you do it; it makes no sense. I don't think it is essential to have continuous variables for PCA; any variables for which Pearson correlation makes sense are defensible in my book. But IP address doesn't qualify; at most it's an identifier like a person or institution name. $\endgroup$
    – Nick Cox
    Apr 8, 2016 at 9:25
  • $\begingroup$ I think the answer is that you can't. That is to say, it wouldn't be possible to integrate massively categorical information such as IP address into a traditional, linear PCA founded on continuously distributed features. Of course, you can ignore IP address and run a PCA on the non-categorical information. But mixtures of scale types -- particularly mixtures of "normally" distributed with 0,1 or dummy features -- are a challenge for PCA. Would you describe your data matrix? What is your objective in wanting to include IP address? Hi Nick. $\endgroup$
    – user78229
    Apr 8, 2016 at 9:27
  • $\begingroup$ Thank you For your replies. Well I am trying to model a fraud detection framework. I still in the exploration data phase. So I see in the log file that there in the Ip adress for customer who did some money transaction. I would like to do data reduction with PCA. Which is the origin of my question. $\endgroup$
    – Fish
    Apr 8, 2016 at 9:35
  • $\begingroup$ There is a website that tracks in real-time IP addresses associated with fraudulent credit card activity. The problem, of course, is that with dark web browsers such as Tor, which mask real IP addresses and criminal activity, it's not too reliable. I have to find that link. That said, I don't see how a "PCA" of IP addresses would even work in your analysis since you would lose all of the specificity inherent to an IP address -- you want specificity. My instincts would be to shift your focus to modeling known fraud with IP address as a massively categorical feature, along with other info. $\endgroup$
    – user78229
    Apr 8, 2016 at 9:54

1 Answer 1

1
$\begingroup$

You can take the first octet (the first three digits of the IP address) and work with it as a categorical variable. This would provide you some information about the location of the IP and/or whether it belongs or not to a few specific companies.

XKCD released a 'Map of the Internet' a while ago, based on this information:

http://imgs.xkcd.com/comics/map_of_the_internet.jpg

Other than that, I don't think using the whole IP as a feature has a particular value, unless you have extra information (a service to convert IPs to specific locations, a description of specific subnets, ...)

$\endgroup$
3
  • $\begingroup$ Thank you @carrdelling and then I use PCA for categorial variables? $\endgroup$
    – Fish
    Apr 8, 2016 at 10:18
  • 1
    $\begingroup$ Yes. But keep in mind that if you just feed the values (as integers), PCA is could assume that there is some sort of order between the possible values - which would not be correct in this case. You can try something like using One-Hot-Encoding (description here: stackoverflow.com/questions/17469835/…) and check if it improves your results. $\endgroup$ Apr 8, 2016 at 10:26
  • 2
    $\begingroup$ @cardelling "could assume" is unduly tentative. PCA in the standard sense will treat integer codes just as if they were measured or counted. Some people are happy to use PCA even on indicator variables, but typically PCA routines take what is fed to them literally, meaning numerically. $\endgroup$
    – Nick Cox
    Apr 8, 2016 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.