Text classification in Python based on large dict of string:string
<p>I have a dataset that would be equivalent to a dict of 5 millions key-values, both strings.<br>
Each key is unique but there are only a couple hundreds of different values.  </p>

<p>Keys are not natural words but technical references. The values are "families", grouping similar technical references. Similar is meant in the sense of "having similar regex", "including similar characters", or some sort of pattern.</p>

<p>Example of key-values:  </p>

<pre><code>ADSF33344 : G1112
AWDX45603 : G1112
D99991111222 : X3334
E98881188393 : X3334
A30-00005-01 : B0007
B45-00234-07A : B0007
F50-01120-06 : B0007
</code></pre>

<p>The final goal is to feed an algorithm with a list of new references (never seen before) and the algorithm would return a suggested family for each reference, ideally together with a percentage of confidence, based on what it learned from the dataset.<br>
The suggested family can only come from the existing families found in the  dataset. No need to "invent" new family name.</p>

<p>I'm not familiar with machine learning so I don't really know where to start. I saw some solutions through Sklearn or TextBlob and I understand that I'm looking for a classifier algorithm but every tutorial is oriented toward analysis of large texts.<br>
Somehow, I don't find how to handle my problem, although it seems to be a "simpler" problem than analysing newspaper articles in natural language...  </p>

<p>Could you indicate me sources or tutorials that could help me?</p>

<p>Make a training dataset, and train a classifier. Most classifiers work on the values of a set of features that you define yourself. (The kind of features depends on the classifier; in some cases they are numeric quantities, in other cases true/false, in others they can take several discrete values.) You provide the features and the classifier decides how important each feature is, and how to interpret their combinations.</p>

<p>By way of a tutorial you can look at <a href="http://www.nltk.org/book/ch06.html" rel="nofollow">chapter 6</a> of the NLTK book. The example task, the classification of names into male and female, is structurally very close to yours: Based on the form of short strings (names), classify them into categories (genders). </p>

<p>You will translate each part number into a dictionary of features. Since you don't show us the real data, nobody give you concrete suggestions, but you should definitely make general-purpose features as in the book, and in addition you should make a feature out of every clue, strong or weak, that you are aware of. If supplier IDS differ in length, make a length feature. If the presence (or number or position) of hyphens is a clue, make that into a feature. If some suppliers' parts use a lot of zeros, ditto. Then make additional features for anything else, e.g. "first three letters" that <em>might</em> be useful. Once you have a working system, experiment with different feature sets and different classifier engines and algorithms, until you get acceptable performance. </p>

<p>To get good results with new data, don't forget to split up your training data into training, testing and evaluation subsets. You could use all this with any classifier, but the NLTK's Naive Bayes classifier is pretty quick to train so you could start with that. (Note that the features can be discrete values, e.g. <code>first_letter</code> can be the actual letter; you don't need to stick to boolean features.)</p>

python algorithm machine-learning