完善了运算
This commit is contained in:
parent
2a2e5f9d27
commit
aa956261b8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
__pycache__/*
|
||||
Temp/
|
||||
Scales/
|
||||
Work/
|
21
file_load.py
21
file_load.py
@ -40,7 +40,7 @@ def calc_similarity(scale):
|
||||
for i in scale:
|
||||
item.append(i)
|
||||
vec.append(client.embeddings.create(
|
||||
input=scale[i], model="text-embedding-3-small" # nomic-embed-text text-embedding-3-small
|
||||
input=scale[i], model="text-embedding-3-large" # nomic-embed-text text-embedding-3-small
|
||||
).data[0].embedding)
|
||||
simi=cosine_similarity(vec)
|
||||
que=[]
|
||||
@ -73,24 +73,17 @@ def make_data():
|
||||
for j in range(1,20):
|
||||
s += ',' + str(random.randint(0,4))
|
||||
s+='\n'
|
||||
with open("Temp/data.csv","w") as data:
|
||||
with open("data.csv","w") as data:
|
||||
data.write(s)
|
||||
|
||||
def corelation(sort:bool=True):
|
||||
data = pandas.read_csv("data.csv")
|
||||
que=[]
|
||||
def corelation():
|
||||
data = pandas.read_csv("Work/data.csv")
|
||||
que={}
|
||||
for i in data:
|
||||
for j in data:
|
||||
try:
|
||||
if(i != j):
|
||||
# que[i,j]["psr"]=data[i].corr(data[j])
|
||||
que.append({"from":j,"to":i,"psr":data[i].corr(data[j])})
|
||||
else:
|
||||
pass
|
||||
que[i,j]=data[i].corr(data[j])
|
||||
except:
|
||||
pass
|
||||
if sort:
|
||||
return sorted(que,key = lambda t : abs(t["psr"]), reverse=True)
|
||||
else:
|
||||
return que
|
||||
return que
|
||||
|
||||
|
20
main.py
20
main.py
@ -10,23 +10,21 @@ import numpy
|
||||
similarity = file_load.similarity()
|
||||
corelation = file_load.corelation()
|
||||
|
||||
table = {}
|
||||
|
||||
for i in corelation:
|
||||
table[i["from"],i["to"]]=i["psr"]
|
||||
|
||||
x=[]
|
||||
y=[]
|
||||
|
||||
s="similarity, corelation\n"
|
||||
|
||||
for i in similarity:
|
||||
x.append(abs(table[i["from"],i["to"]]))
|
||||
y.append(i["similarity"])
|
||||
try:
|
||||
s+=str(i["similarity"])+','+str(corelation[i["from"],i["to"]])+'\n'
|
||||
x.append(i["similarity"])
|
||||
y.append(corelation[i["from"],i["to"]])
|
||||
except:
|
||||
pass
|
||||
|
||||
print(numpy.corrcoef(x,y)[0,1])
|
||||
|
||||
s="similarity, corelation\n"
|
||||
for i in similarity:
|
||||
s+=str(i["similarity"])+','+str(table[i["from"],i["to"]])+'\n'
|
||||
with open("Temp/point.csv","w") as point:
|
||||
with open("Work/point.csv","w") as point:
|
||||
point.write(s)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user