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
| from sklearn.datasets import fetch_lfw_people | |
| faces = fetch_lfw_people(min_faces_per_person=60) | |
| face_data_raw = faces.data | |
| average_face = face_data_raw.mean(axis=0) | |
| face_data = face_data_raw - average_face | |
| pca = PCA(100).fit(face_data) | |
| PC = pca.transform(face_data) |
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
| truncated = faces.data[:500] # 500 *2914 Matrix | |
| average_face = truncted.mean(axis=0) | |
| face_data = truncted - average_face |
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
| U, s, Vt = LA.svd(face_data, full_matrices=False) | |
| S = np.diag(s) | |
| #U: 500 *500, S: 500 *500, Vt:500 *2914 | |
| dim = 100 | |
| US = U[:, 0:dim].dot(S[0:dim, 0:dim]) |
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
| X = US.dot(Vt[:dim,:]) | |
| X = X + average_face |
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
| fig, ax = plt.subplots(2, 5, figsize=(5, 2.5), | |
| subplot_kw={'xticks':[], 'yticks':[]}, | |
| gridspec_kw=dict(hspace=0.1, wspace=0.1)) | |
| for i in range(5, 10): | |
| ax[0, i-5].imshow(faces.data[i].reshape(62,47), cmap='binary_r') | |
| ax[1, i-5].imshow(X[i].reshape(62,47), cmap='binary_r') |
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
| N=5 | |
| fig, ax = plt.subplots(1, N, figsize=(5, 2.5), | |
| subplot_kw={'xticks':[], 'yticks':[]}, | |
| gridspec_kw=dict(hspace=0.1, wspace=0.1)) | |
| for i in range(1, N+1): | |
| ax[i-1].imshow(Vt[i].reshape(62, 47), cmap='binary_r') |
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
| $heroku pg:backups:capture | |
| //Make the latest backup file on Poshgres on heroku | |
| $heroku pg:backups:download | |
| //Download the latest backup file to the localhost(the name is latest.dump) | |
| //Reference is below |
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
| $pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump |
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
| db=# \t //1st command | |
| db=# \a //2nd command | |
| db=# \o file.json //3rd command | |
| db=# SELECT json_agg(json_build_object( //4thcommand | |
| 'pk', t.id,'model','meryota.question', 'fields', | |
| json_build_object('question_text',t.question_text, | |
| 'pub_date',t.pub_date))) from meryota_question as t; |
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
| [ | |
| { | |
| "model": "myapp.person", | |
| "pk": 1, | |
| "fields": { | |
| "first_name": "John", | |
| "last_name": "Lennon" | |
| } | |
| }, | |
| { |