similarity

How can you compare two cluster groupings in terms of similarity or overlap in Python?

喜夏-厌秋 提交于 2019-12-01 18:43:02
问题 Simplified example of what I'm trying to do: Let's say I have 3 data points A, B, and C. I run KMeans clustering on this data and get 2 clusters [(A,B),(C)] . Then I run MeanShift clustering on this data and get 2 clusters [(A),(B,C)] . So clearly the two clustering methods have clustered the data in different ways. I want to be able to quantify this difference. In other words, what metric can I use to determine percent similarity/overlap between the two cluster groupings obtained from the

single-pass单遍聚类方法

这一生的挚爱 提交于 2019-12-01 13:39:46
一.通常关于文本聚类也都是针对已有的一堆历史数据进行聚类,比如常用的方法有kmeans,dbscan等。如果有个需求需要针对流式文本进行聚类(即来一条聚一条),那么这些方法都不太适用了,当然也有很多其它针对流式数据进行动态聚类方法,动态聚类也有很多挑战,比如聚类个数是不固定的,聚类的相似阈值也不好设。这些都有待继续研究下去。本文实现一个简单sing-pass单遍聚类方法,文本间的相似度是利用余弦距离,文本向量可以用tfidf(这里的idf可以在一个大的文档集里统计得到,然后在新的文本中的词直接利用),也可以用一些如word2vec,bert等中文预训练模型对文本进行向量表示。 二.程序 1 import numpy as np 2 import os 3 import sys 4 import pickle 5 import collections 6 from sklearn.feature_extraction.text import TfidfVectorizer 7 from sklearn.decomposition import TruncatedSVD 8 from gensim import corpora, models, matutils 9 from utils.tokenizer import load_stopwords, load_samples,

PHP similar_text() in java

怎甘沉沦 提交于 2019-12-01 11:55:24
问题 Do you know any strictly equivalent implementation of the PHP similar_text function in Java? 回答1: Here is my implementation in java : package comwebndesignserver.server; import android.util.Log; /* * * DenPashkov 2012 * http://www.facebook.com/pashkovdenis * * PhP Similar String Implementation * 30.07.2012 * */ public class SimilarString { private String string = "" ; private String string2 = ""; public int procent = 0 ; private int position1 =0 ; private int position2 =0; // Similar String

PHP similar_text() in java

我与影子孤独终老i 提交于 2019-12-01 11:45:09
Do you know any strictly equivalent implementation of the PHP similar_text function in Java? Denis Here is my implementation in java : package comwebndesignserver.server; import android.util.Log; /* * * DenPashkov 2012 * http://www.facebook.com/pashkovdenis * * PhP Similar String Implementation * 30.07.2012 * */ public class SimilarString { private String string = "" ; private String string2 = ""; public int procent = 0 ; private int position1 =0 ; private int position2 =0; // Similar String public SimilarString(String str1, String str2){ this.string = str1.toLowerCase(); this.string2 = str2

about cosine similarity

╄→尐↘猪︶ㄣ 提交于 2019-12-01 11:08:41
问题 I am finding cosine similarity between documents.. I did it like this D1=(8,0,0,1) where 8,0,0,1 are the tf-idf scores of the terms t1, t2, t3 , t4 D2=(7,0,0,1) cos(theta) = (56 + 0 + 0 + 1) / sqrt(64 + 49) sqrt(1 +1 ) which comes out to be cos(theta)= 5 Now what do I evaluate from this value... I don't get it what does cos(theta)=5 signify about the similarity between them... Am I doing things right? 回答1: The denominator is wrong. The cosine similarity is defined as D1 · D2 sim = ———————————

The similar method from the nltk module produces different results on different machines. Why?

送分小仙女□ 提交于 2019-12-01 02:36:12
I have taught a few introductory classes to text mining with Python, and the class tried the similar method with the provided practice texts. Some students got different results for text1.similar() than others. All versions and etc. were the same. Does anyone know why these differences would occur? Thanks. Code used at command line. python >>> import nltk >>> nltk.download() #here you use the pop-up window to download texts >>> from nltk.book import * *** Introductory Examples for the NLTK Book *** Loading text1, ..., text9 and sent1, ..., sent9 Type the name of the text or sentence to view it

PHP nearest string comparison [duplicate]

假如想象 提交于 2019-12-01 01:34:52
Possible Duplicate: String similarity in PHP: levenshtein like function for long strings I have my subject string $subj = "Director, My Company"; and a list of multiple strings to be compared: $str1 = "Foo bar"; $str2 = "Lorem Ipsum"; $str3 = "Director"; What I want to achieve here is to find the nearest string related to $subj . Is it possible to do it? hek2mgl The levenshtein() function will do what you expect. The Levenshtein algorithm calculates the number of insert and replace actions being required to transform some string into another. The result is called an edit distance . The

Find similar ASCII character in Unicode

一曲冷凌霜 提交于 2019-12-01 01:32:51
问题 Does someone know a easy way to find characters in Unicode that are similar to ASCII characters. An example is the "CYRILLIC SMALL LETTER DZE (ѕ)". I'd like to do a search and replace for similar characters. By similar I mean human readable. You can't see a difference by looking at it. 回答1: As noted by other commenters, Unicode normalisation ("compatibilty characters") isn't going to help you here as you aren't looking for official equivalences but for similarities in glyphs (letter shapes).

How to determine character similarity?

ぃ、小莉子 提交于 2019-11-30 23:45:18
I am using the Levenshtein distance to find similar strings after OCR. However, for some strings the edit distance is the same, although the visual appearance is obviously different. For example the string Co will return these matches: CY (1) CZ (1) Ca (1) Considering, that Co is the result from an OCR engine, Ca would be the more likely match than the ones. Therefore, after calculating the Levenshtein distance, I'd like to refine query result by ordering by visual similarity. In order to calculate this similarity a I'd like to use standard sans-serif font, like Arial. Is there a library I can

The similar method from the nltk module produces different results on different machines. Why?

为君一笑 提交于 2019-11-30 22:15:19
问题 I have taught a few introductory classes to text mining with Python, and the class tried the similar method with the provided practice texts. Some students got different results for text1.similar() than others. All versions and etc. were the same. Does anyone know why these differences would occur? Thanks. Code used at command line. python >>> import nltk >>> nltk.download() #here you use the pop-up window to download texts >>> from nltk.book import * *** Introductory Examples for the NLTK