Last active
August 29, 2015 14:13
-
-
Save chausler/2cf25f7b4dbf36650613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import seaborn as sns | |
from sklearn.decomposition import PCA | |
x_pca = PCA(n_components=2).fit_transform(X) | |
sns.jointplot("PCA_0", "PCA_1", x_pca) | |
import pylab as plt | |
from sklearn.metrics.pairwise import pairwise_distances | |
from sklearn.manifold import TSNE | |
model = TSNE(n_components=2, metric=pairwise_distances) | |
tsne_X = model.fit_transform(X) | |
plt.scatter(tsne_X.tsne_1, tsne_X.tsne_2) | |
from sklearn.cluster import DBSCAN | |
db = DBSCAN(eps=0.5, min_samples=16).fit(tsne_X.values) | |
neigh = KNeighborsClassifier(n_neighbors=10, | |
weights='distance') | |
has_cluster = ~np.isnan(X_clustered.cluster) | |
train_dat = X_clustered[has_cluster][['PCA_0', 'PCA_1']] | |
y = X_clustered[has_cluster].cluster | |
neigh.fit(train_dat, y) | |
predict_data = X_clustered[~has_cluster][['PCA_0', 'PCA_1']] | |
neigh.predict(predice_data) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment