Created
October 30, 2018 16:05
-
-
Save lucasghelal/78cb60b7ddd0661c9c50ef50c254bf3f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 matplotlib.pyplot as plt | |
import numpy as np | |
from sklearn.decomposition import IncrementalPCA | |
from sklearn.preprocessing import LabelEncoder | |
from sklearn.manifold import TSNE | |
def plot_features(file): | |
features = [] | |
labels = [] | |
with open(file) as f: | |
for line in f: | |
values = line.split(' ') | |
labels.append(values[0]) | |
features.append([float(i.strip().split(':')[1]) for i in values[1:] if i != '']) | |
features = np.array(features) | |
pca = IncrementalPCA(n_components=2, batch_size=3) | |
pca.fit(features) | |
data = pca.transform(features) | |
# tsne = TSNE(n_components=2) | |
# data = tsne.fit_transform(features) | |
le = LabelEncoder() | |
labels = le.fit_transform(labels) | |
print(le.classes_) | |
colors = ['navy', 'darkorange'] | |
plt.figure(figsize=(8, 8)) | |
for color, i, target_name in zip(colors, [0, 1], le.classes_): | |
plt.scatter(data[labels == i, 0], data[labels == i, 1], color=color, lw=2, label=target_name) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment