4: 'Other'}

n_comp = 200

handler = data_utils.data_handler(data_dir_path, sample_fractions=sample_fractions, 
                              input_size=input_size, labels_type='classes', 
                              output_size=output_size, normalize_input=False, 
                              create_samples_bool=False, preprocess_bool=False, 
                              crp_factor=2, ds_factor=3)
    
### Load data
X_train, y_train = data_utils.load_samples(handler, 'training', grey_scale=True)    
X_val, y_val = data_utils.load_samples(handler, 'validation', grey_scale=True)    

### Perform PCA
X_train_pca, X_val_pca, pca = data_utils.compute_pca(
        X_train=X_train, n_comp=n_comp, X_test=X_val)

### Train an one vs. all Logistic Regression model
param_grid = {'C': 10.**np.arange(-8, 8, 0.5)}

clf = GridSearchCV(LogisticRegression(multi_class='ovr'), param_grid, scoring="accuracy")

t0 = time()
clf = clf.fit(X_train_pca, y_train)
print("done in %0.3fs" % (time() - t0))
print(clf.best_estimator_)

acc_score = [x[1] for x in clf.grid_scores_]

plt.figure(figsize=(6, 4))
ax = plt.gca()
Exemple #2
0
                                  sample_fractions=sample_fractions,
                                  input_size=input_size,
                                  labels_type='classes',
                                  output_size=output_size,
                                  normalize_input=False,
                                  create_samples_bool=False,
                                  preprocess_bool=False,
                                  crp_factor=2,
                                  ds_factor=3)

X_train, y_train = data_utils.load_samples(handler,
                                           sample='training',
                                           grey_scale=True)

# PCA Variance Explained
X_train_pca, pca = data_utils.compute_pca(X_train, n_comp=X_train.shape[1])

plt.plot(np.cumsum(pca.explained_variance_ratio_))
plt.xlabel('Number of Components')
plt.ylabel('Explained Variance')
plt.title('Cumulative Variance Explained ')
plt.show()
plt.savefig(os.path.join(figures_dir_path, 'PCA_Variance_Explained.png'))

# Reconstruted Images
raw_img = X_train[5000, :].reshape(input_size)
vector_img = raw_img.reshape(np.prod(raw_img.shape))

plt.figure(figsize=(10, 8))
plt.subplot(2, 3, 1)
io.imshow(raw_img, cmap="gray")