Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anhquan0412 committed Dec 15, 2019
1 parent b701c59 commit fd83305
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 156 deletions.
3 changes: 1 addition & 2 deletions model/neural_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ def backward_pass(self,y,y_pred,l2,lr,**kwargs):
grad_wbias = np.sum(grad_wrt_input,axis=0) # (1,200)

grad_w = self.X_acts[i].T @ grad_wrt_input # (400,200)
grad_w+= (l2/bs) * self.weights[i][0] # l2 reg

grad_w,grad_wbias = self.opt.step(grad_w,grad_wbias,i,**kwargs)
self.weights[i][0]-= lr*grad_w #update weight
self.weights[i][0]-= lr*(grad_w + (l2/bs) * self.weights[i][0]) #update weight
self.weights[i][1]-= lr*grad_wbias #update bias

def fit_epoch(self,X_train,y_train,X_val,y_val,lr,epochs,bs=64,l2=0,beta1=0.9,beta2=0.99):
Expand Down
2 changes: 1 addition & 1 deletion model/random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, X, y, n_trees, sample_sz,is_reg=True, min_leaf=3,max_features
self.is_reg = is_reg

def create_tree(self,is_reg,min_leaf,max_features):
# generate random idxs with size sample_sz. Thus this model is not suitable for time-related dataset
# generate random idxs with size sample_sz
sample_idxs = np.random.permutation(len(self.y))[:self.sample_sz]
return DecisionTreeNode(self.X[sample_idxs,:], self.y[sample_idxs], is_reg,min_leaf,max_features)
def predict(self, X,thres=0.5):
Expand Down
2 changes: 1 addition & 1 deletion neural_net_optimizers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
"version": "3.7.4"
}
},
"nbformat": 4,
Expand Down
427 changes: 275 additions & 152 deletions scratch_neural_net.ipynb

Large diffs are not rendered by default.

0 comments on commit fd83305

Please sign in to comment.