This file contains hidden or 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
#imports | |
import numpy as np | |
import pandas as pd | |
import math | |
from sklearn.model_selection import train_test_split | |
from sklearn.linear_model import LinearRegression | |
from sklearn.linear_model import Ridge | |
from sklearn.linear_model import Lasso |
This file contains hidden or 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
#create our X and y | |
X = train_df.drop('medv', axis=1) | |
y = train_df['medv'] | |
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.3) |
This file contains hidden or 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
lr_model = LinearRegression() | |
lr_model.fit(X_train, y_train) | |
print('Training score: {}'.format(lr_model.score(X_train, y_train))) | |
print('Test score: {}'.format(lr_model.score(X_test, y_test))) | |
y_pred = lr_model.predict(X_test) | |
mse = mean_squared_error(y_test, y_pred) | |
rmse = math.sqrt(mse) |
This file contains hidden or 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
steps = [ | |
('scalar', StandardScaler()), | |
('poly', PolynomialFeatures(degree=2)), | |
('model', LinearRegression()) | |
] | |
pipeline = Pipeline(steps) | |
pipeline.fit(X_train, y_train) |
This file contains hidden or 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
steps = [ | |
('scalar', StandardScaler()), | |
('poly', PolynomialFeatures(degree=2)), | |
('model', Ridge(alpha=10, fit_intercept=True)) | |
] | |
ridge_pipe = Pipeline(steps) | |
ridge_pipe.fit(X_train, y_train) | |
print('Training Score: {}'.format(ridge_pipe.score(X_train, y_train))) |
This file contains hidden or 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
steps = [ | |
('scalar', StandardScaler()), | |
('poly', PolynomialFeatures(degree=2)), | |
('model', Lasso(alpha=0.3, fit_intercept=True)) | |
] | |
lasso_pipe = Pipeline(steps) | |
lasso_pipe.fit(X_train, y_train) |
This file contains hidden or 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
import pandas as pd | |
import numpy as np | |
from scipy.optimize import fmin, minimize | |
#load training data | |
train_df = pd.read_csv('./train.csv', index_col='ID') | |
y = train_df['medv'].values | |
y = y.reshape(-1, 1) | |
train_df['constant'] = 1 | |
columns = ['constant', 'crim', 'zn', 'indus', 'chas', 'nox', 'rm', 'age', 'dis', 'rad', 'tax', 'ptratio', 'black', 'lstat'] |
This file contains hidden or 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
import numpy as np | |
import pandas as pd | |
import tensorflow as tf | |
from sklearn.model_selection import train_test_split | |
train_df = pd.read_csv('./train.csv') | |
#create feature columns | |
crim = tf.feature_column.numeric_column('crim', dtype=tf.float64, shape=()) | |
zn = tf.feature_column.numeric_column('zn', dtype=tf.float64, shape=()) |
This file contains hidden or 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
import pandas as pd | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow.python.ops import confusion_matrix | |
from tensorflow.python.ops import math_ops | |
train_df = pd.read_csv('./train.csv', index_col='ID') | |
y = train_df['medv'].values | |
y = y.reshape(-1, 1) |
This file contains hidden or 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
import pandas as pd | |
from sklearn.preprocessing import MinMaxScaler | |
import tensorflow as tf | |
#read in training data | |
train_df = pd.read_csv('train.csv', index_col='ID') | |
train_df.head() | |
target = 'medv' |
OlderNewer