Python Forum
Developing larger Neural Networks
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Developing larger Neural Networks
#1
 def train():
    #random init of weights
    w1 = np.random.randn()
    w2 = np.random.randn()
    b = np.random.randn()
    
    iterations = 1000000
    learning_rate = 0.01
    costs = [] # keep costs during training, see if they go down
    
    for i in range(iterations):
        # get a random point
        ri = np.random.randint(len(data))
        point = data[ri]
        
        z = point[0] * w1 + point[1] * w2 + b
        pred = sigmoid(z) # networks prediction
        
        target = point[2]
        
        # cost for current random point
        cost = np.square(pred - target)
        
        # print the cost over all data points every 1k iters
        if i % 100 == 0:
            c = 0
            for j in range(len(data)):
                p = data[j]
                p_pred = sigmoid(w1 * p[0] + w2 * p[1] + b)
                c += np.square(p_pred - p[2])
            costs.append(c)
        
        dcost_dpred = 2 * (pred - target)
        dpred_dz = sigmoid_p(z)
        
        dz_dw1 = point[0]
        dz_dw2 = point[1]
        dz_db = 1
        
        dcost_dz = dcost_dpred * dpred_dz
        
        dcost_dw1 = dcost_dz * dz_dw1
        dcost_dw2 = dcost_dz * dz_dw2
        dcost_db = dcost_dz * dz_db
        
        w1 = w1 - learning_rate * dcost_dw1
        w2 = w2 - learning_rate * dcost_dw2
        b = b - learning_rate * dcost_db
        
    return costs, w1, w2, b
        
costs, w1, w2, b = train()
Hello All,

I am a new user to Python and have been attempting to develop logistic regressions and Neural Networks in Python over the past few weeks. I've hit a stumbling block with neural networks whereas when trying to handle a large dataset with many inputs i need many weightings, will i have to write them each individually out with the equations as done above for a 2 input model?

Above is for a 2 vraibles, about 8 inputs and 1 output
I want to be able to work with multiple variables, very larger datasets but still aim for 1 output.

Will i need to type our a all the individual weighting equations and such?

Sorry if its not clear.

Cheers,
Chris
Reply


Messages In This Thread
Developing larger Neural Networks - by Chriskelm - Nov-02-2018, 12:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Programming neural networks with Python Kwauka 2 1,176 Jun-15-2024, 02:05 PM
Last Post: jefsummers
Star [HELP] The Application of Deep Neural Networks MistyhV1 0 924 May-05-2024, 02:22 PM
Last Post: MistyhV1
  Compare two lists. Count larger values dervast 2 4,209 Dec-11-2019, 11:39 AM
Last Post: perfringo
  Centralities for Weighted Networks fishbacp 0 2,312 Oct-15-2018, 11:20 PM
Last Post: fishbacp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020