Comments (5)
Hello neonntt,
I can't reproduce the issue. Changing the metric in the provided demo notebook works for me.
So if you change the fourth cell in the demo notebook to the following code snippet:
st_dbscan = ST_DBSCAN(eps1 = 0.05, eps2 = 10, min_samples = 5, metric = 'mahalanobis')
Regarding the second question you mean you want to apply a weighted Euclidean distance?
Cheers,
Eren
from st_dbscan.
Eren, thank you so much for your reply. I will try out as you mentioned regarding changing the metric. Must be some issue with my data.
Regarding the second question, I would like to try a weighted distance with both Euclidean and Mahanalobis metric. Let's say we have another parameter in the data, for example, speed, and we would like the speed value to be given a higher weightage than the others while calculating the distance. Can you please guide how it can be implemented?
Thx again,
from st_dbscan.
Sure, you can adapt the code so using something like the following should work:
def fit(self, X):
"""
Apply the ST DBSCAN algorithm
----------
X : 2D numpy array with
The first element of the array should be the time
attribute as float. The following positions in the array are
treated as spatial coordinates. The structure should look like this [[time_step1, x, y], [time_step2, x, y]..]
For example 2D dataset:
array([[0,0.45,0.43],
[0,0.54,0.34],...])
Returns
-------
self
"""
# check if input is correct
X = check_array(X)
if not self.eps1 > 0.0 or not self.eps2 > 0.0 or not self.min_samples > 0.0:
raise ValueError('eps1, eps2, minPts must be positive')
n, m = X.shape
# Compute sqaured form Euclidean Distance Matrix for 'time' attribute and the spatial attributes
time_dist = pdist(X[:, 0].reshape(n, 1), metric=self.metric)
# --------
# --------
# Line changed here:
# np.array of weights
weights = np.array([0.5, 1, 0.2, 0.3]) # weights for the features
euc_dist = pdist(X[:, 1:], 'wminkowski', p=2, w=weights)
# afterwards the same code snippets
# --------
# --------
# filter the euc_dist matrix using the time_dist
dist = np.where(time_dist <= self.eps2, euc_dist, 2 * self.eps1)
db = DBSCAN(eps=self.eps1,
min_samples=self.min_samples,
metric='precomputed')
db.fit(squareform(dist))
self.labels = db.labels_
return self
Cheers,
Eren
from st_dbscan.
Thanks a ton, Eren...will try it and reach out to you in case I need more help.
regards
from st_dbscan.
Easy, just reopen issue in that case.
Cheers,
Eren
from st_dbscan.
Related Issues (8)
- No issue... Just some questions. HOT 1
- Provide time series before the spatial attributes HOT 1
- Usage of squareform HOT 1
- ValueError: frame_size, frame_overlap not correctly configured HOT 6
- Using the model for multiple features HOT 1
- density factor implementation HOT 2
- wrong when use "st_dbscan.fit_frame_split" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from st_dbscan.