1
$\begingroup$

We're doing pairwise similarity computation for some real estate properties. Our data goes something like this:

import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity

df = pd.DataFrame({
                           'Square Footage': np.random.randint(500, 600, 4),
                           'Year Renovated': np.random.randint(1992, 2019, 4),
                           'Year Built': [1990, 2000, 1995, 2005],
                           'Rent': [1000, 800, 1200, 1500],
                           'ameneties': [4, 6, 8, 10]

                  })

User enters similar information about the a property of interest and then we do cosine similarity between the two vectors.

My questions are:

  1. How do we use data other than numbers such as text data and other categorical variables to compute similarity?

  2. How can we modify the algorithm to specify weights?

  3. Any other algorithms that would be appropriate for this problem?

$\endgroup$
3
  • $\begingroup$ Is your question about cosine similarity or about Python? If the latter, it is likely off-topic. If the former, then why not show the data values rather than some code? $\endgroup$
    – ttnphns
    Commented Oct 20, 2021 at 12:59
  • $\begingroup$ I am facing the same issue, would you please share the solution if you have managed to solve this issue?? $\endgroup$
    – Wafa
    Commented Jun 13, 2022 at 8:11
  • $\begingroup$ What kind of weights? What do you mean by that? Do you mean weighting the features? This is basically handled by scaling them. $\endgroup$
    – Tim
    Commented Jun 13, 2022 at 8:22

1 Answer 1

0
$\begingroup$

How do we use data other than numbers such as text data and other categorical variables to compute similarity?

Use encoding, one simple way of doing encoding is one-hot encoding and there are other encoding methods exists.

How can we modify the algorithm to specify weights?

If you want to use weights on different features, you can consider Euclidean distance

Any other algorithms that would be appropriate for this problem?

Really depends on the problem. Essentially we need to answer what is similar? similar in terms of what? May be resell value? F

or example, if two properties are in different communities, one is big in size, but poor in neighborhood safety, another one is small in size, but have very nice community. Both of them have exact resell value, do you consider them similar?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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