Skip to content

Commit 3cc978f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 750e7da commit 3cc978f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

neural_network/Radial_Basis_Function_Neural_Networks.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from sklearn.model_selection import train_test_split
2222
from sklearn.metrics import accuracy_score
2323

24+
2425
class RBFNN:
2526
def __init__(self, num_centers, gamma):
2627
# Initialize with number of RBF centers and spread parameter (gamma)
@@ -31,8 +32,8 @@ def __init__(self, num_centers, gamma):
3132

3233
def _rbf(self, X, centers):
3334
# Compute Gaussian RBF activations for inputs X given the centers
34-
dist = cdist(X, centers, 'euclidean') # Compute Euclidean distance to centers
35-
return np.exp(-self.gamma * (dist ** 2)) # Apply Gaussian function
35+
dist = cdist(X, centers, "euclidean") # Compute Euclidean distance to centers
36+
return np.exp(-self.gamma * (dist**2)) # Apply Gaussian function
3637

3738
def train(self, x_data, y_data):
3839
# Train the RBFNN
@@ -51,6 +52,7 @@ def predict(self, x):
5152
rbf_activations = self._rbf(x, self.centers)
5253
return rbf_activations.dot(self.weights)
5354

55+
5456
if __name__ == "__main__":
5557
# Load and preprocess Iris dataset
5658
iris = load_iris()
@@ -66,7 +68,9 @@ def predict(self, x):
6668
y_encoded = encoder.fit_transform(y)
6769

6870
# Split data into training and testing sets
69-
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y_encoded, test_size=0.2, random_state=42)
71+
X_train, X_test, y_train, y_test = train_test_split(
72+
X_scaled, y_encoded, test_size=0.2, random_state=42
73+
)
7074

7175
# Initialize and train the RBF Neural Network
7276
rbfnn = RBFNN(num_centers=10, gamma=1.0)

0 commit comments

Comments
 (0)