Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Profiling
#1
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!
Reply
#2
Welcome to the forum. Can you please show what have you tried?
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#3
(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.
Reply
#4
Will anyone help me in this forum??
Reply
#5
(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?
Reply
#6
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
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Forum Jump:

User Panel Messages

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