The term “guinea pig” originally was a name to describe an inexperienced midshipman sailing the seas. A midshipman is a trainee on a ship who is still new at sea and learning the ropes. It wasn’t until the 20th Century that the term “guinea pig” was used as a word to describe a person or animal used as a subject in a scientific experiment. The term was first recorded in Henry Power’s book Experimental Philosophy in 1664.
More theories of how the term originated : http://www.grammarphobia.com/blog/2009/12/how-did-the-guinea-pig-get-its-name.html