{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"#model version with cwt transformation has best score so far\n#convertingg time series to image\n#https://www.kaggle.com/tigurius/recuplots-and-cnns-for-time-series-classification\n\n# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\n# Any results you write to the current directory are saved as output.\n\nimport os\n\nimport numpy as np\nimport pandas as pd\n\nimport pyarrow.parquet as pq\nimport matplotlib.pyplot as plt\nimport pywt\n\nfrom scipy.signal import find_peaks\nfrom scipy import optimize\nfrom numpy.fft import rfft,rfftfreq, irfft\n\nfrom keras.layers import *\nfrom keras.models import Model\nfrom tqdm import tqdm\nfrom sklearn.model_selection import train_test_split\nfrom keras.callbacks import ModelCheckpoint\nfrom keras import backend as K\nfrom keras.optimizers import Adam\n\nfrom statsmodels.robust import mad\nimport scipy\nfrom scipy import signal\nfrom scipy.signal import butter\n\nimport warnings\n\n#os.chdir('D:\\\\Kaggle\\\\VSBPowerLineFalutDetection\\\\all\\\\code')\n#os.getcwd()\nprint(\"The version cwt version run after 5th fails\")\nos.listdir('../input')\ndftrain = pd.read_csv('../input/metadata_train.csv') \n#dftrain.head()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"def matthews_correlation(y_true, y_pred):\n    '''Calculates the Matthews correlation coefficient measure for quality\n    of binary classification problems.\n    '''\n    y_pred_pos = K.round(K.clip(y_pred, 0, 1))\n    y_pred_neg = 1 - y_pred_pos\n\n    y_pos = K.round(K.clip(y_true, 0, 1))\n    y_neg = 1 - y_pos\n\n    tp = K.sum(y_pos * y_pred_pos)\n    tn = K.sum(y_neg * y_pred_neg)\n\n    fp = K.sum(y_neg * y_pred_pos)\n    fn = K.sum(y_pos * y_pred_neg)\n\n    numerator = (tp * tn - fp * fn)\n    denominator = K.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))\n\n    return numerator / (denominator + K.epsilon())\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"888cc64ae6a147647c74f840ee0f2e16ed9ef7c4"},"cell_type":"code","source":"# https://www.kaggle.com/suicaokhoailang/lstm-attention-baseline-0-652-lb\n\nclass Attention(Layer):\n    def __init__(self, step_dim,\n                 W_regularizer=None, b_regularizer=None,\n                 W_constraint=None, b_constraint=None,\n                 bias=True, **kwargs):\n        self.supports_masking = True\n        self.init = initializers.get('glorot_uniform')\n\n        self.W_regularizer = regularizers.get(W_regularizer)\n        self.b_regularizer = regularizers.get(b_regularizer)\n\n        self.W_constraint = constraints.get(W_constraint)\n        self.b_constraint = constraints.get(b_constraint)\n\n        self.bias = bias\n        self.step_dim = step_dim\n        self.features_dim = 0\n        super(Attention, self).__init__(**kwargs)\n\n    def build(self, input_shape):\n        assert len(input_shape) == 3\n\n        self.W = self.add_weight((input_shape[-1],),\n                                 initializer=self.init,\n                                 name='{}_W'.format(self.name),\n                                 regularizer=self.W_regularizer,\n                                 constraint=self.W_constraint)\n        self.features_dim = input_shape[-1]\n\n        if self.bias:\n            self.b = self.add_weight((input_shape[1],),\n                                     initializer='zero',\n                                     name='{}_b'.format(self.name),\n                                     regularizer=self.b_regularizer,\n                                     constraint=self.b_constraint)\n        else:\n            self.b = None\n\n        self.built = True\n\n    def compute_mask(self, input, input_mask=None):\n        return None\n\n    def call(self, x, mask=None):\n        features_dim = self.features_dim\n        step_dim = self.step_dim\n\n        eij = K.reshape(K.dot(K.reshape(x, (-1, features_dim)),\n                        K.reshape(self.W, (features_dim, 1))), (-1, step_dim))\n\n        if self.bias:\n            eij += self.b\n\n        eij = K.tanh(eij)\n\n        a = K.exp(eij)\n\n        if mask is not None:\n            a *= K.cast(mask, K.floatx())\n\n        a /= K.cast(K.sum(a, axis=1, keepdims=True) + K.epsilon(), K.floatx())\n\n        a = K.expand_dims(a)\n        weighted_input = x * a\n        return K.sum(weighted_input, axis=1)\n\n    def compute_output_shape(self, input_shape):\n        return input_shape[0],  self.features_dim\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"63db64ae29e49e5ca70e4e71a9012271122115be"},"cell_type":"code","source":"# 800,000 data points taken over 20 ms\n# Grid operates at 50hz, 0.02 * 50 = 1, so 800k samples in 20 milliseconds will capture one complete cycle\nn_samples = 800000\n\n# Sample duration is 20 miliseconds\nsample_duration = 0.02\n\n# Sample rate is the number of samples in one second\n# Sample rate will be 40mhz\nsample_rate = n_samples * (1 / sample_duration)\n\ndef maddest(d, axis=None):\n    \"\"\"\n    Mean Absolute Deviation\n    \"\"\"\n    return np.mean(np.absolute(d - np.mean(d, axis)), axis)\n\ndef high_pass_filter(x, low_cutoff=1000, sample_rate=sample_rate):\n    \"\"\"\n    From @randxie https://github.com/randxie/Kaggle-VSB-Baseline/blob/master/src/utils/util_signal.py\n    Modified to work with scipy version 1.1.0 which does not have the fs parameter\n    \"\"\"\n    \n    # nyquist frequency is half the sample rate https://en.wikipedia.org/wiki/Nyquist_frequency\n    nyquist = 0.5 * sample_rate\n    norm_low_cutoff = low_cutoff / nyquist\n\n        \n    # Fault pattern usually exists in high frequency band. According to literature, the pattern is visible above 10^4 Hz.\n    # scipy version 1.2.0\n    #sos = butter(10, low_freq, btype='hp', fs=sample_fs, output='sos')\n    \n    # scipy version 1.1.0\n    sos = butter(10, Wn=[norm_low_cutoff*20], btype='highpass', output='sos') \n    filtered_sig = signal.sosfilt(sos, x)\n    \n    return filtered_sig\n\ndef denoise_signal( x, wavelet='db4', level=1):\n    \"\"\"\n    1. Adapted from waveletSmooth function found here:\n    http://connor-johnson.com/2016/01/24/using-pywavelets-to-remove-high-frequency-noise/\n    2. Threshold equation and using hard mode in threshold as mentioned\n    in section '3.2 denoising based on optimized singular values' from paper by Tomas Vantuch:\n    http://dspace.vsb.cz/bitstream/handle/10084/133114/VAN431_FEI_P1807_1801V001_2018.pdf\n    \"\"\"\n    \n    # Decompose to get the wavelet coefficients\n    coeff = pywt.wavedec( x, wavelet, mode=\"per\" )\n    \n    # Calculate sigma for threshold as defined in http://dspace.vsb.cz/bitstream/handle/10084/133114/VAN431_FEI_P1807_1801V001_2018.pdf\n    # As noted by @harshit92 MAD referred to in the paper is Mean Absolute Deviation not Median Absolute Deviation\n    sigma = (1/0.6745) * maddest( coeff[-level] )\n    #sigma = (1/0.25) * maddest( coeff[-level] )\n\n    # Calculte the univeral threshold\n    uthresh = sigma * np.sqrt( 2*np.log( len( x ) ) )\n    coeff[1:] = ( pywt.threshold( i, value=uthresh, mode='hard' ) for i in coeff[1:] )\n    \n    # Reconstruct the signal using the thresholded coefficients\n    return pywt.waverec( coeff, wavelet, mode='per' )\n\n#very high peacks (above height) are removed alonge with lower following peacks till width\ndef removeHighPeacks(x_data,width,height) :\n    mask = (x_data > height)|(x_data < -height)\n    maskCopy = mask.copy()\n    for j in np.arange(1,len(mask)-width):\n        if(mask[j] ==  True):\n            maskCopy[max(j-width,0):j+width] = 1\n    x_data[maskCopy] = 0\n    return x_data\n\n#peacks are retained minimum instance are present in width range. \ndef removeIsolatedPeack(x_data,width, height, min_instances):\n    for j in np.arange(0,len(x_data)-width,width):\n        #print(j,\":\",np.sum((x_dn[j:j+width] > 5) | (x_dn[j:j+width] < -5)))\n        if(np.sum((x_data[j:j+width] > height) | (x_data[j:j+width] < -height)) < min_instances):\n            x_data[j:j+width] = 0\n    return (x_data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"25b8ca68c667aa243aa7d82f82791a95c680da43"},"cell_type":"code","source":"#n_dim=256 divides signal in complete chunk and is power of 2. if want to change\n#following function need to handle last partial signal chunk\n#train_length = 3\n#we are extracting only global features. May need to get features in chunks.\n# While taking the chunks rather than fix size try to capture the brust.\n#May need padding to make same sizes\ndef feature_extraction(x_data, low_cutoff=10000,signal_len=800000,n_dim=256):  \n    # Apply high pass filter with low cutoff of 10kHz, this will remove the low frequency 50Hz sinusoidal motion in the signal\n    #print(\"high_pass_filter\")\n    x_hp = high_pass_filter(x_data, low_cutoff=10000, sample_rate=sample_rate)\n    \n    # Apply denoising\n    #print(\"denoise_signal\")\n    x_dn = denoise_signal(x_hp, wavelet='haar', level=1)\n    # Remove high peacks\n    #print(\"removeHighPeacks\")\n    x_rh = removeHighPeacks(x_dn,250,35)\n    #Remove isolated peacks\n    #print(\"removeIsolatedPeack\")\n    \n    x_clean=removeIsolatedPeack(x_rh,width=1024,height=5, min_instances=4)\n    #x_clean=removeIsolatedPeack(x_rh,1024,height=(np.max(x_rh)-np.min(x_rh))/5, min_instances=4)\n    #print(\"greater than 5\")\n    x_clean[(x_clean<5)&(x_clean>-5)]=0\n    \n    indexes = np.nonzero(x_clean)[0].ravel()\n    \n    #print(\"Collecting faulty data, #of data points : \", len(indexes) )\n    faultSignal=[]\n    maxLen = 0\n    for ind in indexes:\n        faultSignal = np.append(faultSignal,np.asarray(x_clean[ind]))\n        length = len(faultSignal)\n        #print(\"Length :\",length )\n        #if (length > maxLen):\n        #    maxLen = length\n        #    print(\"********Maxium Length is :\", maxLen)\n    length = len(faultSignal)\n    if (length > 256):\n        faultSignal = faultSignal[0:256]\n    else:\n        faultSignal=np.pad(faultSignal,(0,256-length),'constant',constant_values=0)    \n    return (np.asarray(faultSignal))\n    #print(\"Returning Features\")\n    #plt.plot(faultSignal)\n    #new_signal = []\n    #bucket_size = int(signal_len / n_dim)\n    #for i in range(0, signal_len, bucket_size):\n    #    signal_range = faultSignal[i:i + bucket_size]\n    #sumRange = np.sum(np.abs(faultSignal))\n    #count = len(faultSignal)\n    #std = np.std(faultSignal)\n    #tweenthyPercentile = np.percentile(x_data, 20)\n    #eighthPercentile = np.percentile(x_data, 80)\n    #new_signal.append(np.asarray([sumRange,count,std,tweenthyPercentile,eighthPercentile]))\n    #return np.asarray([sumRange,count,std,tweenthyPercentile,eighthPercentile])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e380b941fd855b7972ee44f87449b03b6c3d652f"},"cell_type":"code","source":"def prep_data(start, end):\n    #praq_train = pq.read_pandas('../input/train.parquet').to_pandas()\n    print(start,\" : \" , end)\n    praq_train = pq.read_pandas('../input/train.parquet', columns=[str(i) for i in range(start, end)]).to_pandas()\n    print(praq_train.shape)\n    X = []\n    y = []\n    \n    for i in tqdm(range(start,end)):\n        y.append(dftrain.loc[dftrain.signal_id==i, 'target'].values)\n        feature=feature_extraction(praq_train[str(i)])\n        X.append(np.asarray([feature]))\n    X = np.asarray(X)\n    y = np.asarray(y)\n    return X, y  \n        \n    #for id_measurement in df_train.index.levels[0].unique()[int(start/3):int(end/3)]:\n        #X_signal = []\n        #for phase in [0,1,2]:\n   #         signal_id, target = df_train.loc[id_measurement].loc[phase]\n   #         if phase == 0:\n   #             y.append(target)\n            #if (signal_id %100 == 0):\n  #          print(str(signal_id))\n            \n  #          b = praq_train[str(signal_id)]\n  #          a=feature_extraction(b)\n  #          X_signal.append(a)\n        #X_signal = np.concatenate(X_signal, axis=1)\n  #      X_signal = np.concatenate(X_signal)\n  #      X.append(X_signal)\n  #  X = np.asarray(X)\n  #  y = np.asarray(y)\n  #  return X, y","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cac77fedefbcec8f6a43e3c9d4d51ee82fadcae8"},"cell_type":"code","source":"df_train = pd.read_csv('../input/metadata_train.csv')\ndf_train = df_train.set_index(['id_measurement', 'phase'])\ndf_train.head()\nlen(df_train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cc59dd1bffdc2fedc7267f16579a30c2fb2234be"},"cell_type":"code","source":"\nX = []\ny = []\ndef load_all():    \n    total_size = len(df_train)\n    #total_size = 900 # must be multiple of 3\n    for ini, end in [(0, int(total_size/2)), (int(total_size/2), total_size)]:\n        print(ini,end)\n        X_temp, y_temp = prep_data(ini, end)\n        X.append(X_temp)\n        y.append(y_temp)\nload_all()\nX = np.concatenate(X)\ny = np.concatenate(y)\nprint(\"Loaded data\", X.shape)\nprint(\"Loaded Target\", y.shape)\n#Normalise X\nX = np.nan_to_num(X)\nmaxCoefficient=np.amax(X,axis=0, keepdims = True)\nmaxCoefficient=maxCoefficient+K.epsilon()\nX = X/maxCoefficient","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e5c1d4683d032a578562c30782251f539a00a360"},"cell_type":"code","source":"print(X.shape)\nprint(X[0])\nprint(y[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c71bfa8329d1778cb1547895dc414713bed397f9"},"cell_type":"code","source":"print(X.shape)\nprint(y.shape)\nprint(maxCoefficient.shape)\n#z = X.copy()\n#X = X/maxCoefficient\nprint(np.max(np.ravel(X)))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ae9a337b9beed69b34f211683fe29e7fcd713d0e"},"cell_type":"code","source":"#TODO get balanced split.\nX_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.25)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a44c678ced6f82a14a1c700955db05bbc3d01ab3"},"cell_type":"code","source":"plt.plot(y_train)\nplt.show()\n\nplt.plot(y_valid)\nplt.show()\n\nplt.plot(X_valid[:,:,0])\nplt.show()\nplt.plot(X_valid[:,:,1])\nplt.show()\nplt.plot(X_valid[:,:,2])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"79688e2f9409147d678e9c4402c7c5d064db604d"},"cell_type":"code","source":"#from sklearn import tree, ensemble\n\n#gboost = ensemble.GradientBoostingClassifier(max_depth=4, min_samples_leaf=2, n_estimators = 3)\n#sample_weight1  = np.ones(y_train.shape[0])\n#mask = y_train==1\n#sample_weight1[mask.ravel()] = ((y_train.shape[0]+ np.sum(y_train==1))/np.sum(y_train==1))*0.75\n#gboost_fit = gboost.fit(X_train, y_train.ravel(), sample_weight=sample_weight1.ravel())\n#fit = gboost_fit","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b8c2a299552ffc2773b5404e33f7b6b666f795c9"},"cell_type":"code","source":"#train_y_pred = fit.predict(X_train)\n#train_y_pred=train_y_pred.reshape(len(train_y_pred),1)\n\n#matthews_corrcoef1=matthews_correlation(y_train, train_y_pred)\n#print(matthews_corrcoef1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3d7a1990c443bcad6f0e1fe8996362e884763b3c"},"cell_type":"code","source":"#test_y_pred = fit.predict(X_test)\n#test_y_pred=test_y_pred.reshape(len(test_y_pred),1)\n\n#matthews_corrcoef2=matthews_corrcoef(y_test, test_y_pred)\n#print(matthews_corrcoef2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4fac1ba9f5d970045e914080fb32bce0e88d88b3"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"79f1b0b317acd9caf0c7d2485d6520b007994d5b","scrolled":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9eaa63cb6256fbe9f936af1140a65d7101ae5a2e"},"cell_type":"code","source":"#from tensorflow.python.ops.rnn_cell_impl import DropoutWrapper\ndef model_lstm(input_shape,dropout=0.3):\n    inp = Input(shape=(input_shape[1],input_shape[2],))\n    \n    #x = Bidirectional(CuDNNLSTM(128, return_sequences=True))(inp)\n    #x=DropoutWrapper(output_keep_prob=dropout)(x)\n    #x = Bidirectional(CuDNNLSTM(64, return_sequences=True))(x)\n    #x = Bidirectional(LSTM(128, return_sequences=True))(inp)\n    #x = Bidirectional(LSTM(64, return_sequences=True))(x)\n    x = LSTM(64, return_sequences=True)(inp)\n    x = LSTM(32, return_sequences=True)(x)\n    x = Attention(input_shape[1])(x)\n    x = Dense(2, activation=\"relu\")(x)\n    x  = Dropout(dropout)(x)\n    x = Dense(1, activation=\"sigmoid\")(x)\n    model = Model(inputs=inp, outputs=x)\n    adams= Adam(lr=0.0001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)\n    model.compile(loss='binary_crossentropy', optimizer= adams, metrics=[matthews_correlation])\n    \n    return model","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c1b0ee35443fb053a124f4db5d98654ece9e991c"},"cell_type":"code","source":"model= model_lstm(X_train.shape)\nprint(model.metrics_names)\nmodel.summary()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8add53ebe8b9551b40fb8f23a72d106fc5460b2d"},"cell_type":"code","source":"ckp = ModelCheckpoint('weights.h5', save_best_only=True, save_weights_only=True, verbose=1, monitor='val_matthews_correlation', mode='max')\nhistory=model.fit(X_train, y_train, batch_size=100, epochs=250, validation_data=[X_valid, y_valid] , callbacks=[ckp])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a526b7fbeea6c9583a7099e168e95423aef17ce8"},"cell_type":"code","source":"print(history.history.keys())\n# summarize history for loss\nplt.plot(history.history['loss'])\nplt.plot(history.history['val_loss'])\nplt.title('model loss')\nplt.ylabel('loss')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.show()\n# summarize history for matthews_correlation\nplt.plot(history.history['matthews_correlation'])\nplt.plot(history.history['val_matthews_correlation'])\nplt.title('model matthews_correlation')\nplt.ylabel('matthews_correlation')\nplt.xlabel('epoch')\nplt.legend(['train', 'test'], loc='upper left')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3d598087e5c6b83442109943b230d1bd6c4cc46e"},"cell_type":"code","source":"%%time\n# 25ms in Kernel\nmeta_test = pd.read_csv('../input/metadata_test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"008d25055b79abae4e34361b1df3152225d7fdeb"},"cell_type":"code","source":"meta_test = meta_test.set_index(['signal_id'])\nmeta_test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"32a96bf79ac66fbe50c7158db771e3eec669082d"},"cell_type":"code","source":"%%time\nfirst_sig = meta_test.index[0]\nn_parts = 10\nmax_line = len(meta_test)\n#max_line = 90\npart_size = int(max_line / n_parts)\nlast_part = max_line % n_parts\nprint(first_sig, n_parts, max_line, part_size, last_part, n_parts * part_size + last_part)\nstart_end = [[x, x+part_size] for x in range(first_sig, max_line + first_sig, part_size)]\nstart_end = start_end[:-1] + [[start_end[-1][0], start_end[-1][0] + last_part]]\n\nprint(\"Change max_line = len(meta_test)\")\nX_test = []\nfor start, end in start_end:\n    subset_test = pq.read_pandas('../input/test.parquet', columns=[str(i) for i in range(start, end)]).to_pandas()\n    for i in tqdm(subset_test.columns):\n        id_measurement, phase = meta_test.loc[int(i)]\n        subset_test_col = subset_test[i]\n        subset_trans = extract_features(subset_test_col)\n        X_test.append([i, id_measurement, phase, subset_trans])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"aa8768850dba27cb693cb19b53d0a29f6eee6aeb"},"cell_type":"code","source":"X_test_input = np.asarray([np.concatenate([X_test[i][3],X_test[i+1][3], X_test[i+2][3]], axis=1) for i in range(0,len(X_test), 3)])\nX_test_input.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d8eaf7c9469d726a77dd31827b59a0f852a987b9"},"cell_type":"code","source":"submission = pd.read_csv('../input/sample_submission.csv')\nprint(len(submission))\nsubmission.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"db70fdd8f0183b519bfcfaf79d4c50e0a65106cd"},"cell_type":"code","source":"model.load_weights('weights.h5')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d47f0eb8fd8b330fdfd6cc8155d275833ff4663"},"cell_type":"code","source":"pred = model.predict(X_test_input, batch_size=300)\nplt.plot(pred])\nplt.title('Predications Probabilities')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ba8304d74758ca4e89a28b6a622d197b8ad8a912"},"cell_type":"code","source":"pred_3 = []\nfor pred_scalar in pred:\n    for i in range(3):\n        pred_3.append(int(pred_scalar > 0.15))\nsubmission['target'] = pred_3\nsubmission.to_csv('submission15.csv', index=False)\nprint(\"submission15 # predicted true\",np.sum(submission['target']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4b7b7a2bb56e0e7b2b09b11959fa16e3cb1edaad"},"cell_type":"code","source":"pred_3 = []\nfor pred_scalar in pred:\n    for i in range(3):\n        pred_3.append(int(pred_scalar > 0.2))\nsubmission['target'] = pred_3\nsubmission.to_csv('submission2.csv', index=False)\nprint(\"submission2 # predicted true\",np.sum(submission['target']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"49c76254c125e7a33fe3835abe4107817160c166"},"cell_type":"code","source":"pred_3 = []\nfor pred_scalar in pred:\n    for i in range(3):\n        pred_3.append(int(pred_scalar > 0.25))\nsubmission['target'] = pred_3\nsubmission.to_csv('submission25.csv', index=False)\nprint(\"submission25 # predicted true\",np.sum(submission['target']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3025850fbd73f94decbd8487d0ff6caab8b4d06b"},"cell_type":"code","source":"pred_3 = []\nfor pred_scalar in pred:\n    for i in range(3):\n        pred_3.append(int(pred_scalar > 0.3))\nsubmission['target'] = pred_3\nsubmission.to_csv('submission3.csv', index=False)\nprint(\"submission3 # predicted true\",np.sum(submission['target']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8363bf90aea8eef1a2b896bb5308abc5dfc5e029"},"cell_type":"code","source":"pred_3 = []\nfor pred_scalar in pred:\n    for i in range(3):\n        pred_3.append(int(pred_scalar > 0.35))\nsubmission['target'] = pred_3\nsubmission.to_csv('submission35.csv', index=False)\nprint(\"submission35 # predicted true\",np.sum(submission['target']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f7f93b59709132e191dc3a7a1904eead1f633d20"},"cell_type":"code","source":"pred_3 = []\nfor pred_scalar in pred:\n    for i in range(3):\n        pred_3.append(int(pred_scalar > 0.40))\nsubmission['target'] = pred_3\nsubmission.to_csv('submission4.csv', index=False)\nprint(\"submission4 # predicted true\",np.sum(submission['target']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"11bc713c900d73e5b4b01a9ef16deef44dc1626c"},"cell_type":"code","source":"f=(1,2)\nnp.asarray(f)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3b3c90b0a62401a882944eddac38b731bccd30bb"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}