Last active
February 13, 2020 01:55
-
-
Save dtellogaete/bb8f9c37997151e4d1f542d19326bc20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importar las librerías | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
# Importar el dataset de entranamiento | |
dataset = pd.read_csv('Admission_Predict_Ver1.1.csv') | |
X = dataset.iloc[:len(dataset), 1].values | |
X = X.reshape(-1,1) | |
X = np.insert(X, 0, 1, axis = 1) | |
y = dataset.iloc[:len(dataset), -1].values.reshape(-1,1) | |
# Seleccionar conjunto de training y test | |
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, | |
random_state = 0) | |
# Escalado de las variables | |
from sklearn.preprocessing import StandardScaler | |
st_x = StandardScaler() | |
X_train = st_x.fit_transform(X_train) | |
X_test = st_x.transform(X_test) | |
st_y = StandardScaler() | |
y_train = st_y.fit_transform(y_train).reshape(-1) | |
y_test = st_y.transform(y_test).reshape(-1) | |
# Aplicación del modelo con grad | |
regression = LinearRegressionGD(l_rate = 0.01, n_iter = 20000) | |
coef = regression.fit(X_train, y_train, np.array([0.0, 1])) | |
y_predict = regression.predict(X_test) | |
# Aplicación del modelo con librería de sklearn | |
from sklearn.linear_model import LinearRegression | |
regression_py = LinearRegression() | |
regression_py.fit(X_train, y_train) | |
y_predict_py = regression_py.predict(X_test) | |
# Gráfica de regresión conjunto de test | |
plt.scatter(X_test[:,1], y_test, color = "red") | |
plt.plot(X_test[:,1], y_predict_py, color = "blue") | |
plt.legend(('Descenso de Gradiente',), | |
loc='lower right') | |
plt.title("Probabilidad admisión vs GRE Score (Conjunto de Test)") | |
plt.xlabel("GRE Score") | |
plt.ylabel("Probabilidad admisión a Postgrado") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment