0
$\begingroup$

Imagine predicting BMI index like 1,2,3,4,5 and having weight and height as input. I know it can be easily done with other method. Also I have to use sigmoid function and I am really new to this. I can't seem to find the solution to this question.

As much as I know so far, perceptron is only linearly separable and sigmoid function gives value between 0 and 1. I can't figure out the way to classify the index value 1,2,3,4,5 which are BMI index.

  • No perceptron or any library except numpy and pandas
  • Use only sigmoid function.
import pandas as pd
import numpy as np


df = pd.read_csv('bmi.csv')


X = df[['Height', 'Weight']].values
y = df['Index'].values / 5.0  # Normalize targets

#
X = (X - np.mean(X, axis=0)) / np.std(X, axis=0)

X = np.c_[X, np.ones(X.shape[0])]


np.random.seed(42)
weights = np.random.uniform(low=-0.5, high=0.5, size=X.shape[1])

learning_rate = 0.1

num_iterations = 10000

for _ in range(num_iterations):
    for i in range(X.shape[0]):
        # Forward pass
        weighted_sum = np.dot(X[i], weights)
        output = weighted_sum 
        error = y[i] - output

        weights += learning_rate * error * X[i]

test_input = np.array([174, 96])
test_input = (test_input - np.mean(X[:, :2], axis=0)) / np.std(X[:, :2], axis=0)
test_input = np.append(test_input, 1)

predicted_output = np.dot(test_input, weights)
predicted_bmi = predicted_output * 5.0

print("Predicted BMI:", predicted_bmi)

```
$\endgroup$
2
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Commented Dec 14, 2023 at 14:01
  • 1
    $\begingroup$ As it is posed, it sounds very much like a self-study question. In that case you should add the corresponding tag. $\endgroup$
    – Igor F.
    Commented Dec 14, 2023 at 18:54

1 Answer 1

0
$\begingroup$

I would suggest that after calculating the weighted sum, you might wanna pass it through the sigmoid function to get the final output. Also by experimenting with differnt learning rates you can find a value that would converge well. This might give you better results. In addition to this, I would like to add on that a single layer perceptron with a sigmoid activation may not be as effective as its multilayered counter parts in capturing the non linear relationships in BMI prediction. For a better performance I would suggest that you could try making a much more complex model for an improved performance and accuracy.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.