Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Vedant@11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

11

April 15, 2024

[2]: #How to train a neural network with Tensorflow / Pytorch and evaluation of␣
↪logistic

#regression using tensorflow

import tensorflow as tf
import numpy as np

from keras.models import Sequential


from keras.layers import Dense, Flatten
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_breast_cancer

2024-04-15 08:23:30.956156: I external/local_tsl/tsl/cuda/cudart_stub.cc:32]


Could not find cuda drivers on your machine, GPU will not be used.
2024-04-15 08:23:31.623215: I external/local_tsl/tsl/cuda/cudart_stub.cc:32]
Could not find cuda drivers on your machine, GPU will not be used.
2024-04-15 08:23:32.012440: I tensorflow/core/platform/cpu_feature_guard.cc:210]
This TensorFlow binary is optimized to use available CPU instructions in
performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild
TensorFlow with the appropriate compiler flags.
2024-04-15 08:23:34.290430: W
tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not
find TensorRT

[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)

print("Test Loss: ",test_loss)


print("accuracy is",test_accuracy)

/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

You might also like