Deep Learning With Python File
Deep Learning With Python File
COMMUNICATION TECHNOLOGY
import numpy as np
class Perceptron:
def __init__(self, learning_rate=0.01, epochs=100):
self.learning_rate = learning_rate
self.epochs = epochs
self.weights = None
self.bias = None
# Example usage:
# Binary OR problem
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y = np.array([0, 1, 1, 1])
# Test predictions
test_data = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
for data_point in test_data:
prediction = perceptron.predict(data_point)
print(f"Input: {data_point}, Predicted Output: {prediction}")
2
Output :
3
2. To write a program to implement AND OR gates using Perceptron
import numpy as np
class Perceptron:
def __init__(self, input_size, learning_rate=0.01, epochs=100):
self.learning_rate = learning_rate
self.epochs = epochs
self.weights = np.zeros(input_size)
self.bias = 0
# AND gate
X_and = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_and = np.array([0, 0, 0, 1])
# OR gate
X_or = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_or = np.array([0, 1, 1, 1])
Output:
5
3. To implement Crab Classification using Pattern Net
# Standardize features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
print(f"Accuracy: {accuracy:.2f}")
print("Classification Report:")
print(classification_rep)
Output:
6
4. To write a program to implement Wine Classification using Backpropagation
# Standardize features
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
print(f"Accuracy: {accuracy:.2f}")
print("Classification Report:")
print(classification_rep)
Output:
7
5. To write a MatLab Script containing four functions Addition, Subtraction,
Multiply, and Divide functions
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.linear_model import Perceptron
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
# Data preprocessing
scaler = MinMaxScaler(feature_range=(-1, 1))
sinusoid_scaled = scaler.fit_transform(sinusoid.reshape(-1, 1))
sequence_length = 10
X, y = create_sequences(sinusoid_scaled, sequence_length)
# Make predictions
train_predict = model.predict(X_train)
test_predict = model.predict(X_test)
# Visualize predictions
plt.plot(time[:train_size], y_train_inverse, label='Actual (Train)')
plt.plot(time[train_size:], y_test_inverse, label='Actual (Test)')
plt.plot(time[sequence_length:train_size], train_predict_inverse,
label='Predicted (Train)')
plt.plot(time[train_size + sequence_length:], test_predict_inverse,
label='Predicted (Test)')
plt.title('LSTM Time Series Prediction')
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.legend()
plt.show()
13
Output:
14
8. To study Convolutional Neural Network and Recurrent Neural Network
import tensorflow as tf
from tensorflow.keras import layers, models
from tensorflow.keras.datasets import mnist
OUTPUT:
15
Recurrent Neural Network (RNN)
import tensorflow as tf
from tensorflow.keras import layers, models
import numpy as np
OUTPUT-
16
9. To study ImageNet, GoogleNet, ResNet convolutional Neural Networks
import tensorflow as tf
from tensorflow.keras.applications.vgg16 import VGG16, preprocess_input,
decode_predictions
from tensorflow.keras.preprocessing import image
import numpy as np
# Make predictions
predictions = model_vgg16.predict(img_array)
Output:
17
GoogleNet (Inception)
import tensorflow as tf
from tensorflow.keras.applications.inception_v3 import InceptionV3,
preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image
import numpy as np
# Make predictions
predictions = model_inceptionv3.predict(img_array)
Output:
18
ResNet (Residual Network Pre-trained ResNet50 Model)
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import ResNet50,
preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image
import numpy as np
# Make predictions
predictions = model_resnet50.predict(img_array)
Output:
19
10. To study the use of Long Short-Term Memory / Gated Recurrent Units to
predict the stock prices based on historic data.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense
Output: