Skip to content

Instantly share code, notes, and snippets.

@securetorobert
Created July 15, 2018 21:36
Show Gist options
  • Save securetorobert/e18eb3ea0dafd052527a83bb8b32f113 to your computer and use it in GitHub Desktop.
Save securetorobert/e18eb3ea0dafd052527a83bb8b32f113 to your computer and use it in GitHub Desktop.
Import data for L1 Regularization in TensorFlow
import pandas as pd
import numpy as np
import tensorflow as tf
from sklearn.model_selection import train_test_split
#load training data
train_df = pd.read_csv('train.csv', index_col='ID')
#split into features and target
X = train_df.drop('medv', axis=1)
y = train_df['medv']
#engineer new features
X['crim_2'] = X['crim'] ** 2
X['zn_2'] = X['zn'] ** 2
X['indus_2'] = X['indus'] ** 2
X['chas_2'] = X['chas'] ** 2
X['nox_2'] = X['nox'] ** 2
X['rm_2'] = X['rm'] ** 2
X['age_2'] = X['age'] ** 2
X['dis_2'] = X['dis'] ** 2
X['rad_2'] = X['rad'] ** 2
X['tax_2'] = X['tax'] ** 2
X['ptratio_2'] = X['ptratio'] ** 2
X['black_2'] = X['black'] ** 2
X['lstat_2'] = X['lstat'] ** 2
#split into training and validation
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment