29
votes
Accepted
Removing neighbors in a point cloud
1. Introduction
It is not a good plan to leave code running for 30 hours. Until you have analyzed the code, and have figured out how its runtime varies according to the size of the input, then you ...
26
votes
10
votes
K-Means image segmentation algorithm
I'm not familiar with image processing at all, so I cannot give you any advice about your algorithm implementation. However, there are quite a few things I'd like to say about good practices and code ...
10
votes
Removing neighbors in a point cloud
Gareth provided some excellent ideas, for which I will suggest a very similar solution, only using scipy instead of rtree. I ...
7
votes
K-Means image segmentation algorithm
I want to reinforce a point that Ben Steffan made in his answer:
This part is really bad:
std::vector<Pixel*> m_pixels;
This would be much, much better:
<...
7
votes
Closest Pair algorithm implementation in C++
Your code can be improved in regard to its efficiency and its readability. But first of all, don't write that using namespace std.
Efficiency
You create a lot of ...
6
votes
Finding the closest point to a list of points
By using a kd-tree computing the distance between all points it's not needed for this type of query. It's also built in into scipy and can speed up these types of programs enormously going from O(n^2) ...
6
votes
Accepted
K-means clustering implemented in Python 3
import numpy as np
class kmeans():
Use a PEP 8 checker such as pycodestyle or flake8. Integrate it into your file editor or IDE, if you're not doing it already. ...
5
votes
Given a collection of points on a 2D plane, find the pair that is closest to each other
Comments out of sync with code
...
4
votes
Accepted
Clustering 16 million records in parallel
Hard to tell without sample data, but lets start with a cleaned up
version as there's soo much duplicated code here and the formatting is
inconsistent.
The require ...
4
votes
Accepted
KNN algorithm implemented in Python
First a style nitpick: Python has an official style-guide, PEP8, which recommends using lower_case_with_underscores for variable and function names instead of ...
4
votes
Accepted
Cosine similarity of one vector with many
I'm using Microsoft R (with Intel MKL) which makes matrix multiplications faster, but for fair comparison I set it to be single threaded.
setMKLthreads(1)
In my ...
4
votes
Accepted
Simple natural language classifier
Welcome to Code Review!
This is an interesting program; thanks for sharing!
To help you maintain it ...
baseDict appears to be unused, and can be removed. Ditto ...
4
votes
Accepted
4
votes
Accepted
Calculation of the Distance Matrix in the K-Means Algorithm in MATLAB
Your Distance Matrix Calculation
You wrote the code (I summarize it for the Distance Matrix):
...
3
votes
Accepted
Pole (Hackerrank)
This is my code, but the complexity is very high.
How high?
Python has standard formatting conventions, known as PEP8. There are free tools to lint code to those standards (e.g. this online checker, ...
3
votes
Accepted
Given a collection of points on a 2D plane, find the pair that is closest to each other
Consider using range-based for loop
If you don't need information about index of element, then you can iterate over the vector of points with following code:
<...
3
votes
Accepted
Selecting kids for a Christmas play with similar heights
Time is mostly spent in I/O
I played with your program and found that most of the time was spent doing I/O. However, from your comments, it appears you already improved your I/O so that your best ...
3
votes
Finding closest pair of 2D points, using divide-and-conquer
Here are some observations that may help you improve your code.
Use all required #includes
The code uses std::vector which ...
3
votes
Accepted
3
votes
Accepted
Clustering nodes with Hamming distance < 3
Generic comments
Your spacing is very odd and inconsistent, which makes reading the code a bit harder. 2 blank lines before function definition, spaces around operators, and after a coma is what is ...
3
votes
Accepted
Predict new ratings for each user based on their pearson correlation with other users
You have incorrect indexing in the loop. Better version with mapply and correct indexing:
...
3
votes
Accepted
"Similar Destinations" challenge
I've managed to solve the problem after a bit of selective profiling. It would seem that my initial hunch was right. The problem had less to do with the algorithm and more towards the data structures ...
3
votes
Accepted
A Simple Cluster Generator v0.2
This code looks pretty good, but here are some things that may help you further improve it.
Separate interface from implementation
The interface goes into the .h ...
3
votes
Accepted
A Simple Cluster Generator v0.3
#include <fstream>
#include <vector>
#include <string>
It's really nice to see that you are only #includeing ...
3
votes
DBSCAN "region query" too slow; implement a tree?
You don't provide much information, which is unfortunate, since this kind of optimization problem relies on knowing how to "skew" the code in order to get better performance.
For example, are your ...
3
votes
Accepted
K-Nearest Neighbors in pure Python
Assumption: k << N, where N = len(points)
There is no need to sort the entire list of points!
Instead, take the first k points, and determine their distance ...
3
votes
k-means using numpy
The code looks good, I wouldn't suggest anything as needing to be changed. In line with your question about possible ways to use Numpy better, I'll offer a few things you could try:
You can pass low/...
3
votes
Accepted
Efficiently determining maximum allowed euclidean distance between lists of colors
As @vnp says, a solution involving an octree would a more efficient way to find neighboring points.
Before you implement one, though, there are some huge time savings you can get by making some ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
clustering × 132python × 57
performance × 35
algorithm × 33
c++ × 24
numpy × 19
computational-geometry × 15
time-limit-exceeded × 14
java × 13
beginner × 12
machine-learning × 12
python-3.x × 11
c# × 8
c++11 × 8
python-2.x × 8
image × 7
pandas × 7
r × 7
geospatial × 7
random × 6
strings × 5
matrix × 5
statistics × 5
natural-language-processing × 5
scipy × 5