this means that the first sentence contains all the words except for "problems"while the second contains all except "how""my"and "toin factthese are exactly the same columns as seen in the previous table from xwe can extract feature vector that we can use to compare the two documents with each other first we will start with naive approach to point out some preprocessing peculiarities we have to account for so let us pick random postfor which we will then create the count vector we will then compare its distance to all the count vectors and fetch the post with the smallest one counting words let us play with the toy dataset consisting of the following postspost filename post content txt this is toy post about machine learning actuallyit contains not much interesting stuff txt imaging databases can get huge txt most imaging databases safe images permanently txt imaging databases store images txt imaging databases store images imaging databases store images imaging databases store images in this post datasetwe want to find the most similar post for the short post "imaging databasesassuming that the posts are located in the folder dirwe can feed countvectorizer with it as followsposts [open(os path join(dirf)read(for in os listdir(dir)from sklearn feature_extraction text import countvectorizer vectorizer countvectorizer(min_df= we have to notify the vectorizer about the full dataset so that it knows upfront what words are to be expectedas shown in the following codex_train vectorizer fit_transform(postsnum_samplesnum_features x_train shape print("#samples% #features% (num_samplesnum_features)#samples #features