<jupyter_start><jupyter_text><jupyter_code>import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt #for plotting
"""
x, y, coef = datasets.make_regression(n_samples=500,#number of samples
                                      n_features=1,#number of features
                                      n_informative=1,#number of useful features 
                                      noise=8,#bias and standard deviation of the guassian noise
                                      coef=True,#true coefficient used to generated the data
                                      random_state=4) #set for same data points for each run
print(coef)
# Scale feature x (years of experience) to range 0..20
x = np.interp(x, (x.min(), x.max()), (0, 20))
# Scale target y (salary) to range 2000000..15000000 
y = np.interp(y, (y.min(), y.max()), (2000000, 15000000))


"""
#Otros datos a hacer regresión
n_samples = 1000
rng = np.random.RandomState(0)
#x = rng.randn(n_samples, 1)
x = ((rng.rand(n_samples,1)-0.5)*3)
noise = rng.normal(loc=0.0, scale=0.3, size=n_samples)
y = (1.5 * x[:, 0] + 3*np.sin(2 * np.pi * x[:, 0]) - noise)


plt.figure()
plt.plot(x,y,'.')
plt.xlabel('Years of experience')
plt.ylabel('Salary $')
plt.title('Experience Vs. Salary All data')
plt.show()
print(x.shape)
print(y.shape)
from sklearn.preprocessing import StandardScaler,MinMaxScaler
from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(x, y,random_state=1)
"""
X_train=x_train
X_test=x_test
"""
scaler = StandardScaler()#StandardScaler, MinMaxScaler
scaler.fit(x_train)
X_train =scaler.transform(x_train)
X_test  = scaler.transform(x_test)

plt.figure()
plt.plot(X_train,y_train,'.',label='train data')
plt.xlabel('Years of experience')
plt.ylabel('Salary $')
plt.title('Experience Vs. Salary Train Data')
plt.show()
from sklearn.neural_network import MLPRegressor
regr = MLPRegressor(hidden_layer_sizes=(100,50),alpha=0.1,activation="relu",random_state=1,learning_rate='adaptive', max_iter=6000,solver="adam",verbose=True)
#regr = MLPRegressor(random_state=1, max_iter=500)

print(regr.fit(X_train, y_train))

#TAREA:
# investigar que es el R^2, como se analizan los resultados!!
# investigar que pasa si los datos no estan normalizados en su entrada "y en su salida. :'( "
# Disminuir el numero de datos con los que entrenan y ver que pasa!!! Concluir
print("R^2 entrenamiento",regr.score(X_train,y_train))
print("R^2 validacion",regr.score(X_test, y_test))
y_test_pred=regr.predict(X_test)
plt.figure()
plt.plot(X_test,y_test_pred,'.',label='Complete data')
plt.xlabel('Years of experience')
plt.ylabel('Salary $')
plt.title('Experience Vs. Salary')
plt.show()
y_test_pred=regr.predict(x_test)
plt.figure()
plt.plot(y_test,y_test_pred,'.')
plt.xlabel('True Salary $')
plt.ylabel('Predicted Salary $')
plt.title('regression analysis')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1399726214921287, 'fraction_numerical': 0.02840520191649555, 'mean_word_length': 4.363302752293578, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '415753', 'license': 'CC0-1.0', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1056, 'n_words': 238, 'path': 'Codigo/ANN_regresion.ipynb', 'repo_name': 'MarduckEncoded/CursoMachineLearning', 'size': '2922'}