-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prediction electrode by ANN.py
81 lines (48 loc) · 1.96 KB
/
Prediction electrode by ANN.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
"""Artificial Neural Network
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1eje9zILprgVmohMN7cKykI3fn4FBRPnF
# Artificial Neural Network
### Importing the libraries
"""
import numpy as np
import pandas as pd
import tensorflow as tf
import matplotlib.pyplot as plt
tf.__version__
"""## Part 1 - Data Preprocessing
### Importing the dataset 'electrode composition of slurry'
"""
dataset = pd.read_excel('mixed.xlsx')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, -1].values
"""### 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.2, random_state = 0)
"""Feature Scaling"""
from sklearn.preprocessing import StandardScaler
sc= StandardScaler()
X_train=sc.fit_transform(X_train)
X_test= sc.transform(X_test)
"""## 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='relu'))
"""### Adding the second 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='sigmoid'))
"""## Part 3 - Training the ANN
### Compiling the ANN
"""
ann.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = 'accuracy')
"""### Training the ANN model on the Training set"""
ann.fit(X_train, y_train, batch_size = 32, epochs = 200)
"""### Predicting the results of the Test set 'Prediciting electrode slurry, where 0:anode & 1:cathode'"""
print(ann.predict(sc.transform([[55,3.8,2.3,35.7]])))
"""**which means that this slurry composition tends to be as Cathode eletrode**"""
print(ann.predict(sc.transform([[50.7,0.54,2.7,46]])))
"""**which means that this slurry composition tends to be as anode eletrode**"""