You are on page 1of 6

CÓDIGO DE PROGRAMACIÓN Y RESULTADOS

[1]: # import tensorflow as tf


import numpy as np

[2]: pip install -U scikit-learn

[3]: from sklearn.preprocessing import PowerTransformer


from sklearn.metrics import mean_squared_error
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split

[4]: pip install scikeras

[5]: from scikeras.wrappers import KerasRegressor


from keras.models import sequential
from keras.layers import Dense
from keras import backend as K
from keras.models import model_from_json

[6]: #se ingresan las variables de entrada y salida


MDS = np.array([2.016, 1.752, 1.868, 2.034, 1.781, 2.185, 2.110, 2.134,
,→2.099, 1.899, 1.938, 2.060, 1.481, 2.155, 2.168, 1.822, 2.279, 2.

,→151, 2.136, 2.058, 1.889, 1.792, 1.894, 1.949, 1.970, 1.929, 1.945,

,→2.091, 1.961, 1.829 ],dtype=float )

COH = np.array([13.80, 16.47, 14.06, 12.90, 16.10, 9.90, 12.10, 8.70, 7.


,→70, 9.40, 12.80, 14.32, 21.53, 10.50, 10.10, 16.70, 8.40, 6.60, 10.

,→32, 10.50, 10.60, 18, 14.25, 9.90, 13.50, 13.92, 9, 11.50, 12.50, 12.

,→70],dtype=float)

CBR_al_95_por_ciento=np.array([29.70, 11.70, 14.80, 28.50, 7.40, 48.00,


,→40.50, 28.20, 23.90, 21.30, 13.100, 32, 2.3, 41.10,43.200, 13.200,

,→30, 42, 40 , 23, 19 , 3, 18, 22, 22, 20, 19, 31, 17, 21

,→],dtype=float)

CBR_al_100_por_ciento=np.array([31.8, 13.70, 23.20, 21.00, 10.40, 56.


,→20, 46.00, 41.00, 26.00, 25.00, 15.50, 38.40, 3.100, 46.900, 52.100,

,→19.400, 15, 64, 65, 36, 34, 5, 17, 39, 42, 38, 25, 47, 37,

,→41],dtype=float)

[7]: capa = tf.keras.layers.Dense(units=1, input_shape=[1])


modelo = tf.keras.Sequential([capa])

modelo.compile(
optimizer=tf.keras.optimizers.Adam(0.01),
loss='mean_squared_error'
)

print("comenzando entrenamiento...")

1
historial = modelo.fit(MDS, CBR_al_95_por_ciento,epochs=2500,
,→verbose=False)

print("Modelo entrenado")

[8]: import matplotlib.pyplot as plt


plt.xlabel("# Epoca")
plt.ylabel("Magnitud de perdida")
plt.plot(historial.history["loss"])

print("Realizando una prediccion del CBR al 95%!")


resultado=modelo.predict([2.016])
display("El resultado es " + str(resultado) + "CBR al 95%!")

[9]: import tensorflow as tf


import numpy as np
from sklearn.preprocessing import PowerTransformer
from sklearn.metrics import mean_squared_error
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from scikeras.wrappers import KerasRegressor
from keras.models import sequential
from keras.layers import Dense
from keras import backend as K
from keras.models import model_from_json

[10]: MDS = np.array([2.016, 1.752, 1.868, 2.034, 1.781, 2.185, 2.110, 2.134,
,→2.099, 1.899, 1.938, 2.060, 1.481, 2.155, 2.168, 1.822, 2.279, 2.

,→151, 2.136, 2.058, 1.889, 1.792, 1.894, 1.949, 1.970, 1.929, 1.945,

,→2.091, 1.961, 1.829 ],dtype=float )

2
COH = np.array([13.80, 16.47, 14.06, 12.90, 16.10, 9.90, 12.10, 8.70, 7.
,→70, 9.40, 12.80, 14.32, 21.53, 10.50, 10.10, 16.70, 8.40, 6.60, 10.

,→32, 10.50, 10.60, 18, 14.25, 9.90, 13.50, 13.92, 9, 11.50, 12.50, 12.

,→70],dtype=float)

CBR_al_95_por_ciento=np.array([29.70, 11.70, 14.80, 28.50, 7.40, 48.00,


,→40.50, 28.20, 23.90, 21.30, 13.100, 32, 2.3, 41.10,43.200, 13.200,

,→30, 42, 40 , 23, 19 , 3, 18, 22, 22, 20, 19, 31, 17, 21

,→],dtype=float)

CBR_al_100_por_ciento=np.array([31.8, 13.70, 23.20, 21.00, 10.40, 56.


,→20, 46.00, 41.00, 26.00, 25.00, 15.50, 38.40, 3.100, 46.900, 52.100,

,→19.400, 15, 64, 65, 36, 34, 5, 17, 39, 42, 38, 25, 47, 37,

,→41],dtype=float)

