I have a script which I wrote using python and tflearn. I created a regression neural network model which takes in chemical analysis of wine as input and predicts a score out of 10.
The problem I have is that the prediction of my model is very bad. I'm also new to tflearn, I have only coded classification neural networks(twice). So, I'm a complete beginner in coding regression and in using tflearn.
import pandas as pd import numpy as np import tflearn from tflearn.layers.core import input_data, fully_connected, dropout from tflearn.layers.estimator import regression from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler import matplotlib.pyplot as plt def preprocess(): data_source_red = 'F:\Gautam\...\winequality-red.csv' data_source_white = 'F:\Gautam\...\winequality-white.csv' data_red = pd.read_csv(data_source_red, index_col=False, sep=';') data_white = pd.read_csv(data_source_white, index_col=False, sep=';') data = pd.concat([data_red, data_white]) data = data.dropna(inplace=False) x = data[data.columns[0:11]].values y = data[data.columns].values sc = StandardScaler() x = sc.fit_transform(x) y = np.expand_dims(y, -1) x = np.float32(x) y = np.float32(y) return (x, y) x, y = preprocess() train_x, test_x, train_y, test_y = train_test_split(x, y, test_size = 0.2) network = input_data(shape=[None, 11], name='Input_layer') network = fully_connected(network, 5, activation='relu', name='Hidden_layer_1') network = fully_connected(network, 1, activation='linear', name='Output_layer') network = regression(network, batch_size=64, optimizer='sgd', learning_rate=0.2, loss='mean_square', metric='R2') model = tflearn.DNN(network) model.fit(train_x, train_y, show_metric=True, run_id='wine_regression', validation_set=0.1, n_epoch=10) result = model.evaluate(test_x, test_y) print('Accuracy is %0.2f%%' % (result * 100)) pred_y = model.predict(test_x) plt.plot(test_y, color = 'red', label = 'Real data') plt.plot(pred_y, color = 'blue', label = 'Predicted data') plt.title('Prediction') plt.legend() plt.show()
Again, the prediction is very bad. Also, the loss and R2 values go hectic. Sometimes, the loss is low(6.45) and sometimes very high(23445.45). The same goes for R2 value too. Sometimes, R2 value goes above 1.0
Even if the loss is minimum(0.1) and R2 as 0.95, the graph shows that the actual value varies lot from the predicted values.
What mistake am I doing? Why is my prediction very bad? And why are the values R2 and loss too high sometimes and too low sometimes?
Am I missing something here? This is my first regression neural network, so I don't know much about this. I hope that my question is clear. Thanks.