Jensen-holm commited on
Commit
ffc3a3a
·
1 Parent(s): 592a0f1

fixing train test split issue with iris dataset

Browse files
Files changed (2) hide show
  1. dataset/iris.py +3 -16
  2. neural_network/main.py +10 -5
dataset/iris.py CHANGED
@@ -1,6 +1,5 @@
1
  from sklearn.datasets import load_iris
2
  from sklearn.preprocessing import OneHotEncoder, StandardScaler
3
- from sklearn.model_selection import train_test_split
4
  import numpy as np
5
 
6
 
@@ -11,19 +10,7 @@ def iris() -> tuple[np.array]:
11
  after being normalized and one-hot encoded
12
  """
13
  iris = load_iris()
14
- X_train, X_test, y_train, y_test = train_test_split(
15
- iris.data,
16
- iris.target,
17
- test_size=0.3,
18
- random_state=8675309,
19
- )
20
  scaler = StandardScaler()
21
- X_train, X_test = scaler.fit_transform(
22
- X_train
23
- ), scaler.fit_transform(
24
- X_test
25
- )
26
-
27
- y_train = OneHotEncoder().fit_transform(y_train.reshape(-1, 1)).toarray()
28
- y_test = OneHotEncoder().fit_transform(y_test.reshape(-1, 1)).toarray()
29
- return X_train, X_test, y_train, y_test
 
1
  from sklearn.datasets import load_iris
2
  from sklearn.preprocessing import OneHotEncoder, StandardScaler
 
3
  import numpy as np
4
 
5
 
 
10
  after being normalized and one-hot encoded
11
  """
12
  iris = load_iris()
 
 
 
 
 
 
13
  scaler = StandardScaler()
14
+ x = scaler.fit_transform(iris.data)
15
+ y = OneHotEncoder().fit_transform(iris.target.reshape(-1, 1)).toarray()
16
+ return x, y
 
 
 
 
 
 
neural_network/main.py CHANGED
@@ -22,16 +22,21 @@ def init(
22
 
23
 
24
  def main(
25
- X_train: np.array,
26
- y_train: np.array,
27
- X_test: np.array,
28
- y_test: np.array,
29
  args,
30
  ) -> None:
31
- wb = init(X_train, args["hidden_size"])
32
  act = activation[args["activation_func"]]
33
  args["activation_func"] = act["main"]
34
  args["func_prime"] = act["prime"]
 
 
 
 
 
 
 
35
  model = bp(X_train, y_train, wb, args)
36
 
37
  # evaluate the model and return final results
 
22
 
23
 
24
  def main(
25
+ X: np.array,
26
+ y: np.array,
 
 
27
  args,
28
  ) -> None:
29
+ wb = init(X, args["hidden_size"])
30
  act = activation[args["activation_func"]]
31
  args["activation_func"] = act["main"]
32
  args["func_prime"] = act["prime"]
33
+ X_train, X_test, y_train, y_test = train_test_split(
34
+ X,
35
+ y,
36
+ test_size=0.2,
37
+ random_state=8675309,
38
+ )
39
+
40
  model = bp(X_train, y_train, wb, args)
41
 
42
  # evaluate the model and return final results