# define custom R2 metrics for Keras backend
from keras import backend as K

def r2_keras(y_true, y_pred):
    SS_res =  K.sum(K.square( y_true - y_pred )) 
    SS_tot = K.sum(K.square( y_true - K.mean(y_true) ) ) 
    return ( 1 - SS_res/(SS_tot + K.epsilon()) )
    
# base model architecture definition
def model():
    model = Sequential()
    #input layer
    model.add(Dense(input_dims, input_dim=input_dims))
    model.add(BatchNormalization())
    model.add(Activation('relu'))
    model.add(Dropout(0.3))
    # hidden layers
    model.add(Dense(input_dims))
    model.add(BatchNormalization())
    model.add(Activation(act_func))
    model.add(Dropout(0.3))
    
    model.add(Dense(input_dims//2))
    model.add(BatchNormalization())
    model.add(Activation(act_func))
    model.add(Dropout(0.3))
    
    model.add(Dense(input_dims//4, activation=act_func))
    
    # output layer (y_pred)
    model.add(Dense(1, activation='linear'))
    
    # compile this model
    model.compile(loss='mean_squared_error', # one may use 'mean_absolute_error' as alternative
                  optimizer='adam',
                  metrics=[r2_keras] # you can add several if needed
                 )
    
    # Visualize NN architecture
    print(model.summary())
    return model
    
################K2
import pandas as pd
import numpy as np
from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import LassoCV
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import RobustScaler
from keras import backend as K
from keras.models import Sequential
from keras.layers import Dense, InputLayer, GaussianNoise
from keras.wrappers.scikit_learn import KerasRegressor

train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')


#
# Data preparation
#
y_train = train['y'].values
id_test = test['ID']

num_train = len(train)
df_all = pd.concat([train, test])
df_all.drop(['ID', 'y'], axis=1, inplace=True)

# One-hot encoding of categorical/strings
df_all = pd.get_dummies(df_all, drop_first=True)

# Sscaling features
scaler = RobustScaler()
df_all = scaler.fit_transform(df_all)

train = df_all[:num_train]
test = df_all[num_train:]

# Keep only the most contributing features
sfm = SelectFromModel(LassoCV())
sfm.fit(train, y_train)
train = sfm.transform(train)
test = sfm.transform(test)

print ('Number of features : %d' % train.shape[1])

def r2_keras(y_true, y_pred):
    SS_res =  K.sum(K.square( y_true - y_pred ))
    SS_tot = K.sum(K.square( y_true - K.mean(y_true) ) )
    return ( 1 - SS_res/(SS_tot + K.epsilon()) )

def build_model_fn(neurons=20, noise=0.25):
    model = Sequential()
    model.add(InputLayer(input_shape=(train.shape[1],)))
    model.add(GaussianNoise(noise))
    model.add(Dense(neurons, activation='tanh'))
    model.add(Dense(1, activation='linear'))
    model.compile(loss='mean_squared_error', optimizer='nadam', metrics=[r2_keras])
    return model
    
    
#
# Tuning model parameters
#
model = KerasRegressor(build_fn=build_model_fn, epochs=75, verbose=0)

gsc = GridSearchCV(
    estimator=model,
    param_grid={
        #'neurons': range(18,31,4),
        'noise': [x/20.0 for x in range(3, 7)],
    },
    #scoring='r2',
    scoring='neg_mean_squared_error',
    cv=5
)

grid_result = gsc.fit(train, y_train)

print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
for test_mean, test_stdev, train_mean, train_stdev, param in zip(
        grid_result.cv_results_['mean_test_score'],
        grid_result.cv_results_['std_test_score'],
        grid_result.cv_results_['mean_train_score'],
        grid_result.cv_results_['std_train_score'],
        grid_result.cv_results_['params']):
    print("Train: %f (%f) // Test : %f (%f) with: %r" % (train_mean, train_stdev, test_mean, test_stdev, param))
    
    
#
# Train model with best params for submission
#
model = build_model_fn(**grid_result.best_params_)

model.fit(train, y_train, epochs=75, verbose=2)

y_test = model.predict(test).flatten()

df_sub = pd.DataFrame({'ID': id_test, 'y': y_test})
df_sub.to_csv('mercedes-submission.csv', index=False)

#########################
import pandas as pd
import numpy as np
from sklearn.svm import SVR
from sklearn.ensemble import RandomForestRegressor, ExtraTreesRegressor
from sklearn.decomposition import PCA, FastICA
from sklearn.preprocessing import RobustScaler
from sklearn.pipeline import make_pipeline, Pipeline, _name_estimators
from sklearn.linear_model import ElasticNet, ElasticNetCV
from sklearn.model_selection import cross_val_score, KFold
from sklearn.metrics import r2_score
from sklearn.base import BaseEstimator, TransformerMixin
import xgboost as xgb


train = pd.read_csv('../input/train.csv')
test = pd.read_csv('../input/test.csv')

y_train = train['y'].values
y_mean = np.mean(y_train)
id_test = test['ID']

num_train = len(train)
df_all = pd.concat([train, test])
df_all.drop(['ID', 'y'], axis=1, inplace=True)

# One-hot encoding of categorical/strings
df_all = pd.get_dummies(df_all, drop_first=True)

train = df_all[:num_train]
test = df_all[num_train:]


class AddColumns(BaseEstimator, TransformerMixin):
    def __init__(self, transform_=None):
        self.transform_ = transform_

    def fit(self, X, y=None):
        self.transform_.fit(X, y)
        return self

    def transform(self, X, y=None):
        xform_data = self.transform_.transform(X, y)
        return np.append(X, xform_data, axis=1)


class LogExpPipeline(Pipeline):
    def fit(self, X, y):
        super(LogExpPipeline, self).fit(X, np.log1p(y))

    def predict(self, X):
        return np.expm1(super(LogExpPipeline, self).predict(X))

#
# Model/pipeline with scaling,pca,svm
#
svm_pipe = LogExpPipeline(_name_estimators([RobustScaler(),
                                            PCA(),
                                            SVR(kernel='rbf', C=1.0, epsilon=0.05)]))
                                            
# results = cross_val_score(svm_pipe, train, y_train, cv=5, scoring='r2')
# print("SVM score: %.4f (%.4f)" % (results.mean(), results.std()))
# exit()
                                            
#
# Model/pipeline with scaling,pca,ElasticNet
#
en_pipe = LogExpPipeline(_name_estimators([RobustScaler(),
                                           PCA(n_components=125),
                                           ElasticNet(alpha=0.001, l1_ratio=0.1)]))

#
# XGBoost model
#
xgb_model = xgb.sklearn.XGBRegressor(max_depth=4, learning_rate=0.005, subsample=0.921,
                                     objective='reg:linear', n_estimators=1300, base_score=y_mean)
                                     
xgb_pipe = Pipeline(_name_estimators([AddColumns(transform_=PCA(n_components=10)),
                                      AddColumns(transform_=FastICA(n_components=10, max_iter=500)),
                                      xgb_model]))

# results = cross_val_score(xgb_model, train, y_train, cv=5, scoring='r2')
# print("XGB score: %.4f (%.4f)" % (results.mean(), results.std()))


#
# Random Forest
#
rf_model = RandomForestRegressor(n_estimators=250, n_jobs=4, min_samples_split=25,
                                 min_samples_leaf=25, max_depth=3)

# results = cross_val_score(rf_model, train, y_train, cv=5, scoring='r2')
# print("RF score: %.4f (%.4f)" % (results.mean(), results.std()))


#
# Now the training and stacking part.  In previous version i just tried to train each model and
# find the best combination, that lead to a horrible score (Overfit?).  Code below does out-of-fold
# training/predictions and then we combine the final results.
#
# Read here for more explanation (This code was borrowed/adapted) :
#

class Ensemble(object):
    def __init__(self, n_splits, stacker, base_models):
        self.n_splits = n_splits
        self.stacker = stacker
        self.base_models = base_models

    def fit_predict(self, X, y, T):
        X = np.array(X)
        y = np.array(y)
        T = np.array(T)

        folds = list(KFold(n_splits=self.n_splits, shuffle=True, random_state=2016).split(X, y))

        S_train = np.zeros((X.shape[0], len(self.base_models)))
        S_test = np.zeros((T.shape[0], len(self.base_models)))
        for i, clf in enumerate(self.base_models):

            S_test_i = np.zeros((T.shape[0], self.n_splits))

            for j, (train_idx, test_idx) in enumerate(folds):
                X_train = X[train_idx]
                y_train = y[train_idx]
                X_holdout = X[test_idx]
                y_holdout = y[test_idx]

                clf.fit(X_train, y_train)
                y_pred = clf.predict(X_holdout)[:]

                print ("Model %d fold %d score %f" % (i, j, r2_score(y_holdout, y_pred)))

                S_train[test_idx, i] = y_pred
                S_test_i[:, j] = clf.predict(T)[:]
            S_test[:, i] = S_test_i.mean(axis=1)

        # results = cross_val_score(self.stacker, S_train, y, cv=5, scoring='r2')
        # print("Stacker score: %.4f (%.4f)" % (results.mean(), results.std()))
        # exit()

        self.stacker.fit(S_train, y)
        res = self.stacker.predict(S_test)[:]
        return res

stack = Ensemble(n_splits=5,
                 #stacker=ElasticNetCV(l1_ratio=[x/10.0 for x in range(1,10)]),
                 stacker=ElasticNet(l1_ratio=0.1, alpha=1.4),
                 base_models=(svm_pipe, en_pipe, xgb_pipe, rf_model))

y_test = stack.fit_predict(train, y_train, test)

df_sub = pd.DataFrame({'ID': id_test, 'y': y_test})
df_sub.to_csv('submission.csv', index=False)

#############################
'''This example demonstrates the use of Convolution1D for text classification.
Gets to 0.89 test accuracy after 2 epochs.
90s/epoch on Intel i5 2.4Ghz CPU.
10s/epoch on Tesla K40 GPU.
'''

from __future__ import print_function

from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.layers import Embedding
from keras.layers import Conv1D, GlobalMaxPooling1D
from keras.datasets import imdb

# set parameters:
max_features = 5000
maxlen = 400
batch_size = 32
embedding_dims = 50
filters = 250
kernel_size = 3
hidden_dims = 250
epochs = 2

print('Loading data...')
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
print(len(x_train), 'train sequences')
print(len(x_test), 'test sequences')

print('Pad sequences (samples x time)')
x_train = sequence.pad_sequences(x_train, maxlen=maxlen)
x_test = sequence.pad_sequences(x_test, maxlen=maxlen)
print('x_train shape:', x_train.shape)
print('x_test shape:', x_test.shape)

print('Build model...')
model = Sequential()

# we start off with an efficient embedding layer which maps
# our vocab indices into embedding_dims dimensions
model.add(Embedding(max_features,
                    embedding_dims,
                    input_length=maxlen))
model.add(Dropout(0.2))

# we add a Convolution1D, which will learn filters
# word group filters of size filter_length:
model.add(Conv1D(filters,
                 kernel_size,
                 padding='valid',
                 activation='relu',
                 strides=1))
# we use max pooling:
model.add(GlobalMaxPooling1D())

# We add a vanilla hidden layer:
model.add(Dense(hidden_dims))
model.add(Dropout(0.2))
model.add(Activation('relu'))

# We project onto a single unit output layer, and squash it with a sigmoid:
model.add(Dense(1))
model.add(Activation('sigmoid'))

model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])
model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          validation_data=(x_test, y_test))        

[((1722, 1755), 'pandas.read_csv', 'pd.read_csv', (['"""../input/train.csv"""'], {}), "('../input/train.csv')\n", (1733, 1755), True, 'import pandas as pd\n'), ((1763, 1795), 'pandas.read_csv', 'pd.read_csv', (['"""../input/test.csv"""'], {}), "('../input/test.csv')\n", (1774, 1795), True, 'import pandas as pd\n'), ((1903, 1927), 'pandas.concat', 'pd.concat', (['[train, test]'], {}), '([train, test])\n', (1912, 1927), True, 'import pandas as pd\n'), ((2027, 2066), 'pandas.get_dummies', 'pd.get_dummies', (['df_all'], {'drop_first': '(True)'}), '(df_all, drop_first=True)\n', (2041, 2066), True, 'import pandas as pd\n'), ((2097, 2111), 'sklearn.preprocessing.RobustScaler', 'RobustScaler', ([], {}), '()\n', (2109, 2111), False, 'from sklearn.preprocessing import RobustScaler\n'), ((3005, 3066), 'keras.wrappers.scikit_learn.KerasRegressor', 'KerasRegressor', ([], {'build_fn': 'build_model_fn', 'epochs': '(75)', 'verbose': '(0)'}), '(build_fn=build_model_fn, epochs=75, verbose=0)\n', (3019, 3066), False, 'from keras.wrappers.scikit_learn import KerasRegressor\n'), ((4047, 4089), 'pandas.DataFrame', 'pd.DataFrame', (["{'ID': id_test, 'y': y_test}"], {}), "({'ID': id_test, 'y': y_test})\n", (4059, 4089), True, 'import pandas as pd\n'), ((4718, 4751), 'pandas.read_csv', 'pd.read_csv', (['"""../input/train.csv"""'], {}), "('../input/train.csv')\n", (4729, 4751), True, 'import pandas as pd\n'), ((4759, 4791), 'pandas.read_csv', 'pd.read_csv', (['"""../input/test.csv"""'], {}), "('../input/test.csv')\n", (4770, 4791), True, 'import pandas as pd\n'), ((4830, 4846), 'numpy.mean', 'np.mean', (['y_train'], {}), '(y_train)\n', (4837, 4846), True, 'import numpy as np\n'), ((4901, 4925), 'pandas.concat', 'pd.concat', (['[train, test]'], {}), '([train, test])\n', (4910, 4925), True, 'import pandas as pd\n'), ((5025, 5064), 'pandas.get_dummies', 'pd.get_dummies', (['df_all'], {'drop_first': '(True)'}), '(df_all, drop_first=True)\n', (5039, 5064), True, 'import pandas as pd\n'), ((6451, 6592), 'xgboost.sklearn.XGBRegressor', 'xgb.sklearn.XGBRegressor', ([], {'max_depth': '(4)', 'learning_rate': '(0.005)', 'subsample': '(0.921)', 'objective': '"""reg:linear"""', 'n_estimators': '(1300)', 'base_score': 'y_mean'}), "(max_depth=4, learning_rate=0.005, subsample=0.921,\n    objective='reg:linear', n_estimators=1300, base_score=y_mean)\n", (6475, 6592), True, 'import xgboost as xgb\n'), ((7076, 7185), 'sklearn.ensemble.RandomForestRegressor', 'RandomForestRegressor', ([], {'n_estimators': '(250)', 'n_jobs': '(4)', 'min_samples_split': '(25)', 'min_samples_leaf': '(25)', 'max_depth': '(3)'}), '(n_estimators=250, n_jobs=4, min_samples_split=25,\n    min_samples_leaf=25, max_depth=3)\n', (7097, 7185), False, 'from sklearn.ensemble import RandomForestRegressor, ExtraTreesRegressor\n'), ((9461, 9503), 'pandas.DataFrame', 'pd.DataFrame', (["{'ID': id_test, 'y': y_test}"], {}), "({'ID': id_test, 'y': y_test})\n", (9473, 9503), True, 'import pandas as pd\n'), ((10268, 10306), 'keras.datasets.imdb.load_data', 'imdb.load_data', ([], {'num_words': 'max_features'}), '(num_words=max_features)\n', (10282, 10306), False, 'from keras.datasets import imdb\n'), ((10434, 10480), 'keras.preprocessing.sequence.pad_sequences', 'sequence.pad_sequences', (['x_train'], {'maxlen': 'maxlen'}), '(x_train, maxlen=maxlen)\n', (10456, 10480), False, 'from keras.preprocessing import sequence\n'), ((10490, 10535), 'keras.preprocessing.sequence.pad_sequences', 'sequence.pad_sequences', (['x_test'], {'maxlen': 'maxlen'}), '(x_test, maxlen=maxlen)\n', (10512, 10535), False, 'from keras.preprocessing import sequence\n'), ((10645, 10657), 'keras.models.Sequential', 'Sequential', ([], {}), '()\n', (10655, 10657), False, 'from keras.models import Sequential\n'), ((331, 343), 'keras.models.Sequential', 'Sequential', ([], {}), '()\n', (341, 343), False, 'from keras.models import Sequential\n'), ((2270, 2279), 'sklearn.linear_model.LassoCV', 'LassoCV', ([], {}), '()\n', (2277, 2279), False, 'from sklearn.linear_model import LassoCV\n'), ((2656, 2668), 'keras.models.Sequential', 'Sequential', ([], {}), '()\n', (2666, 2668), False, 'from keras.models import Sequential\n'), ((10780, 10840), 'keras.layers.Embedding', 'Embedding', (['max_features', 'embedding_dims'], {'input_length': 'maxlen'}), '(max_features, embedding_dims, input_length=maxlen)\n', (10789, 10840), False, 'from keras.layers import Embedding\n'), ((10892, 10904), 'keras.layers.Dropout', 'Dropout', (['(0.2)'], {}), '(0.2)\n', (10899, 10904), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((11012, 11087), 'keras.layers.Conv1D', 'Conv1D', (['filters', 'kernel_size'], {'padding': '"""valid"""', 'activation': '"""relu"""', 'strides': '(1)'}), "(filters, kernel_size, padding='valid', activation='relu', strides=1)\n", (11018, 11087), False, 'from keras.layers import Conv1D, GlobalMaxPooling1D\n'), ((11189, 11209), 'keras.layers.GlobalMaxPooling1D', 'GlobalMaxPooling1D', ([], {}), '()\n', (11207, 11209), False, 'from keras.layers import Conv1D, GlobalMaxPooling1D\n'), ((11255, 11273), 'keras.layers.Dense', 'Dense', (['hidden_dims'], {}), '(hidden_dims)\n', (11260, 11273), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((11285, 11297), 'keras.layers.Dropout', 'Dropout', (['(0.2)'], {}), '(0.2)\n', (11292, 11297), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((11309, 11327), 'keras.layers.Activation', 'Activation', (['"""relu"""'], {}), "('relu')\n", (11319, 11327), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((11416, 11424), 'keras.layers.Dense', 'Dense', (['(1)'], {}), '(1)\n', (11421, 11424), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((11436, 11457), 'keras.layers.Activation', 'Activation', (['"""sigmoid"""'], {}), "('sigmoid')\n", (11446, 11457), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((127, 152), 'keras.backend.square', 'K.square', (['(y_true - y_pred)'], {}), '(y_true - y_pred)\n', (135, 152), True, 'from keras import backend as K\n'), ((375, 414), 'keras.layers.Dense', 'Dense', (['input_dims'], {'input_dim': 'input_dims'}), '(input_dims, input_dim=input_dims)\n', (380, 414), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((466, 484), 'keras.layers.Activation', 'Activation', (['"""relu"""'], {}), "('relu')\n", (476, 484), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((500, 512), 'keras.layers.Dropout', 'Dropout', (['(0.3)'], {}), '(0.3)\n', (507, 512), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((548, 565), 'keras.layers.Dense', 'Dense', (['input_dims'], {}), '(input_dims)\n', (553, 565), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((617, 637), 'keras.layers.Activation', 'Activation', (['act_func'], {}), '(act_func)\n', (627, 637), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((653, 665), 'keras.layers.Dropout', 'Dropout', (['(0.3)'], {}), '(0.3)\n', (660, 665), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((686, 708), 'keras.layers.Dense', 'Dense', (['(input_dims // 2)'], {}), '(input_dims // 2)\n', (691, 708), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((758, 778), 'keras.layers.Activation', 'Activation', (['act_func'], {}), '(act_func)\n', (768, 778), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((794, 806), 'keras.layers.Dropout', 'Dropout', (['(0.3)'], {}), '(0.3)\n', (801, 806), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((827, 870), 'keras.layers.Dense', 'Dense', (['(input_dims // 4)'], {'activation': 'act_func'}), '(input_dims // 4, activation=act_func)\n', (832, 870), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((917, 946), 'keras.layers.Dense', 'Dense', (['(1)'], {'activation': '"""linear"""'}), "(1, activation='linear')\n", (922, 946), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((2464, 2489), 'keras.backend.square', 'K.square', (['(y_true - y_pred)'], {}), '(y_true - y_pred)\n', (2472, 2489), True, 'from keras import backend as K\n'), ((2683, 2724), 'keras.layers.InputLayer', 'InputLayer', ([], {'input_shape': '(train.shape[1],)'}), '(input_shape=(train.shape[1],))\n', (2693, 2724), False, 'from keras.layers import Dense, InputLayer, GaussianNoise\n'), ((2740, 2760), 'keras.layers.GaussianNoise', 'GaussianNoise', (['noise'], {}), '(noise)\n', (2753, 2760), False, 'from keras.layers import Dense, InputLayer, GaussianNoise\n'), ((2776, 2809), 'keras.layers.Dense', 'Dense', (['neurons'], {'activation': '"""tanh"""'}), "(neurons, activation='tanh')\n", (2781, 2809), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((2825, 2854), 'keras.layers.Dense', 'Dense', (['(1)'], {'activation': '"""linear"""'}), "(1, activation='linear')\n", (2830, 2854), False, 'from keras.layers import Dense, Dropout, Activation\n'), ((5440, 5472), 'numpy.append', 'np.append', (['X', 'xform_data'], {'axis': '(1)'}), '(X, xform_data, axis=1)\n', (5449, 5472), True, 'import numpy as np\n'), ((7924, 7935), 'numpy.array', 'np.array', (['X'], {}), '(X)\n', (7932, 7935), True, 'import numpy as np\n'), ((7948, 7959), 'numpy.array', 'np.array', (['y'], {}), '(y)\n', (7956, 7959), True, 'import numpy as np\n'), ((7972, 7983), 'numpy.array', 'np.array', (['T'], {}), '(T)\n', (7980, 7983), True, 'import numpy as np\n'), ((9294, 9329), 'sklearn.linear_model.ElasticNet', 'ElasticNet', ([], {'l1_ratio': '(0.1)', 'alpha': '(1.4)'}), '(l1_ratio=0.1, alpha=1.4)\n', (9304, 9329), False, 'from sklearn.linear_model import ElasticNet, ElasticNetCV\n'), ((5575, 5586), 'numpy.log1p', 'np.log1p', (['y'], {}), '(y)\n', (5583, 5586), True, 'import numpy as np\n'), ((5766, 5780), 'sklearn.preprocessing.RobustScaler', 'RobustScaler', ([], {}), '()\n', (5778, 5780), False, 'from sklearn.preprocessing import RobustScaler\n'), ((5826, 5831), 'sklearn.decomposition.PCA', 'PCA', ([], {}), '()\n', (5829, 5831), False, 'from sklearn.decomposition import PCA, FastICA\n'), ((5877, 5915), 'sklearn.svm.SVR', 'SVR', ([], {'kernel': '"""rbf"""', 'C': '(1.0)', 'epsilon': '(0.05)'}), "(kernel='rbf', C=1.0, epsilon=0.05)\n", (5880, 5915), False, 'from sklearn.svm import SVR\n'), ((6252, 6266), 'sklearn.preprocessing.RobustScaler', 'RobustScaler', ([], {}), '()\n', (6264, 6266), False, 'from sklearn.preprocessing import RobustScaler\n'), ((6311, 6332), 'sklearn.decomposition.PCA', 'PCA', ([], {'n_components': '(125)'}), '(n_components=125)\n', (6314, 6332), False, 'from sklearn.decomposition import PCA, FastICA\n'), ((6377, 6414), 'sklearn.linear_model.ElasticNet', 'ElasticNet', ([], {'alpha': '(0.001)', 'l1_ratio': '(0.1)'}), '(alpha=0.001, l1_ratio=0.1)\n', (6387, 6414), False, 'from sklearn.linear_model import ElasticNet, ElasticNetCV\n'), ((8285, 8322), 'numpy.zeros', 'np.zeros', (['(T.shape[0], self.n_splits)'], {}), '((T.shape[0], self.n_splits))\n', (8293, 8322), True, 'import numpy as np\n'), ((195, 209), 'keras.backend.mean', 'K.mean', (['y_true'], {}), '(y_true)\n', (201, 209), True, 'from keras import backend as K\n'), ((249, 260), 'keras.backend.epsilon', 'K.epsilon', ([], {}), '()\n', (258, 260), True, 'from keras import backend as K\n'), ((2531, 2545), 'keras.backend.mean', 'K.mean', (['y_true'], {}), '(y_true)\n', (2537, 2545), True, 'from keras import backend as K\n'), ((2584, 2595), 'keras.backend.epsilon', 'K.epsilon', ([], {}), '()\n', (2593, 2595), True, 'from keras import backend as K\n'), ((6724, 6744), 'sklearn.decomposition.PCA', 'PCA', ([], {'n_components': '(10)'}), '(n_components=10)\n', (6727, 6744), False, 'from sklearn.decomposition import PCA, FastICA\n'), ((6807, 6845), 'sklearn.decomposition.FastICA', 'FastICA', ([], {'n_components': '(10)', 'max_iter': '(500)'}), '(n_components=10, max_iter=500)\n', (6814, 6845), False, 'from sklearn.decomposition import PCA, FastICA\n'), ((8006, 8068), 'sklearn.model_selection.KFold', 'KFold', ([], {'n_splits': 'self.n_splits', 'shuffle': '(True)', 'random_state': '(2016)'}), '(n_splits=self.n_splits, shuffle=True, random_state=2016)\n', (8011, 8068), False, 'from sklearn.model_selection import cross_val_score, KFold\n'), ((8699, 8726), 'sklearn.metrics.r2_score', 'r2_score', (['y_holdout', 'y_pred'], {}), '(y_holdout, y_pred)\n', (8707, 8726), False, 'from sklearn.metrics import r2_score\n')]