[11]: capa = tf.keras.layers.Dense(units=1, input_shape=[1])


modelo = tf.keras.Sequential([capa])

[12]: modelo.compile(
optimizer=tf.keras.optimizers.Adam(0.01),
loss='mean_squared_error'
)

print("comenzando entrenamiento...")
historial = modelo.fit(COH, CBR_al_95_por_ciento,epochs=2500,
,→verbose=False)

print("Modelo entrenado")

[13]: import matplotlib.pyplot as plt


plt.xlabel("# Epoca")
plt.ylabel("Magnitud de perdida")
plt.plot(historial.history["loss"])

3
[14]: print("Realizando una prediccion del CBR al 95%!")
resultado=modelo.predict([2.016])
display("El resultado es " + str(resultado) + "CBR al 95%!")

[15]: import tensorflow as tf


import numpy as np
from sklearn.preprocessing import PowerTransformer
from sklearn.metrics import mean_squared_error
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from scikeras.wrappers import KerasRegressor
from keras.models import sequential
from keras.layers import Dense
from keras import backend as K
from keras.models import model_from_json

[16]: capa = tf.keras.layers.Dense(units=1, input_shape=[1])


modelo = tf.keras.Sequential([capa])

[17]: modelo.compile(
optimizer=tf.keras.optimizers.Adam(0.01),
loss='mean_squared_error'
)

print("comenzando entrenamiento...")
historial = modelo.fit(MDS, CBR_al_100_por_ciento,epochs=2500,
,→verbose=False)

print("Modelo entrenado")

[18]: import matplotlib.pyplot as plt


plt.xlabel("# Epoca")
plt.ylabel("Magnitud de perdida")
plt.plot(historial.history["loss"])

4
[19]: print("Realizando una prediccion del CBR al 100%!")
resultado=modelo.predict([2.016])
display("El resultado es " + str(resultado) + "CBR al 100%!")

[20]: import tensorflow as tf


import numpy as np
from sklearn.preprocessing import PowerTransformer
from sklearn.metrics import mean_squared_error
from sklearn import preprocessing
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from scikeras.wrappers import KerasRegressor
from keras.models import sequential
from keras.layers import Dense
from keras import backend as K
from keras.models import model_from_json

[21]: MDS = np.array([2.016, 1.752, 1.868, 2.034, 1.781, 2.185, 2.110, 2.134,
,→2.099, 1.899, 1.938, 2.060, 1.481, 2.155, 2.168, 1.822, 2.279, 2.

,→151, 2.136, 2.058, 1.889, 1.792, 1.894, 1.949, 1.970, 1.929, 1.945,

,→2.091, 1.961, 1.829 ],dtype=float )

COH = np.array([13.80, 16.47, 14.06, 12.90, 16.10, 9.90, 12.10, 8.70, 7.


,→70, 9.40, 12.80, 14.32, 21.53, 10.50, 10.10, 16.70, 8.40, 6.60, 10.

,→32, 10.50, 10.60, 18, 14.25, 9.90, 13.50, 13.92, 9, 11.50, 12.50, 12.

,→70],dtype=float)

CBR_al_95_por_ciento=np.array([29.70, 11.70, 14.80, 28.50, 7.40, 48.00,


,→40.50, 28.20, 23.90, 21.30, 13.100, 32, 2.3, 41.10,43.200, 13.200,

,→30, 42, 40 , 23, 19 , 3, 18, 22, 22, 20, 19, 31, 17, 21

,→],dtype=float)

CBR_al_100_por_ciento=np.array([31.8, 13.70, 23.20, 21.00, 10.40, 56.


,→20, 46.00, 41.00, 26.00, 25.00, 15.50, 38.40, 3.100, 46.900, 52.100,

,→19.400, 15, 64, 65, 36, 34, 5, 17, 39, 42, 38, 25, 47, 37,

,→41],dtype=float)

5
[22]: capa = tf.keras.layers.Dense(units=1, input_shape=[1])
modelo = tf.keras.Sequential([capa])

[23]: modelo.compile(
optimizer=tf.keras.optimizers.Adam(0.01),
loss='mean_squared_error'
)

print("comenzando entrenamiento...")
historial = modelo.fit(COH, CBR_al_100_por_ciento,epochs=2500,
,→verbose=False)

print("Modelo entrenado")

[24]: import matplotlib.pyplot as plt


plt.xlabel("# Epoca")
plt.ylabel("Magnitud de perdida")
plt.plot(historial.history["loss"])

[25]: display("Realizando una prediccion del CBR al 100%!")


resultado=modelo.predict([2.016])
display("El resultado es " + str(resultado) + "CBR al 100%!")

You might also like