Commit Graph

48 Commits

Author SHA1 Message Date
Gauthier I 5b04fe66e4
DOC Increase execution speed of plot_cluster_comparison.py (#21624)
* Reduced n_samples to increse speed

* ENH imporved visuals of Optic method for the first two dataset, still working on the other datasets

* ENH improved visuals for Optic method by tuning parameters

* Linting with black
2022-03-10 17:15:50 +01:00
Dimitri Papadopoulos Orfanos d4d5f8c7e0
MAINT consistent use of `print(__doc__)` in examples (#21307)
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
2021-10-22 15:33:22 +02:00
Thomas J. Fan 70a185ae59
MAINT Enable and run black on examples (#20502) 2021-10-07 10:13:00 +02:00
Thomas J. Fan d44c7ae8eb
EXA Set random_state=0 in AffinityPropagation example (#19507)
to prevent warning

Co-authored-by: Roman Yurchak <rth.yurchak@gmail.com>
2021-06-17 20:58:25 +02:00
putschblos 04534204f2
EXA Fix overlapping titles in clustering overview (#19506) 2021-02-22 16:23:55 +01:00
EL-ATEIF Sara 28fa8972d3
DOC rename Birch to BIRCH in docs (#19368) 2021-02-06 09:54:47 +00:00
Thomas J. Fan 7cc0177f8e
MNT Replaces numpy alias with builtin typse (#17687)
* MNT Replaces numpy alias with builtin typse

* STY Lint error
2020-06-24 16:51:51 +02:00
Adrin Jalali a475594614 FEA OPTICS: add extract_xi method (#12077) 2019-04-28 00:11:04 +10:00
Adrin Jalali 40441e86f5 [MRG+1] OPTICS fit uses the selected `extract_method` parameter (#12087)
* add extract method parameter

* change fancy to sqlnk

* test for invalid extract_method value

* test easy dbscan

* pep8

* add extract_sqlnk

* mention which parameter is used for which extact method

* add tests for extract methods with no params given

* Add the reference for the SQLNK method.

* make extract_optics_dbscan and extract_optics_sqlnk public

* fix references, sync docstrings

* fix more morege conflicts

* reorganize the code and get it closer to what we want

* pep8

* remove sqlnk, make compute_optics_graph public

* pep8

* remove unused reference

* make tests pass

* fix docstrings

* fix removal of removed parameter

* add back min_cluster size, xi needs it

* pep8

* fix docstring issue

* address Hanmin's comments

* remove core_sample_indices_

* fix comment

* pep8

* apply comments, remove example

* add public functions to classes.rst and __init__

* address Joel's comments
2019-03-03 20:38:00 +01:00
Gael Varoquaux 7d745eeed3
OPTICS (#11547)
* OPTICS clustering algorithm

Equivalent results to DBSCAN, but allows execution on arbitrarily large datasets. After initial construction, allows multiple 'scans' to quickly extract DBSCAN clusters at variable epsilon distances

* Create plot_optics

Shows example usage of OPTICS to extract clustering structure

* pep8 fixes

Mainly issues in long lines, long comments

* fixed conditional to be pep8

* updated to match sklearn API

OPTICS object, with fit method. Documentation updates.
extract method

* removed extra files

* plotting example updated, small changes

new plot example that matches the updated API
updated n_cluster attribute with reruns of extract
removed scaling factor on first ‘fit’ run

* updated OPTICS.labels to OPTICS.labels_

should pass unit test now?

* additional labels_ changes

* added stability warning

Scales eps to give stable results from first input distance. Extraction
above scaled eps is not allowed; extraction below scaled eps but
greater than input distance prints stability warning but still will run
clustering extraction. All distances below initial input distance are
stable; no warning printed

* Noise fix; updated example plot

Fixed noise points from being initialized as type ‘core point’
Fixed initialization for first ‘fit’ call
Decoupled eps and eps_prime (deep copy)

Matched plot example to same random state as dbscan
Added second plot to show ‘extract’ usage

* Changed to match Sklearn API

eps is not modified in init; kwargs fix

* Forcing 2 parameters

Why do I have to do this?

* Conforming to API

Fit now returns self; test fix for unit test fail in ball tree (asarray
problem)

* Fixing plot example

labels to labels_

* Fixed issue with sparse matrices

* Another attempt at fixing the sparse matrix error

Temporary fix until balltree can be updated to deal with sparse
matrices.

* Better checking of sparse arrays

Using ‘check_array’

* General cleanup

Removed extraneous lines and comments (old commented out code has been
removed)

*  Added unit tests for extract function

Added the unit tests in test_optics for fit, extract, and declaration.
Should bring coverage to ~100%. Additionally, fixed a small bug that
cropped up in the extract function during testing.

* Attempting for near 100% coverage

Removed unused imports, added to get warning.

* Fixed error in unit tests

* Trimmed extraneous 'if-else' check

see title

* forcing to check for a warning.

Result should be 100% coverage

* Updates to doc strings

All public methods now have doc strings; forcing a rebuild of OPTICS so
that build tests pass (last round failed due to external module)

* Style / pep8 changes

99% pep8 now… line 138 isn’t, but reads better with the long variable
names

* Added Narrative Documentation

Includes general description, discussion of algorithm output, and
comparison with DBSCAN. References and implementation notes are included

* Vectorized nneighbors lookups

Following suggestion from jnothman for doing nneighbors queries enmass.
Added OPTICS to cluster init

* fixing init build error

* reverting init

* All code now vectorized

…at least all code that can be ;)

Some general pruning and cleanup as well

* Style changes

Now 100% pep8

* Changing parameter style

matching DBSCAN

* Extraction change; Authors update

—initialize all points as ‘not core’ (fixes bug when plotting at
epsPrime larger than eps)
—added Sean Freeman to authors list

* Changed eps scaling to 5x instead of 10x

10x scaling is too conservative…eps scaling at 5x is perfectly stable,
and much faster as well.

* Fixing unit test

Should be ‘None’ for this; initialization previously at 1 for ‘is_core’
was incorrect

* Actually fixing unit test

Null comparison doesn’t work, using size

* Making ordering_ and other attributes public

renamed core_samples to core_sample_indices_ (as in DBSCAN). Used
attribute naming conventions (trailing _ character), and made
ordering_, reachability_, and core_dists_ public.

* Updates for Documentation

includes attribute strings for now public attributes

* Pep8 cleanup

Minor pep8 and pyflakes fixes

* updating plot example to match new attribute name

* CamelCase fixes

conforming to sklearn API on CamelCase

* adding hierarchical extraction function

Added hierarchical extraction from #2043

#2043 is BSD licensed and hasn’t had any activity for 10 months, so
this seems pretty kosher; authors are cited in the code

* added hierarchical switch to extract

Additional style and documentation changes as well

* cluster order bug fix

ensured that ordered list is always same length as input data

* removed hierarchical cluster extraction

Code from FredrikAppelros is totally unable to handle noise— as
currently written every point is assigned to a cluster, except the
first point of that cluster. May include later as a third method

* initial import of automatic cluster extraction code

Adding the excellent (and working) automatic cluster extraction code
from Amy X. Zhang. Some minor formatting changes on import to conform
to pep8

* wrapper for 'auto' extraction

additional fixes to style (camelCase, etc.), comments; made all helper
functions private

* test and example updates

Much better example data to showcase ‘auto’ extraction. Unit tests now
test both extraction methods. Set ‘auto’ as default, as it doesn’t
require any parameters and gives a better result. Pruned references to
hierarchical clustering

* fixing unit coverage; pruning unused functions

probably could still get a better unit test for ‘auto’ clustering…

* Added 'filter' fuction

Allows density-based filtering. Useful for cases where only a
‘noise’/‘no noise’ classification is desired. Function does not require
fitting prior to running, although it can be run after a fit if desired

* Vectorizing auto_cluster

generalizes input to multiple dimensions as well…

* updated filter function

* fixing test error

setting minPts to < data size returns None (with error message)

* removing exception handling in favor of conditional check

* Updated unit tests

Coverage to 90%. PEP8 fixes

* Additional unit test

Now at 94%; auto extract method is very hard to test… this new unit
test adds a more robust dataset to trigger more branches for testing.
Some of the remaining conditionals are pretty rare … :-/

* Fix unit test bug / python 3 compat

None type comparison problem…

* Fixed annoying deprecation warning for 1d array in BallTree

PEP8 Fixes

* More PEP8 and remove print statements fromt est

* 70 to 80% faster, fixed distance metrics

Modified to remove extraneous sorts, nneighbors query, and reduced
pairwise distance calculations to the upper triangle of a distance
matrix (instead of the full matrix). It appears that in ‘full’ scans
(i.e., when epsilon is set to inf, or the width of the data set),
OPTICS now actually outperforms DBSCAN… also, should be easy to run
distance calculations in parallel now for large datasets, with proper
heuristics.

* Fixing unit test failure

* Exposed auto_cluster parameters as public

documentation and API update so that users can tweek the auto method

* Fixed def with missing ':'

* Fix bugs from api change...

make sure that arguments are being called correctly with the new
extract_auto() method

* pep8 / pyflakes changes

* Updated example / plot

Correctly generates figure with subplots for DBSCAN / OPTICS comparison

* Tuning plot example / pep8 change

* Bug fix for commit 0b4cbdd (enforce stable sort)

the returned index from “sp.argmin(setofobjects.reachability_[n_pr])”
assumes that entires are stably sorted by distance from query point
(i.e., that ties in the argmin return the closest point to the input
point).

Still overall faster compared to the pre 0b4cbdd version, since we’re
filtering processed points before sorting by distance… and also only
calculating distances for non-processed points, instead of all within
the epsilon query.

* Code review fixes (style)

Fixes coding style (test comments, camel case, author list, relative
imports, etc). Included a new unit test and .npy file to explicitly
test reachability distances (test coverage at 99%).

* fixing new unit test

can’t import reach_values.npy in current directory….just placed testing
values in script directly (~200 lines for 1500 testing values)

* refactored min_heap to c extension

reduced optics file by about 100 lines of code… new c extension for
speedup (needs further optimization…6-10X speedup still possible)

* minor fixes..

* small cython optimizations

* cython fixes

* Add foo.txt

* Remove foo.txt

* fix compilation error

* last optimizations cython/numpy

MinHeap is only called once…so it’s faster to do a simple linear scan
here. The np.argmin() function does *almost* the exact same thing, but
the custom quick scan function is needed for cases where reachability
distances are tied (and the next point is selected based on which of
the points tied in reachability are closest to the querying point).
OPTICS is now faster than DBSCAN for medium-to-large number of input
points, and has better worst case run time (eps=inf).

* fix pyflakes errors; change default eps value

* _

* API changes from agramfort

Removed ‘filter method’, changed print statements to exceptions and
warnings as needed, remove ‘processed’ flag and replaced with fit_check
method, changed array copies to parameters, updated unit tests, changed
inline documentation to match proper doc string formatting, made
private class private. Probably some other changes too…

* fixed core samples bug

* added fit_predict

conforming to scipy api

* updates to variable names; update plot

* refactor to remove balltree specific code

* major refactor

finished decoupling balltree; lots of changes

* fixed bugs; test all pass again

:-)

* fixed weird cython bug

…not at all sure why pairwise_distances doesn’t automatically return
np.float arrays. Makes no sense to me. I could understand cases in
which the metric call returns int’s (i.e., city block)… but why it
would return float.32 instead of float.64 seems super odd.

* major refactor

deleted extract and auto_extract methods; added optics function; added
extract_dbscan method; added extract_dbscan and extract_optics
functions; updated unit tests; renamed `eps` to `max_bounds`; flake8
corrections; added types: int —> labels, bool —> is_core, enforced X to
be ‘float’ (fixes cython type errors)

* Updated Documentation!

Updated plot with reachability plot, as well as documentation :)

* fix flake8 error

* added optics to cluster comparison

Don't like the figure since it doesn't use black for noise, but added OPTICS for consistency

* Updated comparison plot to transpose

...kinda kludgy fix for the transpose

* small fix

* flake8 error

* reverting transpose of cluster comparison (seperate PR #9739)

* fixes from agramfort's review

public/private changes, numpydocstring fixes, a few pep8 fixes that flake8 didn't flag for some reason...

* fix for error message

unit test should pass now

* force cluster_id's to start at 0

* Fix sp. error and flake8 warning(s)

* Updated documentation

responses to reviews

* Removed extraneous files

also fixed small typo

* fixing lgtm alert

* changes from jnothman

small fixes for docs, plots, and tests

* Fixes from jnothman's review

Reorded parameters, updated documentation, removed unneeded else statement, changes to varible names.

* Fixing flake8 error

* Removed neighbors / balltree inheritance

Also decouples n_jobs -- can set n_jobs for just the kneighbors lookup, while keeping pairwise lookups to single job

* Made nbrs private and moved initiation to fit()

also renamed core_dists to core_distances.

* fixed non-standard characters

* Response to TomDLT review

narrative changes to tests. Normalized reachability distances for significant_min parameter. Cleaned up plots; small changes to documentation with optics_.py

* Fixed labeling bug

also minor documentation updates

* update unit test

since labels are 0 indexed, max of labels is (1 - total number of clusters). We can't take len(set(clusters)) because of noise (will be 4, not 3).

* Simple fixes per jnothman

Fixed float division, condensed variable names to be shorter, renamed bools to True and False, removed un-needed code block. Still need to add tests for cluster tree extraction :-(

* Auto-cluster tests

coverage should be complete now; fixed minor bug; removed un-needed check.

* fixing test error

* removed python loop

also fixed documentation link

* Fixing test error

* Fix typo in unit test

entry was supposed to be '1.0' not '10'; the test is supposed to posit 3 clusters, 2 of which are too small and are merged. Old version posited 4 clusters, two of which were merged as intended, and two of which were discarded (cluster merging requires one of the clusters to be large enough to be an independent cluster; with 4 instead of three, this case did not happen for either of the first two clusters).

* documentation updates

* Post-merge doctest fix

merge conflict in clustering.rst in previous commit; this push updates the doctest values to current correct values, and resolves the conflict

* DBSCAN / OPTICS invariant test

Restructured documentation. Small unit test fixes. Added test to ensure clustering metrics between OPTICS dbscan_extract and DBSCAN are within 2% of each other.

* Update _auto_cluster docstring

renamed reachability_ordering --> ordering for consistency

* changes fro jnothman

changes unit tests to check for specific error message (instead of 'a' error); minor updates to documentation. This also fixes a bug in the extract_dbscan function whereby some core points were erroneously marked as periphery... this is fixed by reverting to a previous extraction code block that initalizes all points as core and then demotes noise and periphery points during the extract scan. Parameterized unit test.

* fix spelling error in tests

* contingency_matrix test

New invarient test between optics and dbscan

* small unit test updates per jnothman

* unit test typo fix

* extract dbscan updates

Vectorized extract dbscan function to see if would improve performance of periphery point labeling; it did not, but the function is vectorized. Changed unit test with min_samples=1 to min_samples=3, as at min_samples=1 the test isn't meaningful (no noise is possible, all points are marked core). Parameterized parity test. Changed parity test to assert ~5% or better mismatch, instead of 5 points (this is needed for larger clusters, as the starting point mismatch effect scales with cluster size).

* updated documentation comparing OPTICS/DBSCAN

* DOC: phrasing and whats_new

* MISC: small mem footprint in OPTICS
2018-07-16 13:10:42 +02:00
Mohamed Maskani f793f55310 [MRG + 1] Fix cluster coloring in example (#10876)
* Fix issue

* [doc build] trigger doc build

* Color outliers in black
2018-03-28 10:20:39 +11:00
Bob Baxley db370178d6 [MRG+1] [DOC] Adding GMM to plot_cluster_comparison.py (#6305)
* Adding GMM to plot_cluster_comparison.py and changing number of components in all algos to 3.

* adding two datasets to clustering comparision example

* Adding GMM to plot_cluster_comparison.py and changing number of components in all algos to 3.

* adding two datasets to clustering comparision example

* GMM example using GaussianMixture

* fixing lint errors; changing order of datasets in the columns so that no_structure is at the end.

* adding warning supression.

* fixing warning supression.

* hand-tuned cluster parameters

* moved list of algo names; cleaning up color cycling

* fixing islice stop to be an int

* change default to params, make plot color-blind compatible, fix spelling error

* new color palette that is more color-blind friendly
2017-03-21 23:15:37 +01:00
YenChenLin 46fc1be145 Remove redundant words in sklearn 2016-02-23 16:54:03 +08:00
Andreas Mueller 46060feddc Pass the appropriate include_self argument to kneighbors_graph everywhere. 2015-03-16 13:30:22 -04:00
MechCoder 129f371f85 DOC: Modification to the documentation of threshold 2014-12-05 14:07:16 +01:00
MechCoder abc78088b9 Made the following changes
1. Fix condition for checking threshold.
2. Fix the global clustering by remapping the samples to the
   subcluster_centers.
3. Add tests for threshold.
4. Minor doc and cosmits.
2014-12-05 14:07:16 +01:00
MechCoder f4afc7ecf0 ENH: Add narrative documentation 2014-12-05 14:07:16 +01:00
Andreas Mueller c1a429e46d Remove unused distance calculation from clustering example. 2014-11-13 15:31:09 -05:00
Rajat Khanduja 5e20b8c664 Fixed pep8 violations. Some 'line too long' errors still remain. 2014-05-15 09:23:16 +05:30
Rajat Khanduja 2244098532 Updated examples to use pyplot for plotting instead of pylab
Some examples not updated because scripts throw error (probably not
because of the change)
2014-05-15 02:18:07 +05:30
Gael Varoquaux 3ac34554e4 MISC: documentation and cosmits
Address comments by @jnothman
2014-02-17 11:20:42 +01:00
Gael Varoquaux 75705e2b24 MISC: remove reference to deprecated Ward 2014-02-07 09:25:08 +01:00
Gael Varoquaux cfa55d3e31 DOC: AgglomerationClustering doc and examples 2014-02-06 12:51:42 +01:00
Lars Buitinck 837093df7f P3K: use print as a function in the examples
Also corrected some typos, including two people misspelling their own names :)
2013-02-01 15:04:42 +01:00
kuantkid 46f15875db RENAME rename eigen_tol and eigen_solver, and warning about using old variable name eig_tol and mode 2012-11-27 09:35:45 -05:00
kuantkid 0ef3aadc69 RENAME parameter rename in examples 2012-11-27 09:35:16 -05:00
Andreas Mueller c0a057843c ENH rename Scaler to StandardScaler everywhere 2012-09-23 17:31:15 +01:00
Andreas Mueller 0df98bb3c0 ENH add test, revert affinity propagation to previous parametrization (was a bit over-eager there) 2012-08-27 09:35:14 +02:00
Andreas Mueller 28fd13f7e4 ENH Starting on affinity propagation 2012-06-03 20:33:06 +02:00
Andreas Mueller 86baa8a7d6 ENH "fit_pairwise" for spectral clustering. 2012-06-03 20:33:06 +02:00
Andreas Mueller d9a6243c98 ENH rename k in clustering examples and doctests to n_clusters 2012-05-30 07:41:34 +02:00
Andreas Mueller dcc1c7431c COSMIT + MISC pep8, pyflakes, typos and some other cleanup of examples. 2012-04-29 23:13:06 +02:00
GaelVaroquaux 2784be98a0 COSMIT: prettier plot 2012-03-27 11:06:27 +02:00
GaelVaroquaux 77c844afba DOC: timings in cluster comparison example 2012-03-27 11:01:51 +02:00
GaelVaroquaux cc1765cc38 COSMIT: layout tweak 2012-03-26 01:59:15 +02:00
GaelVaroquaux df558e84be MISC: tweak example layout 2012-03-26 00:17:35 +02:00
GaelVaroquaux e64b7a62fc ENH: summary table on clustering 2012-03-26 00:17:35 +02:00
GaelVaroquaux f0d7eb6382 DOC: affinity-propagation in clustering comparison
Also add a 'null' example for clustering
2012-03-25 19:13:16 +02:00
GaelVaroquaux 118c00d93d ENH Ward: better behavior for non-fully-connected graphs
Improves the plot_cluster_comparison example
2012-03-25 17:33:49 +02:00
Olivier Grisel de2511871c better blob seed so that both DBSCAN and meanshift are working well 2012-03-04 20:11:48 +01:00
Andreas Mueller 24661d3513 ENH fixed seed, added center positions 2012-03-04 19:53:38 +01:00
Andreas Mueller 842f366f83 MISC added xlim and ylim for @ogrisel's weird matplotlib ;) 2012-03-04 19:34:25 +01:00
Andreas Mueller 84edda6ba7 COSMIT removed debugging print 2012-03-04 19:07:03 +01:00
Andreas Mueller 124b19f1e8 COSMIT cleanup, pep8 2012-03-04 17:51:38 +01:00
Andreas Mueller 9bcd00af23 MISC use Gaels pretty plot, add dbscan, normalize data... 2012-03-04 17:46:38 +01:00
Andreas Mueller c93c1a290e FIX broke label_probagation example, now fixed it again. 2012-03-04 14:38:14 +01:00
Andreas Mueller 11ba3f725a ENH clustering example with spectral clustering and ward with connectivity. looking better now, still not perfect. 2012-03-04 14:30:56 +01:00
Andreas Mueller db1e1868be ENH cluster comparison example (starting) 2012-03-04 00:43:36 +01:00