User Database — This dataset contains information about users from a company database. Contains information about user ID, gender, age, estimated salary, purchase. We use this dataset to predict whether a user will purchase a new company product or not.
Data — User_Data
Let’s create a logistic regression model that predicts whether a user will buy a product or not.
Input libraries
|
Loading dataset — User_Data
|
Now, to predict whether a user will purchase a product or not, we need to figure out the relationship between age and estimated salary. Here, user ID and gender are not important factors to figure this out.
|
Splitting the dataset for training and testing. 75% of the data is used to train the model, and 25% is — to test the performance of our model.
|
Now it is very important to scale the features here because the age and estimated salary values are in different ranges. If we are not scaling objects, then the Estimated Wages function will dominate the Age function when the model finds the nearest neighbor to the data point in the data space.
|
Output:
[[0.58164944 -0.88670699] [-0.60673761 1.46173768] [-0.01254409 -0.5677824] [-0.60673761 1.89663484] [1.37390747 -1.40858358] [1.47293972 0.99784738] [0.08648817 -0.79972756] [-0.01254409 -0.24885782] [-0.21060859 -0.5677824] [-0.21060859 -0.19087153p] Herethe estimated wages are sacred, and now they are in the range from -1 to 1. Therefore, each feature will equally contribute to decision making, ie
Finally, we train our logistic regression model.
< code class = "plain"> classifier |
After training the model, it’s time to use it to predict data testing.
|
Let’s check the performance our model — Confusion Matrix
|
Output:
Confusion Matrix: [[65 3] [8 24]]
Out of 100:
TruePostive + TrueNegative = 65 + 24
FalsePositive + FalseNegative = 3 + 8
Performance Indicator — precision
|
Output:
Accuracy: 0.89
Visualization of the performance of our model.
|
Output:

Analyzing performance metrics — accuracy and confusion matrix and graph, we can clearly say that our model is performing really well.