User Profiling - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: User Profiling (/thread-26457.html) |
User Profiling - akis - May-02-2020 Hello to all of you, I 've created a (fake, for educational reasons only on user profiling), online store. My store tracks the "movements-clicks" of visitors and based on these clicks my system predicts if the user is a man, woman, or if he-she is a parent. My online store sells athletic accessories. If a user enters the "male" section more often then "probably" he is a man. If the user enters the female section then "probably" she is a woman. The same way, if the user is entering the kids section, then my tracking system is guessing that this user might be a parent. My tracking system also saves info about the sports that my users like, how often they login to my site, how much money they've spent etc. I have records in my database for more than 100 users. Some of this tracking can be seen in the following table. [Image: DATA.jpg] So as an example my tracking system for user with ID 3 predicts that: man: 0.0000 % Woman: 100.0000 % No child. For ID 17 predicts that: Man: 21.0526 % Woman: 78.9474 % No child. For ID 31 predicts that: Man: 0 % Woman: 0 % Parent. For ID 38 predicts that: Man: 37.5000 % Woman: 62.5000 % Parent. etc How could I use Python and neural networks to predict any new user coming to my site? The rules that I have to use are: If man >= 1 , woman = 0, child = 0 Then he is male, no parent man >= 1 , woman = 0, child >= 1 Then he is male, parent man = 0 , woman >=1 , child = 0 Then she is female, no parent man = 0 , woman >=1 , child >= 1 Then she is female, parent man = 0 , woman = 0 , child >= 1 parent If man = woman then nothing can be said, ie if the user have entered 5 times in the male's section and 5 in the female's one, then we cannot predict anything on his/her sex. Any ideas? Thank you all! RE: User Profiling - pyzyx3qwerty - May-02-2020 Welcome to the forum. Can you please show what have you tried? RE: User Profiling - akis - May-02-2020 (May-02-2020, 10:27 AM)pyzyx3qwerty Wrote: Welcome to the forum. Can you please show what have you tried? My first approach: import numpy as np class NeuralNetwork(): def __init__(self): # seeding for random number generation np.random.seed(1) #converting weights to a 3 by 1 matrix with values from -1 to 1 and mean of 0 self.synaptic_weights = 2 * np.random.random((3, 1)) - 1 def sigmoid(self, x): #applying the sigmoid function return 1 / (1 + np.exp(-x)) def sigmoid_derivative(self, x): #computing derivative to the Sigmoid function return x * (1 - x) def train(self, training_inputs, training_outputs, training_iterations): #training the model to make accurate predictions while adjusting weights continually for iteration in range(training_iterations): #siphon the training data via the neuron output = self.think(training_inputs) #computing error rate for back-propagation error = training_outputs - output #performing weight adjustments adjustments = np.dot(training_inputs.T, error * self.sigmoid_derivative(output)) self.synaptic_weights += adjustments def think(self, inputs): #passing the inputs via the neuron to get output #converting values to floats inputs = inputs.astype(float) output = self.sigmoid(np.dot(inputs, self.synaptic_weights)) return output if __name__ == "__main__": #initializing the neuron class neural_network = NeuralNetwork() print("Beginning Randomly Generated Weights: ") print(neural_network.synaptic_weights) #training data consisting of 5 examples--3 input values and 1 output training_inputs = np.array([[1,0,0],#man [1,0,1],#man_Parent [0,1,0],#woman [0,1,1],#woman_Parent [0,0,1],])#Parent training_outputs = np.array([[1,1,1,1,1]]).T #hellpppp me here!!I cannot write "male", "male_Parent", etc here... #training taking place neural_network.train(training_inputs, training_outputs, 15000) print("Ending Weights After Training: ") print(neural_network.synaptic_weights) user_input_one = str(input("User Input One: ")) user_input_two = str(input("User Input Two: ")) user_input_three = str(input("User Input Three: ")) print("Considering New Situation: ", user_input_one, user_input_two, user_input_three) print("New Output data: ") print(neural_network.think(np.array([user_input_one, user_input_two, user_input_three])))I want it to display a right message at the end based on the case, like Male no Parent, or Female Parent etc. RE: User Profiling - akis - May-03-2020 Will anyone help me in this forum?? RE: User Profiling - akis - May-04-2020 (May-02-2020, 10:27 AM)pyzyx3qwerty Wrote: Welcome to the forum. Can you please show what have you tried? I replied to you, will you reply to me? RE: User Profiling - pyzyx3qwerty - May-04-2020 Sorry for the late response. Is it working properly and as required? If not,Can you show what exactly is the error ,so i'll probably be able to find the mistake |