0% found this document useful (0 votes)
61 views8 pages

Assignment NeuralNetwork

The document describes building neural network models to predict profit and burned forest area. It discusses importing datasets, preprocessing data like normalization and converting variables to numeric, splitting data into training and test sets, defining and training neural network models with Keras, and evaluating model performance by measuring correlation between predicted and actual values. A more complex model with multiple hidden layers showed improved performance for predicting forest fire burned area.

Uploaded by

Sandhya Kuppala
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)
61 views8 pages

Assignment NeuralNetwork

The document describes building neural network models to predict profit and burned forest area. It discusses importing datasets, preprocessing data like normalization and converting variables to numeric, splitting data into training and test sets, defining and training neural network models with Keras, and evaluating model performance by measuring correlation between predicted and actual values. A more complex model with multiple hidden layers showed improved performance for predicting forest fire burned area.

Uploaded by

Sandhya Kuppala
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/ 8

Dexler Christewart Padan - Data Science_170922

Neural Network

Assignment_NeuralNetwork_50_Startups

Build a Neural Network model for 50_startups data to predict profit.

Import dataset from excel:

*State: Shall convert in numerical data by using library(plyr):


startups$State <- as.numeric(revalue(startups$State, c("New York"="0",
"California"="1","Florida"="2")))

str(startups)
Dexler Christewart Padan - Data Science_170922
Neural Network

Custom the function of normalization:


normalize <- function(x) {
return((x - min(x)) / (max(x) - min(x)))
}

Apply normalization function to entire data:

summary(startups_norm):

Creating train data and test data:


startups_train <- startups_norm[1:35, ]
startups_test <- startups_norm[36:50, ]

Test data = 30%, Train data = 70%


Dexler Christewart Padan - Data Science_170922
Neural Network

Train the neuralnet model:


install.packages("neuralnet")
library(neuralnet)

ANN with only a single hidden neuron:


Startups_model <- neuralnet(Profit~R.D.Spend+Administration
+Marketing.Spend+State,data = startups_train)

Visualize the Network Topology:


Dexler Christewart Padan - Data Science_170922
Neural Network
Evaluating model performance
> model_results <- compute(Startups_model, startups_test[1:5])
> View(model_results)

Obtain predicted strength values:


predicted_Profit <- model_results$net.result

Examine the correlation between predicted and actual values:


cor(predicted_Profit, startups_test$Profit)
[,1]
[1,] 0.7987082

Improving model performance.


A more complex neural network topology with 5 hidden neurons:
Startups_model2 <- neuralnet(Profit~R.D.Spend+Administration
+Marketing.Spend+State,data = startups_train,
hidden = 2)
Dexler Christewart Padan - Data Science_170922
Neural Network

plot the network:


plot(Startups_model2)

Evaluate the results:


model_results2 <- compute(Startups_model2, startups_test[1:5])
predicted_Profit2 <- model_results2$net.result
cor(predicted_Profit2, startups_test$Profit)
[,1]
[1,] 0.8357094
Dexler Christewart Padan - Data Science_170922
Neural Network

Assignment_NeuralNetwork_Forest Fires

Predict the Burned Area due to Forest Fires using Neural Network model

import numpy as np
import pandas as pd

from keras.models import Sequential


from keras.layers import Dense

forest = pd.read_csv("C:/Users/Administrator/Desktop/forestfires.csv")

forest.head()

Change month and day as numerical data:


forest.month.replace(('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'),(1,2,3,4,5,6,7,8
,9,10,11,12), inplace=True)
forest.day.replace(('mon','tue','wed','thu','fri','sat','sun'),(1,2,3,4,5,6,7), inplace=True)
Dexler Christewart Padan - Data Science_170922
Neural Network

Drop/delete irrelevant columns:


*F1 as a new file = “Forest 1”
F1= forest.drop(forest.iloc[:,11:31], axis=1)

F1.describe()

from sklearn.model_selection import train_test_split


X = F1
Y = F1["area"]
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.25)

cont_model = Sequential()
cont_model.add(Dense(50, input_dim=8, activation="relu"))
cont_model.add(Dense(250, activation="relu"))
cont_model.add(Dense(1, kernel_initializer="normal"))
cont_model.compile(loss="mean_squared_error", optimizer = "adam", metrics = ["mse"])
Dexler Christewart Padan - Data Science_170922
Neural Network
model = cont_model
model.fit(np.array(X_train), np.array(y_train), epochs=20)

import matplotlib.pyplot as plt


plt.hist((F1.area))

F1.plot(kind='density', subplots=True, layout=(4,4), sharex=False, sharey=False)

You might also like