-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartificial_neural_network.py
68 lines (41 loc) · 1.53 KB
/
artificial_neural_network.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
# -*- 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
tf.__version__
"""## Part 1 - Data Preprocessing
### Importing the dataset
"""
dataset = pd.read_excel('Folds5x2_pp.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)
"""## 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))
"""## Part 3 - Training the ANN
### Compiling the ANN
"""
ann.compile(optimizer = 'adam', loss = 'mean_squared_error')
"""### Training the ANN model on the Training set"""
ann.fit(X_train, y_train, batch_size = 32, epochs = 100)
"""### Predicting the results of the Test set"""
y_pred = ann.predict(X_test)
np.set_printoptions(precision=2)
print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))