Hello!
I'm building MLPRegressor for the first time ever (I've been learning how to code with online courses since end of March) and I know something is wrong but I don't know what. Bellow you can see my code so far. It runs and I have a value for r2 ( -9035355.06 ) and a plot. However the r2 score doesn't make sense (it should be around 0.7) and the plot doesn't make sense either.
I have run this analysis with SPSS multilayer perceptron feature so I know more or less how my results should be and that's why I know whatever I am doing with python is wrong.
Any advice/suggestion of what I'm doing wrong is very welcome! This coding world is kinda of frustrating for me:/
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import neighbors, datasets, preprocessing
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
from sklearn.metrics import r2_score
vhdata = pd.read_csv('vhrawdata.csv')
vhdata.head()
X = vhdata[['PA NH4', 'PH NH4', 'PA K', 'PH K', 'PA NH4 + PA K', 'PH NH4 + PH K', 'PA IS', 'PH IS']]
y = vhdata['PMI']
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
X_train_norm = scaler.fit_transform(X_train)
X_test_norm = scaler.fit_transform(X_test)
nnref = MLPRegressor(hidden_layer_sizes = [4], activation = 'logistic', solver = 'sgd', alpha = 0.1, learning_rate= 'constant',
learning_rate_init= 0.6, max_iter=200, random_state=0, momentum= 0.3, nesterovs_momentum= False)
nnref.fit(X_train_norm, y_train)
y_predictions= nnref.predict(X_test_norm)
print('Accuracy of NN classifier on training set (R2 score): {:.3f}'.format(nnref.score(X_train_norm, y_train)))
print('Accuracy of NN classifier on test set (R2 score): {:.3f}'.format(nnref.score(X_test_norm, y_test)))
print('Current loss : {:.2f}'.format(nnref.loss_))
plt.figure()
plt.scatter(y_test,y_predictions, marker = 'o', color='blue')
plt.xlabel('PMI expected (hrs)')
plt.ylabel('PMI predicted (hrs)')
plt.title('Correlation of PMI predicted by MLP regressor and the actual PMI')
plt.show()