In [1]:
# Crear un modelo de regresion lineal que sea capaz de convertir grados celcius a fahrenheit
In [4]:
import pandas as pd
temperatura = pd.read_csv("datos_temperatura.csv")
temperatura.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 20 entries, 0 to 19
Data columns (total 2 columns):
 #   Column      Non-Null Count  Dtype  
---  ------      --------------  -----  
 0   Fahrenheit  20 non-null     int64  
 1   Celsius     20 non-null     float64
dtypes: float64(1), int64(1)
memory usage: 448.0 bytes
In [12]:
# visualizacion de los datos
import seaborn as sb
sb.scatterplot(x="Fahrenheit" , y="Celsius" , data=temperatura,
               hue="Fahrenheit" , palette="coolwarm")
Out[12]:
<Axes: xlabel='Fahrenheit', ylabel='Celsius'>
No description has been provided for this image
In [15]:
# preparacion de los datos
# caracteristicas X , etiqueta y
X = temperatura["Celsius"]
y = temperatura["Fahrenheit"]
Out[15]:
(0     16.111111
 1     -5.000000
 2     10.000000
 3     33.333333
 4      7.777778
 5    -47.777778
 6     -3.888889
 7    -18.333333
 8    -28.888889
 9    -40.555556
 10   -16.111111
 11   -18.333333
 12    -4.444444
 13   -55.555556
 14    -0.555556
 15    21.111111
 16   -62.222222
 17   -44.444444
 18     2.222222
 19   -49.444444
 Name: Celsius, dtype: float64,
 0     61
 1     23
 2     50
 3     92
 4     46
 5    -54
 6     25
 7     -1
 8    -20
 9    -41
 10     3
 11    -1
 12    24
 13   -68
 14    31
 15    70
 16   -80
 17   -48
 18    36
 19   -57
 Name: Fahrenheit, dtype: int64)
In [17]:
X.values
Out[17]:
array([ 16.11111111,  -5.        ,  10.        ,  33.33333333,
         7.77777778, -47.77777778,  -3.88888889, -18.33333333,
       -28.88888889, -40.55555556, -16.11111111, -18.33333333,
        -4.44444444, -55.55555556,  -0.55555556,  21.11111111,
       -62.22222222, -44.44444444,   2.22222222, -49.44444444])
In [19]:
# transformacion a un arreglo en cada posicion de los datos
X_procesada = X.values.reshape(-1,1)
y_procesada = y.values.reshape(-1,1)
In [22]:
# Creacion del modelo
from sklearn.linear_model import LinearRegression
modelo = LinearRegression()
In [23]:
# entrenamiento del modelo
modelo.fit(X_procesada , y_procesada)
Out[23]:
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
In [37]:
# Prediccion
C = int(input("Ingresa la cantidad de grados Celcius para Convertir : "))
prediccion = modelo.predict([[C]])
print(f"La prediccion de {C} grados Celcius es de {prediccion} Fahrenheit")
Ingresa la cantidad de grados Celcius para Convertir : 22
La prediccion de 22 grados Celcius es de [[71.6]] Fahrenheit
In [35]:
# puntaje de aprendizaje del modelo (0 a 1)
modelo.score(X_procesada , y_procesada)
Out[35]:
1.0
In [ ]: