Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NMF.inverse_transform when reconstructing the dataset #107

Open
qinhanmin2014 opened this issue Dec 17, 2018 · 1 comment
Open

Use NMF.inverse_transform when reconstructing the dataset #107

qinhanmin2014 opened this issue Dec 17, 2018 · 1 comment

Comments

@qinhanmin2014
Copy link
Contributor

In notebook 03-unsupervised-learning

X_train, X_test, y_train, y_test = train_test_split(
    X_people, y_people, stratify=y_people, random_state=0)
nmf = NMF(n_components=100, random_state=0)
nmf.fit(X_train)
pca = PCA(n_components=100, random_state=0)
pca.fit(X_train)
kmeans = KMeans(n_clusters=100, random_state=0)
kmeans.fit(X_train)

X_reconstructed_pca = pca.inverse_transform(pca.transform(X_test))
X_reconstructed_kmeans = kmeans.cluster_centers_[kmeans.predict(X_test)]
X_reconstructed_nmf = np.dot(nmf.transform(X_test), nmf.components_)

Maybe we can change

X_reconstructed_nmf = np.dot(nmf.transform(X_test), nmf.components_)

to

X_reconstructed_nmf = nmf.inverse_transform(nmf.transform(X_test))

This will be more consistent with pca and I guess it's better to rely on scikit-learn API

@amueller
Copy link
Owner

Yeah, good idea. I had opened the issue for adding this scikit-learn/scikit-learn#6118 as a reaction to writing this code ;)

So when I wrote this, the feature wasn't there, but now it can be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants