Skip to main content
added 349 characters in body; edited title
Source Link

Is it possible to predict non-classifiable label using single layer perceptron and sigmoid function? (without using any perceptron library)

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)

```

Is it possible to predict non-classifiable label using single layer perceptron? (without using any perceptron library)

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. I am really new to this.

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)

```

Is it possible to predict non-classifiable label using single layer perceptron and sigmoid function? (without using any perceptron library)

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)

```
added 24 characters in body
Source Link

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. I am really new to this.

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)

```

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.

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)

```

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. I am really new to this.

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)

```
Source Link

Is it possible to predict non-classifiable label using single layer perceptron? (without using any perceptron library)

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.

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)

```