<jupyter_start><jupyter_text>Neural network models<jupyter_code>from sklearn.neural_network import MLPRegressor

mlp =  MLPRegressor(hidden_layer_sizes=(5, 18),
                    tol=0.01,
                    max_iter=200,
                    random_state=0,
                    alpha=0.1)

mlp.fit(X_train, y_train)

mlp.score(X_test, y_test)
from sklearn.neural_network import MLPRegressor
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()

X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

mlp =  MLPRegressor(hidden_layer_sizes=(9, 17),
                    tol=0.005,
                    max_iter=200,
                    random_state=0,
                    alpha=0.01)

mlp.fit(X_train_scaled, y_train)

mlp.score(X_test_scaled, y_test)
from sklearn import metrics

pred = mlp.predict(X_test)

print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, pred))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, pred))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, pred)))
learning_rate_inits = np.arange(0.005, 0.015, 0.0001)
results = []

for feature in learning_rate_inits:
    rf = MLPRegressor(hidden_layer_sizes=(9, 17), tol=feature, max_iter=200, random_state=0)
    rf.fit(X_train_scaled, y_train)
        
    results.append(rf.score(X_test_scaled, y_test))

fig, ax = plt.subplots(figsize=(17,8)) 

plt.plot(learning_rate_inits, results, 'b')

ax.set_axisbelow(True)
ax.minorticks_on()
ax.grid(which='major', linestyle='-', linewidth=0.5, color='black',)
ax.grid(which='minor', linestyle=':', linewidth=0.5, color='black', alpha=0.7)

plt.gca().xaxis.set_major_locator(plt.MultipleLocator(0.01))
print(results[results.index(max(results))])
print(learning_rate_inits[results.index(max(results))])
results = []
layers=[]

for j in range(1,30,1):
    for i in range(1,30,1):
        nnm = MLPRegressor(random_state=0, hidden_layer_sizes=(j, i), tol=0.01, max_iter=200, alpha=0.1)
        nnm.fit(X_train_scaled, y_train)

        results.append(nnm.score(X_test_scaled, y_test))
        layers.append("("+str(j)+", "+str(i)+")")
print(max(results))
print(results.index(max(results)))
print(results[results.index(max(results))])

print(layers[results.index(max(results))])<jupyter_output>0.7142827833844141
248
0.7142827833844141
(9, 17)
{'fraction_non_alphanumeric': 0.1419491525423729, 'fraction_numerical': 0.048728813559322036, 'mean_word_length': 4.390410958904109, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '238427', 'license': 'MIT', 'n_tokens_mistral': 982, 'n_tokens_neox': 891, 'n_words': 134, 'path': 'Neural Networks/Multi-layer Perceptron.ipynb', 'repo_name': 'vislupus/machine-learning', 'size': '2360'}