0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import preprocessing
data = pd.read_csv('Boston.csv')
X1 = data.iloc[:,1:5]
X2 = data.iloc[:,6:14]
X = pd.concat([X1,X2],axis=1)
y = pd.DataFrame(data.iloc[:,14])

'''
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X = sc_X.fit_transform(X)
'''
#X = (X - X.mean(axis=0)) / X.std(axis=0)
X = preprocessing.normalize(X)

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.1)

import keras
from keras.models import Sequential
from keras.layers import Dense

# Initialising the ANN
classifier = Sequential()

classifier.add(Dense(output_dim = 512, init = 'normal', activation = 'relu', input_dim = 12))
classifier.add(Dense(output_dim = 128, init = 'normal', activation = 'relu'))
classifier.add(Dense(output_dim = 1, init = 'normal', activation = 'relu'))

classifier.compile(optimizer = 'adam', loss = 'mse', metrics = ['accuracy'])

classifier.fit(X_train, y_train, batch_size = 10, nb_epoch = 100)

I have tried data preprocessing and adding more layers/neurons but still i'm getting accuracy below 2%.what is wrong with my code. I Have tried diffrent methods for preprocessing like standard scaler, normalization etc. I have also tried many activation functions like relu, linear, sigmoid. This is my first time developing a neural network so sorry the messy code...

EDIT: Dataset used is boston housing dataset. https://www.cs.toronto.edu/~delve/data/boston/bostonDetail.html

desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

1

You are in a regression setting, where accuracy is meaningless (it is meaningful only for classification settings). In such settings, the MSE itself is the performance metric (apart from being also the loss) - see own answer (and discussion) in What function defines accuracy in Keras when the loss is mean squared error (MSE)?.

For the same reason, you should not use activation = 'relu' for your final layer - in regression settings we use activation = 'linear' (or we leave it empty, since this is the default activation used in Keras when nothing is specified).

desertnaut
  • 57,590
  • 26
  • 140
  • 166