Python Forum
Why is "weights" in the function header and loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is "weights" in the function header and loop
#1
# Define predict_with_network()
def predict_with_network(input_data_row, weights):

# Calculate node 0 value
node_0_input = (input_data_row * weights['node_0']).sum()
node_0_output = relu(node_0_input)

# Calculate node 1 value
node_1_input = (input_data_row * weights['node_1']).sum()
node_1_output = relu(node_1_input)

# Put node values into array: hidden_layer_outputs
hidden_layer_outputs = np.array([node_0_output, node_1_output])

# Calculate model output
input_to_final_layer = (hidden_layer_outputs * weights['output']).sum()
model_output = relu(input_to_final_layer)

# Return model output
return(model_output)


# Create empty list to store prediction results
results = []
for input_data_row in input_data:
# Append prediction to results
results.append(predict_with_network(input_data_row, weights))

# Print results
print(results)

# -*- coding: utf-8 -*-
"""
Created on Mon Jul 16 13:21:15 2018

@author: Paul
"""

def predict_with_network(input_data):
# Calculate node 0 in the first hidden layer
node_0_0_input = (input_data * weights['node_0_0']).sum()
node_0_0_output = relu(node_0_0_input)

# Calculate node 1 in the first hidden layer
node_0_1_input = (input_data * weights['node_0_1']).sum()
node_0_1_output = relu(node_0_1_input)

# Put node values into array: hidden_0_outputs
hidden_0_outputs = np.array([node_0_0_output, node_0_1_output])

# Calculate node 0 in the second hidden layer
node_1_0_input = (hidden_0_outputs * weights['node_1_0']).sum()
node_1_0_output = relu(node_1_0_input)

# Calculate node 1 in the second hidden layer
node_1_1_input = (hidden_0_outputs * weights['node_1_1']).sum()
node_1_1_output = relu(node_1_1_input)

# Put node values into array: hidden_1_outputs
hidden_1_outputs = np.array([node_1_0_output, node_1_1_output])

# Calculate model output: model_output
model_output = (hidden_1_outputs * weights['output']).sum()

# Return model_output
return(model_output)

output = predict_with_network(input_data)
print(output)

why is the "weights" array set as a param in the function header and in the function call in the loop body, while in the other script its not in the function header yet it is still accessible in the function body ?
Reply
#2
Please post the python code, output and errors using the specific tags.
Reply
#3
For instructions on how to do what gontajones wisely suggests, see the BBCode link in my signature.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Exit Function - loop Tetsuo30 2 2,066 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  Using Function in a For loop vp1989 5 2,812 May-19-2020, 03:53 PM
Last Post: vp1989
  Sample weights using XGBClassifier MagnusOlsen 0 2,644 Apr-16-2018, 07:19 PM
Last Post: MagnusOlsen

Forum Jump:

User Panel Messages

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