Vedant@11
Vedant@11
Vedant@11
[2]: #How to train a neural network with Tensorflow / Pytorch and evaluation of␣
↪logistic
import tensorflow as tf
import numpy as np
[3]: df=load_breast_cancer()
# two classifications -- malignant / benign
X_train,X_test,y_train,y_test=train_test_split(df.data,df.target,test_size=0.
↪20,random_state=42)
sc=StandardScaler()
X_train=sc.fit_transform(X_train)
X_test=sc.transform(X_test)
model=Sequential([
1
Flatten(input_shape=(X_train.shape[1],)),
Dense(1,activation='sigmoid')
])
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
model.fit(X_train,y_train,epochs=5)
test_loss,test_accuracy = model.evaluate(X_test,y_test)
/home/codespace/.python/current/lib/python3.10/site-
packages/keras/src/layers/reshaping/flatten.py:37: UserWarning: Do not pass an
`input_shape`/`input_dim` argument to a layer. When using Sequential models,
prefer using an `Input(shape)` object as the first layer in the model instead.
super().__init__(**kwargs)
Epoch 1/5
15/15 �������������������� 1s 1ms/step -
accuracy: 0.2533 - loss: 1.1562
Epoch 2/5
15/15 �������������������� 0s 1ms/step -
accuracy: 0.2794 - loss: 0.9930
Epoch 3/5
15/15 �������������������� 0s 791us/step -
accuracy: 0.3805 - loss: 0.8562
Epoch 4/5
15/15 �������������������� 0s 860us/step -
accuracy: 0.4316 - loss: 0.7761
Epoch 5/5
15/15 �������������������� 0s 805us/step -
accuracy: 0.5924 - loss: 0.6963
4/4 �������������������� 0s 2ms/step -
accuracy: 0.6548 - loss: 0.5986
Test Loss: 0.6006454825401306
accuracy is 0.6578947305679321