0% found this document useful (0 votes)
9 views4 pages

Ann Code For The Problem

Ml
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Ann Code For The Problem

Ml
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ANN CODE FOR THE PROBLEM

# Importing the libraries

import tensorflow as tf

from tensorflow import keras

from tensorflow.keras import optimizers

from tensorflow.keras.optimizers import schedules

import numpy as np

import pandas as pd

import time

import matplotlib.pyplot as plt

import pylab

tf.__version__

start = time.time() # to calculate the training time.

# Part 1 - Data Preprocessing

# Importing the dataset

dataset = pd.read_excel('ANN10000.xlsx')

X = dataset.iloc[1:10000,0:2].values

y = dataset.iloc[1:10000,2:3].values

print(X)

print(y)

# Splitting the dataset into the Training set and Test set

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.015, random_state = 1)

# Feature Scaling

from sklearn.preprocessing import StandardScaler

sc = StandardScaler()

X_train[:,0:2] = sc.fit_transform(X_train[:,0:2])

X_test[:,0:2] = sc.transform(X_test[:,0:2])
# Part 2 - Building the ANN

# Initializing the ANN

ann = tf.keras.models.Sequential()

# Adding the input layer and the first hidden layer

ann.add(tf.keras.layers.Dense(units=6, activation='tanh'))

# Adding the second hidden layer

ann.add(tf.keras.layers.Dense(units=6, activation='relu'))

# Adding the third hidden layer

ann.add(tf.keras.layers.Dense(units=6, activation='relu'))

# Adding the fourth hidden layer

ann.add(tf.keras.layers.Dense(units=6, activation='relu'))

# Adding the fifth hidden layer

ann.add(tf.keras.layers.Dense(units=6, activation='relu'))

# Adding the output layer

ann.add(tf.keras.layers.Dense(units=1, activation='relu'))

# Part 3 - Training the ANN

# learning rate scheduling (optional)

# lr_schedule = keras.optimizers.schedules.ExponentialDecay(

# initial_learning_rate=1e-2,

# decay_steps=10000,
# decay_rate=0.9)

# Compiling the ANN

ann.compile(optimizer = 'adamax', loss = 'mse', metrics=[tf.keras.metrics.MeanAbsoluteError()])

# Training the ANN on the Training set

history=ann.fit(X_train, y_train, batch_size = 32, epochs = 100000)

end = time.time() # end of training time

print(end - start)

# Part 4 - Making the predictions and evaluating the model

# Predicting the Test set results

y_pred = ann.predict(X_test)

# Checking result accuracy

from sklearn.metrics import explained_variance_score,mean_absolute_error,max_error

mape = tf.keras.losses.MeanAbsolutePercentageError()

mape(y_test, y_pred).numpy()

max_error(y_test, y_pred)

explained_variance_score(y_test, y_pred)

r2_score(y_test, y_pred)

# plotting predicted as well as real values

%matplotlib inline
e=np.arange(1,151,1)

e=e.reshape(150,1)

plt.plot(e,y_test, label='test')

plt.plot(e,y_pred, label='pred')

plt.title('predictions')

plt.show()

# preinting predicted and real friction factor array (150 values each)

y_pred

y_test

# saving these arrays to an excel file

dft = pd.DataFrame(data=y_test)

dfp = pd.DataFrame(data=y_pred)

dft.to_excel("70t.xlsx")

dfp.to_excel("70p.xlsx")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy