2
$\begingroup$

What would be a good non cryptographic Hash function to use for converting string features to a numerical representation for feeding into machine learning algorithms?

To explain the scenario my feature set has both categorical data (e.g.: Country) and non categorical data (e.g.: IP Address, Email address). I have used MurMur3 Hash function so far, is there some better algorithm?

$\endgroup$
1
$\begingroup$

See also: Neural Network parse string data?

I do not see a problem with using MurMur3 per se.

For the categorical labels, you can use one-hot encoding / one-of-k encoding.

For the strings, it's an application-specific question. Presumably if you use exactly those strings as features, it will be very sparse. The effect of this will depend on the algorithm that you are using, and how the training data compare to the data you see in practice. You are running the risk that you will effectively either only create a traditional IP/email whitelist/blacklist OR throw out the feature altogether.

You must decide what you want (eg should a certain email address always get a certain output label?) and have some intuition about the application so as to generate more features from IP address and email address. For example, from email address you can extract the local part (eg "john1972") and domain, and from each of those you can extract:
- length
- character tri-grams
- count/proportion of numbers to alphachars
- number of hyphens
- dictionary validity
...
(From domain you can also extract TLD and possibly subdomains.) You can try to tokenise . You can even hit external services to get information like number of Google hits, detected language, spam score etc.

$\endgroup$
0
$\begingroup$

There's potentially some useful ideas for you in the answers to this question about transforming names in a confidential data set but preserve some of the characteristics of the names I read a while ago and found very interesting. It's not exactly the right topic but there is some discussion on encrypting strings while preserving edit distance, which may not answer your question but perhaps will give you some ideas to think about if you're still stuck...

$\endgroup$
0
$\begingroup$

I recommend doing a stacked model.

If you are doing categorical prediction, you could use a Naive Bayes model to form a prediction on the string data using a bag of words model. That is now a continuous variable to be fed into the ANN.

Another way to process text is to term frequency/inverse document freq stats and use a cosine distance from reference docs. Let's say you have a document that speaks about topic A and one about topic B, you could convert unclassified docs to a numerical distance from A and B. (Typically you build a "reference" A vector from many A docs...)

https://en.wikipedia.org/wiki/Tf–idf

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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