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 numpy as np | |
from numpy.linalg import inv | |
import statsmodels.api as sm | |
# from scratch | |
x = sm.add_constant(x) # add constant in the 0 index | |
b = inv(x.T.dot(x)).dot(x.T).dot(y) | |
yest_ols = np.array([b[2]*v**2 + b[1]*v + b[0] for v in x.T[0]]) | |
# with using numpy.linalg.lstsq |
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
{ //json_build_object | |
"model": "myapp.person", | |
"pk": 1, | |
"fields": { //json_build_object | |
"first_name": "John", | |
"last_name": "Lennon" | |
} | |
} |
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 | |
db=# \a | |
db=# \o file.json | |
db=# select row_to_json(t) from meryota_question as t; | |
//'meryota_question' is just my database name. |
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" | |
} | |
}, | |
{ |
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
$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
$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
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
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
X = US.dot(Vt[:dim,:]) | |
X = X + average_face |