I want to know the similarity (accuracy) of the two array-type lists in Python.

Asked 1 years ago, Updated 1 years ago, 117 views

I'm a college student who just started studying deep learning.

For study, we processed the time series data in the GRU method of RNN for the purpose of predicting specific meteorological phenomena, and succeeded in visualizing them as graphs.

But I wanted to measure the similarity, the accuracy, between train data and test data. For this purpose, we tried the cosine similarity method, but an error occurred.

First of all, the form of train data and test data based on deep learning results is as follows.

In [51] : train
Out[51] : array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)

(train data consists of 0 and 1 only. On the graph, the graph is drawn at right angles, just like a digital graph.)

In [52] : test
Out[52] : array([[0.        , 0.        , 0.        , ..., 0.0603604 , 0.11037167,
        0.        ],
       [0.        , 0.        , 0.        , ..., 0.07735108, 0.13839354,
        0.        ],
       [0.        , 0.        , 0.        , ..., 0.07322919, 0.12958862,
        0.        ],
       ...,
       [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
        0.        ],
       [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
        0.        ],
       [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
        0.        ]], dtype=float32)

(The test data consists of 0.xx units. The graph looks like an analog graph.)

We tried to calculate these two data in a cosine similarity scheme, but an error occurred.

from numpy import dot
from numpy.linalg import norm
cos_sim = dot(train_r, test_r)/(norm(train_r)*norm(test_r))
ValueError: shapes (100,24) and (100,24) not aligned: 24 (dim 1) != 100 (dim 0)

It hasn't been long since I started studying deep learning, so I don't know why, but while searching, I found that this is a dimension-related problem. But I'm thinking about how, what code and how to handle this.

I'd really appreciate it if you could answer me.

python jupyter

2022-09-22 18:27

1 Answers

Problem solved. It was a simple way to solve it.

Train and test contained 24 lists, not just one list. An error occurred when trying to calculate these 24 lists at once using cosine similarity method.

To resolve the error, you can just specify a specific list in train_r, test_r, and save it as a different name.

train_c = train_r[:,12]

test_c = test_r[:,12]

After specifying this, the calculation is performed using the cosine similarity formula, and the results are displayed normally.


2022-09-22 18:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.