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 ...
Gareth Rees's user avatar
  • 49.6k
26 votes

Finding the closest point to a list of points

All your code could be rewritten as: ...
arekolek's user avatar
  • 401
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 ...
Ben Steffan's user avatar
  • 5,228
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 ...
Aaron's user avatar
  • 233
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: <...
Cris Luengo's user avatar
  • 5,503
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 ...
papagaga's user avatar
  • 5,747
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) ...
vidstige's user avatar
  • 273
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. ...
Quentin Pradet's user avatar
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 ...
Jerry Coffin's user avatar
  • 33.5k
4 votes
Accepted

Grouping rectangles horizontally and vertically

You can have a boolean as a parameter and select X or Y and Width or Height based on that parameter. You can declare the method like this: ...
Risky Martin's user avatar
  • 1,611
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 ...
ferada's user avatar
  • 11k
4 votes
Accepted

K-means clustering in Rust

DataPoint is a small enough structure, it might as well be Copy. squared_euclidean_distance ...
Shepmaster's user avatar
  • 8,628
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 ...
Graipher's user avatar
  • 40.9k
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 ...
Andrey Shabalin's user avatar
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 ...
AJNeufeld's user avatar
  • 33.4k
4 votes
Accepted

Implementation of K-means

Unnecessary type checking In update_h_params, you write ...
Brian61354270's user avatar
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): ...
Royi's user avatar
  • 582
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 ...
Edward's user avatar
  • 66.4k
3 votes
Accepted

Zip code reduce function

An alternative ...
mdfst13's user avatar
  • 21.5k
3 votes
Accepted

k-means clustering algorithm implementation

N.b. I'm pretty sure you can find optimised replacements of many of these functions in either the NumPy or SciPy library. Edit: I don't immediately see a reason for a slowdown except the addition of ...
ferada's user avatar
  • 11k
3 votes

Clustering similar tweets in a corpus

This is the same as just return document.lower().split(): ...
warvariuc's user avatar
  • 337
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 ...
cottonman's user avatar
  • 171
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 ...
301_Moved_Permanently's user avatar
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: ...
m0nhawk's user avatar
  • 366
3 votes

Grouping rectangles horizontally and vertically

To keep your code clean, you could define delegates: ...
wardies's user avatar
  • 161
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 ...
JS1's user avatar
  • 28.5k
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, ...
Peter Taylor's user avatar
  • 24.1k
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: <...
adasikow's user avatar
  • 121
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 ...
Edward's user avatar
  • 66.4k

Only top scored, non community-wiki answers of a minimum length are eligible