Training algorithm for finding relationships within a data set Given a dataset that looks like the following:


-----------------------------------------------------------
|Category|Phrase         |Related 1       |Related 2  |...|
-----------------------------------------------------------
|Art     |Art exhibitions|                |           |   |
|Art     |Art galleries  |Art exhibitions |Art museum |   |
|Art     |Art museum     |Art galleries   |           |   |
|Sports  |Football       |Sports coaching |NFL        |   |
|Sports  |Basketball     |NBA             |           |   |
|Sports  |Sports coaching|                |           |   |
-----------------------------------------------------------


If I have an input phrase, how can I list possible related phrases inside the dataset? For example, I would relate "art exhibitions" to "art museum" and "art galleries". The dataset has some relationships filled out already (I am not sure if this counts as usable training data or if I have to transform it further) and I am looking to fill in the blanks, that is find relationships for some rows.

Eventually we would want to be able to support input phrases that don't exist yet in this dataset and establish relationships for them based on historical info, which is why I think I should be looking at machine learning.

What is the best algorithm/approach I can make use of for this problem?
Given your example, if you want to group phrases based on terms, a simple approach would be to use grep to find rows that contain specific letter sequences (e.g. "art", "ball"). For example, say your table is a csv file (myfile.csv), where each line is a word or phrase (e.g. "Football", "Jazz music"). We can use a UNIX terminal to get all lines that contain "ball":

grep -n ball myfile.csv | cut -d: -f1 &gt; myresults.txt


This would yield a file (myresults.txt) that containts the lines numbers of phrases that contain "ball". You can also apply grep to a data frame version of your table using R or Python, so you can loop over different letter sequences and save the found relationships to a separate column of the data frame or a separate data frame or vector.