Commit Graph

350 Commits

Author SHA1 Message Date
Joel Nothman 1a54989ce8 DOC credit multiple authors of new example 2019-01-17 22:19:19 +11:00
Christos Aridas d2a77d7e78 DOC Add an example of inductive clustering (#10852) 2019-01-17 22:16:22 +11:00
Adrin Jalali 69c8967e21 DOC Fix warnings in examples (#12654)
Fixe or suppresses many warnings in examples, including matplotlib complaining about the non-gui backend.
2019-01-17 21:41:13 +11:00
Thomas Moreau d25da1be20 FIX make joblib utils private, and remove mentions of externals.joblib (#12345) 2018-11-20 10:53:52 +11:00
Koen 81d2178ed0 EXA calculate number of noise points (#12428) 2018-10-23 07:56:53 +11:00
Hanmin Qin dd3b705f7b MNT Unused imports in examples 2018-10-02 17:12:19 +08:00
Hanmin Qin a47e7795f9 EXA Fix plot in plot_optics.py
Closes #11849
2018-08-30 22:07:07 +08:00
Nicolau Werneck e79fe955c5 DOC Update plot_color_quantization.py (#11750)
Make random color actually select n_colors
2018-08-06 18:22:20 +10:00
ZJ Poh adddf00433 [MRG] np.ones -> np.full (#11628) 2018-07-23 09:49:01 +02:00
Joel Nothman 14e7c328df Restructure access to vendored/site Joblib (#11471)
In order to fix #11408, this swaps `joblib` and `_joblib`. It however, allows users to access joblib's `Memory` or `Parallel` functionality without accessing `sklearn.externals._joblib` by importing `Memory`, `Parallel`, etc. into `sklearn.utils`.
2018-07-17 18:02:11 +02:00
Andreas Mueller 0b8d362545 [MRG] Examples deprecations (#11561) 2018-07-17 00:08:04 -05: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
Justin Shenk 21eb82dea2 DOC Remove unused function argument `X` from `plot_clustering` function (#11049) 2018-05-02 10:04:45 +10: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
Hanmin Qin 6f7394953b EXA avoid use of matplotlib.cm.spectral which has been removed (#10764) 2018-03-07 16:49:45 +11:00
jotasi cf9c67e9ec DOC Change image in segmentation example (#10647)
* The Coins image is segmented more intuitively

* Changed face->coin in the docs as well

* Removed unused scipy import.
2018-02-18 12:12:27 +11:00
jotasi 7f0e433183 Remove _pilutil usages from examples (#10527)
Use scikit-image and scipy instead where appropriate.
2018-02-12 17:54:18 +01:00
jotasi b846467476 contours is not a kwarg of matplotlib.pyplot.contour (#10569) 2018-02-01 10:16:14 +01:00
Leland McInnes 823382995c [MRG+2] Single linkage clustering (#9372)
* First cut at basic single linkage internals

* Refer to correct dist_metrics package

* Add csgraph sparse implementation for single linkage

* Add fast labelling/conversion from MST to single linkage tree; remove uneeded single_linkage.pyx file.

* Ensure existing tests cover single linkage

* Iterating toward correct solution. Still have to get n_clusters, compute_full_tree=False working

* Fix the parents array when we don't get the "full tree"

* Add single linkage to agglomerative clustering example.

* Add single linkage to digits agglomerative clustering example.

* Update documentation to reflect the addition of single linkage.

* Update documentation to reflect the addition of single linkage.

* Provide a more complete comparison of the different linkage methods, highlighting the relative strengths and weaknesses.

* Update docs with a more complete comparison on linkage methods (scale to be determined?)

* Update WhatsNew for single linkage clustering.

* Handle true zero distances by setting them to "epsilon" distances

* Add test for identical points messing with sparse linkage clustering.

* Test all the linkage methods for identical point issues

* Cast precomputed distances to float64 for consistency

* Turn bounds checking off; add docsting warning.

* Make public and private versions of labelling.

* more efficient is sorted check

* Explicit cast to cover all bases
2018-01-22 14:58:17 +01:00
jotasi 96dd337ae0 Remove deprecated imread/imresize from docs and examples (#10502) 2018-01-19 14:20:50 +01:00
Jan Margeta d01cdc204e Fix spectral embedding implementation (#9062) 2017-12-18 10:20:53 +01:00
Vrishank Bhardwaj ed5a0cac6b [MRG+1] Update docstrings of KMeans.inertia_ (#9920)
[MRG+2] Update docstrings of KMeans.inertia_
2017-10-15 18:56:18 -07:00
Hanmin Qin 32ac22870d [MRG+1] Fix warnings in lgtm.com (remove redundant code) (#9719) 2017-09-14 11:42:58 +02:00
tobycheese da415db476 DOC remove unnecessary line (#9504) 2017-08-07 08:48:07 +10:00
Loïc Estève 1bb8826fd2 Fix pdf doc generation
Use 4 plots instead of one so that unsupervised_learning.rst can show png separately.

Partially reverts #9030. Minor changes for consistent labeling.
2017-06-26 14:13:20 +02:00
Aarshay Jain 1d4e18a1a7 [MRG + 1] 10 more examples fixed with matplotlib 2.0 updates (#9030)
* examples/covariance/plot_outlier_detection.py - matplotlib2.0 update

* examples/cluster/plot_kmeans_silhouette_analysis.py - matplotlib2.0 update

* examples/cluster/plot_birch_vs_minibatchkmeans.py - matplotlib2.0 + pep8 fix

* examples/cluster/plot_cluster_iris.py - matplotlib2.0 update

* examples/cluster/plot_agglomerative_clustering.py - matplotlib2.0 update

* examples/cluster/plot_ward_structured_vs_unstructured.py - matplotlib2.0 update

* examples/cluster/plot_kmeans_assumptions.py - matplotlib2.0 update

* examples/classification/plot_lda_qda.py - matplotlib2.0 + pep8 fix

* examples/calibration/plot_calibration.py - matplotlib2.0 update

* examples/plot_johnson_lindenstrauss_bound.py - matplotlib2.0 update

* flake8 changes

* reversing changes for plot_kmeans_assumptions & plot_agglomerative_clustering

* cluster/plot_cluster_iris.py - major fixes

* examples/cluster/plot_cluster_iris.py - flake8 fix

* examples/cluster/plot_cluster_iris.py - 3d projection error fix

* cluster/plot_cluster_iris.py - elevation and azimuth setting
2017-06-21 16:04:53 +02:00
plagree 1f6ac72df7 [MRG] DOC examples with correct notebook style (#9061)
* DOC examples with correct notebook style

* Modifications in examples/ to avoid unwanted notebook style

* Remove last notebook style example

* Space formatting to avoid notebook style
2017-06-20 14:48:57 +02:00
Nate Guerin 25917bae33 Use tuples for color specification (#9149)
In the Matplotlib 'Specifying Colors' section, neither list nor array is a valid color specification type.  When this example is run using Python 3.5, and matplotlib 2.0.2 (latest), it errors with the message: 

"ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"

This change preserves the semantics of the example while allowing it to successfully run by converting to tuples for the matplotlib color specification.
2017-06-19 00:33:10 +10:00
Loïc Estève b185c4e8f9 FIX examples with numpy 1.13 2017-06-09 00:21:41 +02:00
Naoya Kanai bd0fc236e0 [MRG+1] MAINT drop SciPy < 0.13 (#8854)
Remove sklearn.utils.fixes functions that are not needed for scipy >= 0.13 and keep deprecated wrappers in other modules.
2017-06-02 23:36:33 +02: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
Patrick Pei bd4e00b1eb [MRG] DOC Example: Fix minor standard output formatting (#7456) 2016-09-20 08:06:36 +10:00
fisache b242539fc0 Fix minor typo 2016-07-13 16:23:14 +09:00
Thierry Guillemot 78a674875e Correct the deprecation of the random_integers numpy function. (#6712) 2016-04-26 16:08:48 +02:00
Saiwing Yeung c5fd5cbb7e DOC: fixed typos and one style issue in plot examples
The comment in a few example plots refer to "the mesh [x_min, m_max] x
[y_min, y_max]" when it should be "x_max".

Also fixed the spacing in plot_random_forest_embedding.py `[x_min,
x_max] x [y_min, y_max]` to `[x_min, x_max]x[y_min, y_max]` to comply
with the coding style of other files with similar code (like those in
the current pull request).
2016-04-25 11:59:40 +08:00
YenChenLin 46fc1be145 Remove redundant words in sklearn 2016-02-23 16:54:03 +08:00
Nelson Liu fcfaa5fc37 Updated examples and tests that use scipy's lena
scipy.misc.lena will be removed in scipy version 0.17.
This changes the example to use scipy.misc.face instead.
2016-02-11 09:13:40 +01:00
Gael Varoquaux 317dea8a05 Merge pull request #6005 from seales/SpellingFix
[MRG+1] General spelling fixes
2016-01-04 13:42:20 +01:00
MechCoder ad758d2069 FIX: Cluster centers after fir in KMeans and MBKMeans need not be ordered in the same way 2015-12-19 23:59:32 -05:00
seales 0485ada58b General spelling fixes 2015-12-16 09:46:42 -08:00
Qimu Zheng 0e074a009a Fix bug in mini batch kmeans example 2015-12-16 14:19:31 +08:00
Andreas Mueller 5b1aca08c2 MAINT Don't use deprecated 1d X (or deprecated matplotlib stuff) in examples. 2015-12-10 12:11:48 -05:00
Gael Varoquaux b043d643d1 DOC: Comment better the importance of the mask
To address #5921
2015-11-26 07:34:39 +01:00
Raghav R V f67e911124 DOC Modify documentation/examples for the new model_selection module 2015-10-29 16:49:23 +01:00
Phil Roth f9e07364d6 Adding a new kmeans example. 2015-07-23 14:43:26 -04:00
Yury Zhauniarovich d9e46314b0 Updated graph ranges
The minimum and maximum values for the graph were not correctly defined.
2015-07-10 14:13:56 +02:00
Andreas Mueller 1491843d95 DOC minor fixes in formatting, don't use deprecated n_components in Agglomerative 2015-03-25 20:20:29 -04:00
Andreas Mueller 46060feddc Pass the appropriate include_self argument to kneighbors_graph everywhere. 2015-03-16 13:30:22 -04:00
Andreas Mueller 9bc4de8dae some fixes for sphinx and in examples 2015-03-02 12:50:53 -05:00
Loïc Estève 7b24628421 DOC python 3 fix in plot_kmeans_silhouette_analysis.py 2015-02-18 16:24:41 +01:00