Skip to content

Fix "Variables are collinear" warning in plots_lle_digits#14162

Merged
glemaitre merged 2 commits intoscikit-learn:masterfrom
KenitoInc:fix-plot-lle-digits-14117
Jul 1, 2019
Merged

Fix "Variables are collinear" warning in plots_lle_digits#14162
glemaitre merged 2 commits intoscikit-learn:masterfrom
KenitoInc:fix-plot-lle-digits-14117

Conversation

@KenitoInc
Copy link
Copy Markdown
Contributor

Fix this by assigning a value init='random' during initializing NeighborhoodComponentsAnalysis.

Related to issue #14117

#WiMLDS
@MaggieChege
@dominicondigo

Copy link
Copy Markdown
Member

@rth rth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few comments below.

X2.flat[::X.shape[1] + 1] += 0.01 # Make X invertible
t0 = time()
X_lda = discriminant_analysis.LinearDiscriminantAnalysis(n_components=2).fit_transform(X2, y)
X_lda = discriminant_analysis.LinearDiscriminantAnalysis(n_components=2)\
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended to avoid \ for line breaks. A better way to fix this would be to do,

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

then

estimator = LineariscriminantAnalysis(n_components=2)
X_lda = estimator.fit_transform(X2, y)

if it's still too long

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback noted. Let me work on it

n_components=2, random_state=0)
t0 = time()
# X3 = X.copy()
# X3.flat[::X.shape[1] + 1] += 0.01 # Make X invertible
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, either add this code (if it is necessary and it solves some issues) or remove these added lines. Commented code is really confusing for the reader, particularly in examples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left these lines inadvertently. I am removing them

X2.flat[::X.shape[1] + 1] += 0.01 # Make X invertible
t0 = time()
X_lda = discriminant_analysis.LinearDiscriminantAnalysis(n_components=2).fit_transform(X2, y)
X_lda = discriminant_analysis.LinearDiscriminantAnalysis(n_components=2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that there is a bit of inconsistency originally in the example. Could you do make sure that we have the following pattern for all the example:

estimator = module.Class(...)
t0 = time()
estimator.fit_transform(...)

It will be nicer style for the line breaking then/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, let it as it is. We will open a new issue/PR to solve these inconsistencies.

Copy link
Copy Markdown
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. However, we need to open an issue to make the example consistent:

  • importing only the class estimator on the top of the file (and not the module)
  • declaring the estimator first and operate fit_transform with the timing around
  • correct that we apply TruncatedSVD and not PCA

@KenitoInc
Copy link
Copy Markdown
Contributor Author

Thanks @glemaitre Once we open the issue, I am willing to work on it.

@glemaitre glemaitre merged commit 5310b87 into scikit-learn:master Jul 1, 2019
@glemaitre
Copy link
Copy Markdown
Member

I am merging and opening an issue. Thanks @KenitoInc for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants