# fetch the images for the dataset
# this will take a long time the first run because it needs to download
# after the first time, the dataset will be save to your disk (in sklearn package somewhere) 
# if this does not run, you may need additional libraries installed on your system (install at your own risk!!)
from sklearn.datasets import fetch_lfw_people

lfw_people = fetch_lfw_people(min_faces_per_person=20, resize=None)

# get some of the specifics of the dataset
X = lfw_people.data
y = lfw_people.target
names = lfw_people.target_names

n_samples, n_features = X.shape
_, h, w = lfw_people.images.shape
n_classes = len(names)

print("n_samples: {}".format(n_samples))
print("n_features: {}".format(n_features))
print("n_classes: {}".format(n_classes))
print("Original Image Sizes {} by {}".format(h,w))
print (125*94) # the size of the images are the size of the feature vectors

"""
Explanation: Enter Team Member Names here (double click to edit):

Name 1:
Name 2:
Name 3:


In Class Assignment Two
In the following assignment you will be asked to fill in python code and derivations for a number of different problems. Please read all instructions carefully and turn in the rendered notebook (or HTML of the rendered notebook)  before the end of class (or right after class). The initial portion of this notebook is given before class and the remainder is given during class. Please answer the initial questions before class, to the best of your ability. Once class has started you may rework your answers as a team for the initial part of the assignment. 
<a id="top"></a>
Contents

<a href="#Loading">Loading the Data</a>
<a href="#svm">Linear SVMs</a>

Available only during the in class assignment:
* <a href="#svm_using">Using Linear SVMs</a>
* <a href="#nonlinear">Non-linear SVMs</a>

<a id="Loading"></a>
<a href="#top">Back to Top</a>
Loading the Data
Please run the following code to read in the "olivetti faces" dataset from sklearn's data loading module. 
This will load the data into the variable ds. ds is a bunch object with fields like ds.data and ds.target. The field ds.data is a numpy matrix of the continuous features in the dataset. The object is not a pandas dataframe. It is a numpy matrix. Each row is a set of observed instances, each column is a different feature. It also has a field called ds.target that is an integer value we are trying to predict (i.e., a specific integer represents a specific person). Each entry in ds.target is a label for each row of the ds.data matrix.
End of explanation
"""


# Enter any scratchwork or calculations here



"""
Explanation: Question 1: For the faces dataset, describe what the data represents? That is, what is each column? What is each row? What do the unique class values represent?
Every column is a pixel location in a 125x94 photograph.
Each row is a single image of someone's face.
The unique class values are the names of the people in the photographs.
<a id="svm"></a>
<a href="#top">Back to Top</a>
Linear Support Vector Machines
Question 2: If we were to train a linear Support Vector Machine (SVM) upon the faces data, how many parameters would need to be optimized in the model? That is, how many coefficients would need to be calculated?
11750
End of explanation
"""


# Enter any scratchwork or calculations here

print('Part C. With 100 features: ', '100')

"""
Explanation: Question 3: 
- Part A: Given the number of parameters calculated above, would you expect the model to train quickly using batch optimization techniques? Why or why not? 
- Part B: Is there a way to reduce training time?
- Part C: If we transformed the X data using principle components analysis (PCA) with 100 components, how many parameters would we need to find for a linear Support Vector Machine (SVM)?
Enter you answer here (double click)
A. No. Parallelizing wouldn't scale well to 11,750 threads.
B. Train on a subsample
C. 100
End of explanation
"""


