{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# 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\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\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\nimport os\nprint(os.listdir(\"../input\"))\nimport gc\nimport time\nimport logging\nimport datetime\nimport warnings\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport xgboost as xgb\nimport lightgbm as lgb\nfrom scipy import stats\nfrom scipy.signal import hann\nfrom tqdm import tqdm_notebook\nimport matplotlib.pyplot as plt\nfrom scipy.signal import hilbert\nfrom scipy.signal import convolve\nfrom catboost import CatBoostRegressor\nfrom sklearn.kernel_ridge import KernelRidge\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.metrics import mean_absolute_error\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.model_selection import KFold,StratifiedKFold, RepeatedKFold\nwarnings.filterwarnings(\"ignore\")\n\n#from sklearn.linear_model import LinearRegression as lmr\nfrom xgboost import XGBRegressor as xgbr\nfrom sklearn.pipeline import make_pipeline as mpp\nfrom sklearn.preprocessing import Imputer as imp\nfrom sklearn.ensemble import AdaBoostRegressor as adr\nfrom sklearn.model_selection import cross_val_score as cvs\nfrom sklearn.linear_model import Lasso as lss\nfrom sklearn.linear_model import Ridge as rdg\nfrom sklearn.linear_model import ElasticNet as ecn\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"%%time\ntrain = pd.read_csv('../input/train.csv', dtype={'acoustic_data': np.int16, 'time_to_failure': np.float32})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0fcfc95d67098573ece0c4f58e5bc1d064cb5c0d"},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"82b32cdaf6a0bfe998b96e369aecf04fa251fbd1"},"cell_type":"code","source":"rows =150_000\nsgt = int(np.floor(train.shape[0] / rows))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a2a1a721d68f90b10c07b89a42c53a0bfa6c0f61"},"cell_type":"code","source":"#Feature Engeneering\ndef data_feature(arr,abs_values=False):\n    idx = np.array(range(len(arr)))\n    if abs_values:\n        arr = np.abs(arr)\n    lr = LinearRegression()\n    lr.fit(idx.reshape(-1,1),arr)\n    return lr.coef_[0]\n\ndef unknow_func(x,length_sta,length_lta):\n    sta = np.cumsum( x ** 2)\n    sta = np.require(sta,dtype=np.float)# convert to float\n    lta = sta.copy()\n    sta[length_sta:] = sta[length_sta:] - sta[:-length_sta]\n    sta /= length_sta\n    lta[length_lta:] = lta[length_lta:] - lta[:-length_lta]\n    lta /= length_lta\n    # Pad zeros\n    sta[:length_lta - 1] = 0\n    # Avoid division by zero by setting zero values to tiny float\n    dtiny = np.finfo(0.0).tiny\n    idx = lta < dtiny\n    lta[idx] = dtiny\n    return sta / lta","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"636fc2a604d52006d89378aab53e62559a0fe908"},"cell_type":"code","source":"def sigmoid(z):\n    \n    return 1 / (1 + np.exp(-z))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2da6f4c34aa7c9ba5bf22a6a950afcd71c0717f8"},"cell_type":"code","source":"def cost(theta, e, d, lr) :\n    theta = np.matrix(theta) \n    e = np.matrix(e)\n    d = np.matrix(d)\n        \n    fst = np.multiply(-e, np.log(sigmoid(d * theta.T)))\n    scd = np.multiply((1 - e), np.log(1 - sigmoid(d * theta.T)))\n    reg = (lr / 2 * len(e)) * np.sum(np.power(theta[:, 1:theta.shape[1]], 2))\n    \n    return np.sum(fst - scd) / (len(e)) + reg \n\ne = train['acoustic_data'].values[-1]\nf = train['time_to_failure'].values[-1]\n\nef = cost(- 0.04194, e, f, 0.33)\nee = cost(- 0.02624, e, f, 0.33)\n\nprint(ef)\nprint(ee)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6748f5ddaa1c50deaceede40816a52f4635a8908"},"cell_type":"code","source":"def EvalutedHypothesis(theta, e, d, lr) :\n    theta = np.matrix(theta) \n    e = np.matrix(e)\n    d = np.matrix(d)\n        \n    fst = np.multiply(-e, np.log(sigmoid(d * theta.T)))\n    scd = np.multiply((1 - e), np.log(1 - sigmoid(d * theta.T)))\n    reg = (lr / 2 * len(e)) * np.sum(np.power(theta[:, 1:theta.shape[1]], 2))\n    \n    return ((np.sum(fst - scd) ** 2) / (len(e))) + reg \n\naa = EvalutedHypothesis(- 0.04194, e, f, 0.33)\nbb = EvalutedHypothesis(- 0.02624, e, f, 0.33)\n\nprint(aa)\nprint(bb)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cc64d246b8f06da52ad7bf3850bd499e011da369"},"cell_type":"code","source":"xtr = pd.DataFrame(index = range(sgt), dtype = np.float64)\nytr = pd.DataFrame(index = range(sgt), dtype = np.float64, columns = ['time_to_failure'])\n\nmn = train['acoustic_data'].mean()\nsd = train['acoustic_data'].std()\nmx = train['acoustic_data'].max()\nmi = train['acoustic_data'].min()\ntt = np.abs(train['acoustic_data']).sum() ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"de7d28b07b396a6d36c85d6376bce9c255cd7417"},"cell_type":"code","source":"def create_features(seg_id, seg, xtr):\n    X = pd.Series(seg['acoustic_data'].values)\n    zc = np.fft.fft(X)\n    \n    realFFT = np.real(zc)\n    imagFFT = np.imag(zc)\n    \n    xtr.loc[seg_id, 'Sigmoid_call_std'] = sigmoid(X.std())\n    xtr.loc[seg_id, 'Sigmoid_call_mean'] = sigmoid(X.mean())\n    xtr.loc[seg_id, 'Cost_func_trn_std'] = cost(-2.555912182174505, X.std(), sd, 0.33)\n    xtr.loc[seg_id, 'Cost_func_trn_mean'] = cost(-2.555912182174505, X.mean(), mn, 0.33)\n    xtr.loc[seg_id, 'Cost_func_tst_std'] = cost(-1.8537597012091438, X.std(), sd, 0.33)\n    xtr.loc[seg_id, 'Cost_func_tst_mean'] = cost(-1.8537597012091438, X.mean(), mn, 0.33)\n    \n    xtr.loc[seg_id, 'EvalutedHypothesis_func_trn_std'] = EvalutedHypothesis(-6.53268708298804, X.std(), sd, 0.33)\n    xtr.loc[seg_id, 'EvalutedHypothesis_func_trn_mean'] = EvalutedHypothesis(-6.53268708298804, X.mean(), mn, 0.33)\n    xtr.loc[seg_id, 'EvalutedHypothesis_func_tst_std'] = EvalutedHypothesis(-3.436425029827014, X.std(), sd, 0.33)\n    xtr.loc[seg_id, 'EvalutedHypothesis_tst_mean'] = EvalutedHypothesis(-3.436425029827014, X.mean(), mn, 0.33)\n    \n    xtr.loc[seg_id, 'mean'] = X.mean()\n    xtr.loc[seg_id, 'std'] = X.std()\n    xtr.loc[seg_id, 'max'] = X.max()\n    xtr.loc[seg_id, 'min'] = X.min()\n    xtr.loc[seg_id, 'kurtosis'] = X.kurtosis()\n    xtr.loc[seg_id, 'skew'] = X.skew()\n    \n    xtr.loc[seg_id, 'quantile0'] = X.quantile()\n    xtr.loc[seg_id, 'quantile1'] = np.count_nonzero(X < np.quantile(X,0.05))\n    xtr.loc[seg_id, 'quantile2'] = np.count_nonzero(X < np.quantile(X,0.10))\n    xtr.loc[seg_id, 'quantile3'] = np.count_nonzero(X > np.quantile(X,0.15))\n    xtr.loc[seg_id, 'quantile4'] = np.count_nonzero(X > np.quantile(X,0.20))\n    xtr.loc[seg_id, 'quantile5'] = np.count_nonzero(X < np.quantile(X,0.25))\n    xtr.loc[seg_id, 'quantile6'] = np.count_nonzero(X < np.quantile(X,0.30))\n    xtr.loc[seg_id, 'quantile7 '] = np.count_nonzero(X > np.quantile(X,0.35))\n    xtr.loc[seg_id, 'quantile8'] = np.count_nonzero(X > np.quantile(X,0.40))\n    xtr.loc[seg_id, 'quantile9'] = np.count_nonzero(X < np.quantile(X,0.45))\n    xtr.loc[seg_id, 'quantile10'] = np.count_nonzero(X < np.quantile(X,0.50))\n    \n    xtr.loc[seg_id, 'data_feature0'] = data_feature(X)\n    xtr.loc[seg_id, 'data_feature1'] = data_feature(X, abs_values = True)\n    xtr.loc[seg_id, 'unknow_func0'] = unknow_func(X, 500, 10000).mean()\n    xtr.loc[seg_id, 'unknow_func1'] = unknow_func(X, 625, 25000).mean()\n    \n    xtr.loc[seg_id, 'absolute_max'] = np.abs(X).max()\n    xtr.loc[seg_id, 'absolute_min'] = np.abs(X).min()    \n    \n    xtr.loc[seg_id, 'real_mean'] = realFFT.mean()\n    xtr.loc[seg_id, 'real_std'] = realFFT.std()\n    xtr.loc[seg_id, 'real_max'] = realFFT.max()\n    xtr.loc[seg_id, 'real_min'] = realFFT.min()\n    xtr.loc[seg_id, 'image_mean'] = imagFFT.mean()\n    xtr.loc[seg_id, 'image_std'] = imagFFT.std()\n    xtr.loc[seg_id, 'image_max'] = imagFFT.max()\n    xtr.loc[seg_id, 'image_min'] = imagFFT.min()    \n    \n    xtr.loc[seg_id, 'Roll_second_col_50000_std'] = X[:50000].std()\n    xtr.loc[seg_id, 'Roll_first_col_-50000_std'] = X[-50000:].std()\n    xtr.loc[seg_id, 'Roll_second_col_10000_std'] = X[:10000].std()\n    xtr.loc[seg_id, 'Roll_first_col_-10000_std'] = X[-10000:].std()\n    xtr.loc[seg_id, 'Roll_second_col_50000_mean'] = X[:50000].mean()\n    xtr.loc[seg_id, 'Roll_first_col_-50000_mean'] = X[-50000:].mean()\n    xtr.loc[seg_id, 'Roll_second_col_10000_mean'] = X[:10000].mean()\n    xtr.loc[seg_id, 'Roll_first_col_-10000_mean'] = X[-10000:].mean()\n    xtr.loc[seg_id, 'Roll_second_col_50000_min'] = X[:50000].min()\n    xtr.loc[seg_id, 'Roll_first_col_-10000_min'] = X[-50000:].min()\n    xtr.loc[seg_id, 'Roll_second_col_50000_min'] = X[:10000].min()\n    xtr.loc[seg_id, 'Roll_first_col_-10000_min'] = X[-10000:].min()\n    xtr.loc[seg_id, 'Roll_second_col_50000_max'] = X[:50000].max()\n    xtr.loc[seg_id, 'Roll_first_col_-50000_max'] = X[-50000:].max()\n    xtr.loc[seg_id, 'Roll_second_col_10000_max'] = X[:10000].max()\n    xtr.loc[seg_id, 'Roll_first_col_-10000_max'] = X[-10000:].max()\n    \n    for win in [10, 100, 1000] :\n        xrllsd = X.rolling(win).std().dropna().values \n        xrllmn = X.rolling(win).std().dropna().values\n        \n        xtr.loc[seg_id, 'WindowsPartition1.1' + str(win)] = xrllsd.mean()\n        xtr.loc[seg_id, 'WindowsPartition1.2' + str(win)] = xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartitio1.3' + str(win)] = xrllsd.max()\n        xtr.loc[seg_id, 'WindowsPartition1.4' + str(win)] = xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition1.5' + str(win)] = np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition1.6' + str(win)] = np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition1.7' + str(win)] = np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition1.8' + str(win)] = np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition1.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition1.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition1.11' + str(win)] = np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartitio1.12' + str(win)] = xrllsd.mean() - xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartition1.13' + str(win)] = xrllsd.max()  - xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition1.14' + str(win)] = np.quantile(xrllsd, 0.0250) - np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition1.15' + str(win)] = np.quantile(xrllsd, 0.0900) - np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition1.16' + str(win)] = np.quantile(xrllsd, 0.250) - np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition1.17' + str(win)] = np.quantile(xrllsd, 0.210) - np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition1.18' + str(win)] = np.quantile(xrllsd, 0.2575) \n        xtr.loc[seg_id, 'WindowsPartition1.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) - np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition1.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) + np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition1.21' + str(win)] = sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition1.22' + str(win)] = sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition1.23' + str(win)] = sigmoid(xrllsd.std()) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition1.24' + str(win)] = sigmoid(xrllsd.std()) + sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition1.25' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.26' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.27' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.28' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.29' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.30' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.31' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.32' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition1.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition1.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition1.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition1.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition1.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition1.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition1.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition1.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition1.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        \n        xtr.loc[seg_id, 'WindowsPartition2.1' + str(win)] = xrllmn.mean()\n        xtr.loc[seg_id, 'WindowsPartition2.2' + str(win)] = xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition2.3' + str(win)] = xrllmn.max()\n        xtr.loc[seg_id, 'WindowsPartition2.4' + str(win)] = xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition2.5' + str(win)] = np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition2.6' + str(win)] = np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition2.7' + str(win)] = np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition2.8' + str(win)] = np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition2.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition2.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition2.11' + str(win)] = np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition2.12' + str(win)] = xrllmn.mean() - xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition2.13' + str(win)] = xrllmn.max()  - xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition2.14' + str(win)] = np.quantile(xrllmn, 0.0250) - np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition2.15' + str(win)] = np.quantile(xrllmn, 0.0900) - np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition2.16' + str(win)] = np.quantile(xrllmn, 0.250) - np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition2.17' + str(win)] =  np.quantile(xrllmn, 0.210) - np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition2.18' + str(win)] = np.quantile(xrllmn, 0.2575)\n        xtr.loc[seg_id, 'WindowsPartition2.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) - np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition2.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) + np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition2.21' + str(win)] = sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition2.22' + str(win)] = sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition2.23' + str(win)] = sigmoid(xrllmn.std()) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition2.24' + str(win)] = sigmoid(xrllmn.std()) + sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition2.25' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.26' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.27' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.28' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.29' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.30' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.31' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.32' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition2.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition2.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition2.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition2.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition2.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition2.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition2.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition2.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition2.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        \n        \n    for win in [15, 125, 1125] :\n        xrllsd = X.rolling(win).std().dropna().values \n        xrllmn = X.rolling(win).std().dropna().values\n        \n        xtr.loc[seg_id, 'WindowsPartition3.1' + str(win)] = xrllsd.mean()\n        xtr.loc[seg_id, 'WindowsPartition3.2' + str(win)] = xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartition3.3' + str(win)] = xrllsd.max()\n        xtr.loc[seg_id, 'WindowsPartition3.4' + str(win)] = xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition3.5' + str(win)] = np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition3.6' + str(win)] = np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition3.7' + str(win)] = np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition3.8' + str(win)] = np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition3.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition3.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition3.11' + str(win)] = np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition3.12' + str(win)] = xrllsd.mean() - xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartition3.13' + str(win)] = xrllsd.max()  - xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition3.14' + str(win)] = np.quantile(xrllsd, 0.0250) - np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition3.15' + str(win)] = np.quantile(xrllsd, 0.0900) - np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition3.16' + str(win)] = np.quantile(xrllsd, 0.250) - np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition3.17' + str(win)] = np.quantile(xrllsd, 0.210) - np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition3.18' + str(win)] = np.quantile(xrllsd, 0.2575) \n        xtr.loc[seg_id, 'WindowsPartition3.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) - np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition3.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) + np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition3.21' + str(win)] = sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition3.22' + str(win)] = sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition3.23' + str(win)] = sigmoid(xrllsd.std()) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition3.24' + str(win)] = sigmoid(xrllsd.std()) + sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition3.25' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.26' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.27' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.28' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.29' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.30' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.31' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.32' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition3.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition3.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition3.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition3.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition3.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition3.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition3.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition3.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition3.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        \n        xtr.loc[seg_id, 'WindowsPartition4.1' + str(win)] = xrllmn.mean()\n        xtr.loc[seg_id, 'WindowsPartition4.2' + str(win)] = xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition4.3' + str(win)] = xrllmn.max()\n        xtr.loc[seg_id, 'WindowsPartition4.4' + str(win)] = xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition4.5' + str(win)] = np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition4.6' + str(win)] = np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition4.7' + str(win)] = np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition4.8' + str(win)] = np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition4.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition4.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition4.11' + str(win)] = np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition4.12' + str(win)] = xrllmn.mean() - xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition4.13' + str(win)] = xrllmn.max()  - xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition4.14' + str(win)] = np.quantile(xrllmn, 0.0250) - np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition4.15' + str(win)] = np.quantile(xrllmn, 0.0900) - np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition4.16' + str(win)] = np.quantile(xrllmn, 0.250) - np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition4.17' + str(win)] =  np.quantile(xrllmn, 0.210) - np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition4.18' + str(win)] = np.quantile(xrllmn, 0.2575)\n        xtr.loc[seg_id, 'WindowsPartition4.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) - np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition4.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) + np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition4.21' + str(win)] = sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition4.22' + str(win)] = sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition4.23' + str(win)] = sigmoid(xrllmn.std()) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition4.24' + str(win)] = sigmoid(xrllmn.std()) + sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition4.25' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.26' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.27' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.28' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.29' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.30' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.31' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.32' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition4.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition4.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition4.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition4.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition4.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition4.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition4.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition4.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition4.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        \n    for win in [20, 175, 1375] :\n        xrllsd = X.rolling(win).std().dropna().values \n        xrllmn = X.rolling(win).std().dropna().values\n        \n        xtr.loc[seg_id, 'WindowsPartition5.1' + str(win)] = xrllsd.mean()\n        xtr.loc[seg_id, 'WindowsPartition5.2' + str(win)] = xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartitio5.3' + str(win)] = xrllsd.max()\n        xtr.loc[seg_id, 'WindowsPartition5.4' + str(win)] = xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition5.5' + str(win)] = np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition5.6' + str(win)] = np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition5.7' + str(win)] = np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition5.8' + str(win)] = np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition5.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition5.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition5.11' + str(win)] = np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition5.12' + str(win)] = xrllsd.mean() - xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartition5.13' + str(win)] = xrllsd.max()  - xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition5.14' + str(win)] = np.quantile(xrllsd, 0.0250) - np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition5.15' + str(win)] = np.quantile(xrllsd, 0.0900) - np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition5.16' + str(win)] = np.quantile(xrllsd, 0.250) - np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition5.17' + str(win)] = np.quantile(xrllsd, 0.210) - np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition5.18' + str(win)] = np.quantile(xrllsd, 0.2575) \n        xtr.loc[seg_id, 'WindowsPartition5.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) - np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition5.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) + np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition5.21' + str(win)] = sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition5.22' + str(win)] = sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition5.23' + str(win)] = sigmoid(xrllsd.std()) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition5.24' + str(win)] = sigmoid(xrllsd.std()) + sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition5.25' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.26' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.27' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.28' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.29' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.30' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.31' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.32' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition5.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition5.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition5.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition5.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition5.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition5.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition5.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition5.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition5.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        \n        xtr.loc[seg_id, 'WindowsPartition6.1' + str(win)] = xrllmn.mean()\n        xtr.loc[seg_id, 'WindowsPartition6.2' + str(win)] = xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition6.3' + str(win)] = xrllmn.max()\n        xtr.loc[seg_id, 'WindowsPartition6.4' + str(win)] = xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition6.5' + str(win)] = np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition6.6' + str(win)] = np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition6.7' + str(win)] = np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition6.8' + str(win)] = np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition6.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition6.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition6.11' + str(win)] = np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition6.12' + str(win)] = xrllmn.mean() - xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition6.13' + str(win)] = xrllmn.max()  - xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition6.14' + str(win)] = np.quantile(xrllmn, 0.0250) - np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition6.15' + str(win)] = np.quantile(xrllmn, 0.0900) - np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition6.16' + str(win)] = np.quantile(xrllmn, 0.250) - np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition6.17' + str(win)] =  np.quantile(xrllmn, 0.210) - np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition6.18' + str(win)] = np.quantile(xrllmn, 0.2575)\n        xtr.loc[seg_id, 'WindowsPartition6.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) - np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition6.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) + np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition6.21' + str(win)] = sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition6.22' + str(win)] = sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition6.23' + str(win)] = sigmoid(xrllmn.std()) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition6.24' + str(win)] = sigmoid(xrllmn.std()) + sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition6.25' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.26' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.27' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.28' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.29' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.30' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.31' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.32' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition6.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition6.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition6.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition6.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition6.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition6.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition6.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition6.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition6.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        \n    for win in [25, 200, 1500] :\n        xrllsd = X.rolling(win).std().dropna().values \n        xrllmn = X.rolling(win).std().dropna().values\n        \n        xtr.loc[seg_id, 'WindowsPartition7.1' + str(win)] = xrllsd.mean()\n        xtr.loc[seg_id, 'WindowsPartition7.2' + str(win)] = xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartition7.3' + str(win)] = xrllsd.max()\n        xtr.loc[seg_id, 'WindowsPartition7.4' + str(win)] = xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition7.5' + str(win)] = np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition7.6' + str(win)] = np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition7.7' + str(win)] = np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition7.8' + str(win)] = np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition7.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition7.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition7.11' + str(win)] = np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition7.12' + str(win)] = xrllsd.mean() - xrllsd.std()\n        xtr.loc[seg_id, 'WindowsPartition7.13' + str(win)] = xrllsd.max()  - xrllsd.min()\n        xtr.loc[seg_id, 'WindowsPartition7.14' + str(win)] = np.quantile(xrllsd, 0.0250) - np.quantile(xrllsd, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition7.15' + str(win)] = np.quantile(xrllsd, 0.0900) - np.quantile(xrllsd, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition7.16' + str(win)] = np.quantile(xrllsd, 0.250) - np.quantile(xrllsd, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition7.17' + str(win)] = np.quantile(xrllsd, 0.210) - np.quantile(xrllsd, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition7.18' + str(win)] = np.quantile(xrllsd, 0.2575) \n        xtr.loc[seg_id, 'WindowsPartition7.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) - np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition7.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllsd) / xrllsd[:-1]))[0]) + np.abs(xrllsd).max()\n        xtr.loc[seg_id, 'WindowsPartition7.21' + str(win)] = sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition7.22' + str(win)] = sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition7.23' + str(win)] = sigmoid(xrllsd.std()) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition7.24' + str(win)] = sigmoid(xrllsd.std()) + sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition7.25' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.26' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.27' + str(win)] = cost(-2.555912182174505, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.28' + str(win)] = cost(-2.555912182174505, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.29' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.30' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.31' + str(win)] = cost(-1.8537597012091438, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.32' + str(win)] = cost(-1.8537597012091438, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition7.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition7.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition7.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.33) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition7.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition7.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.33) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition7.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition7.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.std(), sd, 0.25) - sigmoid(xrllsd.std())\n        xtr.loc[seg_id, 'WindowsPartition7.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        xtr.loc[seg_id, 'WindowsPartition7.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllsd.mean(), mn, 0.25) - sigmoid(xrllsd.mean())\n        \n        xtr.loc[seg_id, 'WindowsPartition8.1' + str(win)] = xrllmn.mean()\n        xtr.loc[seg_id, 'WindowsPartition8.2' + str(win)] = xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition8.3' + str(win)] = xrllmn.max()\n        xtr.loc[seg_id, 'WindowsPartition8.4' + str(win)] = xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition8.5' + str(win)] = np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition8.6' + str(win)] = np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition8.7' + str(win)] = np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition8.8' + str(win)] = np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition8.9' + str(win)] = np.mean(np.diff(xrllsd))\n        xtr.loc[seg_id, 'WindowsPartition8.10' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0])\n        xtr.loc[seg_id, 'WindowsPartition8.11' + str(win)] = np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition8.12' + str(win)] = xrllmn.mean() - xrllmn.std()\n        xtr.loc[seg_id, 'WindowsPartition8.13' + str(win)] = xrllmn.max()  - xrllmn.min()\n        xtr.loc[seg_id, 'WindowsPartition8.14' + str(win)] = np.quantile(xrllmn, 0.0250) - np.quantile(xrllmn, 0.0125)\n        xtr.loc[seg_id, 'WindowsPartition8.15' + str(win)] = np.quantile(xrllmn, 0.0900) - np.quantile(xrllmn, 0.0750)\n        xtr.loc[seg_id, 'WindowsPartition8.16' + str(win)] = np.quantile(xrllmn, 0.250) - np.quantile(xrllmn, 0.125)\n        xtr.loc[seg_id, 'WindowsPartition8.17' + str(win)] =  np.quantile(xrllmn, 0.210) - np.quantile(xrllmn, 0.105)\n        xtr.loc[seg_id, 'WindowsPartition8.18' + str(win)] = np.quantile(xrllmn, 0.2575)\n        xtr.loc[seg_id, 'WindowsPartition8.19' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) - np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition8.20' + str(win)] = np.mean(np.nonzero((np.diff(xrllmn) / xrllmn[:-1]))[0]) + np.abs(xrllmn).max()\n        xtr.loc[seg_id, 'WindowsPartition8.21' + str(win)] = sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition8.22' + str(win)] = sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition8.23' + str(win)] = sigmoid(xrllmn.std()) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition8.24' + str(win)] = sigmoid(xrllmn.std()) + sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition8.25' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.26' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.27' + str(win)] = cost(-2.555912182174505, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.28' + str(win)] = cost(-2.555912182174505, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.29' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.30' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.31' + str(win)] = cost(-1.8537597012091438, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.32' + str(win)] = cost(-1.8537597012091438, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.33' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.34' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.35' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.36' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.37' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.38' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.39' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33)\n        xtr.loc[seg_id, 'WindowsPartition8.40' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25)\n        xtr.loc[seg_id, 'WindowsPartition8.41' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition8.42' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.33) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition8.43' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition8.44' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.33) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition8.45' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition8.46' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.std(), sd, 0.25) - sigmoid(xrllmn.std())\n        xtr.loc[seg_id, 'WindowsPartition8.47' + str(win)] = EvalutedHypothesis(-6.53268708298804, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())\n        xtr.loc[seg_id, 'WindowsPartition8.48' + str(win)] = EvalutedHypothesis(-3.436425029827014, xrllmn.mean(), mn, 0.25) - sigmoid(xrllmn.mean())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b7b0b85942b262d8ffdf77d5071a2802f9e9bab5","scrolled":false},"cell_type":"code","source":"# iterate over all segments\nfor seg_id in tqdm_notebook(range(sgt)):\n    seg = train.iloc[seg_id * rows : seg_id * rows + rows]\n    create_features(seg_id, seg, xtr)\n    ytr.loc[seg_id, 'time_to_failure'] = seg['time_to_failure'].values[-1]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"921c26d6c0c69cc9776ecc90c1786fe36b828a7e"},"cell_type":"code","source":"xtr.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"np.abs(xtr.corrwith(ytr['time_to_failure'])).sort_values(ascending=False).head(12)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0bd5d6438e60310e89e18e6eb5768b8dea71168f"},"cell_type":"code","source":"scl = StandardScaler()\nscl.fit(xtr)\nxtsc = pd.DataFrame(scl.transform(xtr), columns = xtr.columns)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1f734985cf95189a05e93199ee95cb0a5da90d42"},"cell_type":"code","source":"lm = LinearRegression()\nlm.fit(xtsc, ytr)\n\nlmpr = lm.predict(xtsc)\ns = mean_absolute_error(ytr, lmpr)\nprint(s)\n\nxgbm = xgbr()\nxgbm.fit(xtsc, ytr)\n\nxgbpr = xgbm.predict(xtsc)\nxgbs = mean_absolute_error(ytr, xgbpr)\nprint(xgbs)\n\nlaso = lss(alpha = 0.1)\nlaso.fit(xtsc, ytr)\n\n\nlspr = laso.predict(xtsc)\nlsss = mean_absolute_error(ytr, lspr)\nprint(lsss)\n\nrdgm = rdg()\nrdgm.fit(xtsc, ytr)\n\nrdgr = rdgm.predict(xtsc)\nrdgs = mean_absolute_error(ytr, rdgr)\nprint(rdgs)\n\necnm = ecn()\necnm.fit(xtsc, ytr)\n\necnpr = ecnm.predict(xtsc)\necnms = mean_absolute_error(ytr, ecnpr)\nprint(ecnms)\n\nadrm = adr()\nadrm.fit(xtsc, ytr)\n\nadrpr = adrm.predict(xtsc)\nadrms = mean_absolute_error(ytr, adrpr)\nprint(adrms)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"45d690c7f2416c510df16843bd15dc8614bf7159"},"cell_type":"code","source":"sub = pd.read_csv('../input/sample_submission.csv', index_col='seg_id')\nxtst = pd.DataFrame(columns = xtr.columns, dtype = np.float64, index = sub.index)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2c5a3531ecc480233cd1895bf24695bd10af2a9b"},"cell_type":"code","source":"sub.shape, xtst.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"326f36a438120e8871fc189855fd6772d25ae01f","scrolled":true},"cell_type":"code","source":"for seg_id in tqdm_notebook(xtst.index):\n    seg = pd.read_csv('../input/test/' + seg_id + '.csv')\n    create_features(seg_id, seg, xtst)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1f806273a04dbbaa1619a1bcfba58bdf94087e82"},"cell_type":"code","source":"stx = pd.DataFrame(scl.transform(xtst), columns = xtst.columns)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c7b6fd6c1b78c53966ffa50aa3e0a6738019d740","scrolled":true},"cell_type":"code","source":"stx.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4a0d4a2f7e755f29d5c967c89b936e4cf437e17f"},"cell_type":"code","source":"combo = pd.concat([xtsc, stx])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6560d50e07623877ce4109c89764ec896a692bbb"},"cell_type":"code","source":"nfd = 5\nfds = KFold(n_splits = nfd, shuffle = True, random_state = 33)\ntnc = stx.columns.values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ce367797e5d328c48e0ccd4ce5e6caeebe60b31b"},"cell_type":"code","source":"prms = {'num_leaves': 51,\n         'min_data_in_leaf': 10, \n         'objective':'regression',\n         'max_depth': -1,\n         'learning_rate': 0.001,\n         \"boosting\": \"gbdt\",\n         \"feature_fraction\": 0.91,\n         \"bagging_freq\": 1,\n         \"bagging_fraction\": 0.91,\n         \"bagging_seed\": 42,\n         \"metric\": 'mae',\n         \"lambda_l1\": 0.1,\n         \"verbosity\": -1,\n         \"nthread\": -1,\n         \"random_state\": 33}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"255bdd0e8084cca33518abf70df8eac1b06be9bc"},"cell_type":"code","source":"oof = np.zeros(len(xtsc))\npred = np.zeros(len(stx))\nfeimpf = pd.DataFrame()\n#run model\nfor fold_, (tidx, vidx) in enumerate(fds.split(xtsc,ytr.values)):\n    strLog = \"fold {}\".format(fold_)\n    print(strLog)\n    \n    xtrf, xvl = xtsc.iloc[tidx], xtsc.iloc[vidx]\n    ytrf, yvl = ytr.iloc[tidx], ytr.iloc[vidx]\n\n    model = lgb.LGBMRegressor(**prms, n_estimators = 20000, n_jobs = -1)\n    model.fit(xtrf, ytrf, \n                    eval_set=[(xtrf, ytrf), (xvl, yvl)], eval_metric = 'mae',\n                    verbose = 1000, early_stopping_rounds = 200)\n    oof[vidx] = model.predict(xvl, num_iteration = model.best_iteration_)\n    #feature importance\n    fimpf = pd.DataFrame()\n    fimpf[\"Feature\"] = tnc\n    fimpf[\"importance\"] = model.feature_importances_[:len(tnc)]\n    fimpf[\"fold\"] = fold_ + 1\n    feimpf = pd.concat([feimpf, fimpf], axis=0)\n    #predictions\n    pred += model.predict(stx, num_iteration = model.best_iteration_) / fds.n_splits","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b55f464b6d2835b5d1df1b10d5424d49f705aa25"},"cell_type":"code","source":"def GUIPred(dat) :\n    return((((ab.mean() + cd.mean()) / 2) + ef) + (0.4194 * np.tanh(((dat[\"part20.0\"]) - ef))) - (0.2624\n           * np.sinh(((dat[\"part7.5\"]) - ef)) + (0.2624 * np.cosh(((dat[\"part7.0\"]) - ef)))) + (0.4194 * \n           np.tanh(((dat[\"part10.0\"]) - ef)) - np.tanh(0.4194 - ((dat[\"part10.1\"]) - ef))) + (0.2624 - \n           np.sinh(ef) + np.cosh(ef) - cd.std()) - ((0.2624 - np.sinh(ef) + np.cosh(ef) - ab.std())) - \n           sigmoid(0.4194 - 0.2624) + ((zz.std()) + zz.mean() / (zz.min() + zz.max())) - ((sigmoid(0.4194) * \n           (np.tanh(dat[\"part22.0\"] + (dat[\"part22.1\"] - dat[\"part22.2\"]))) - ef) / pred.mean()) - \n           ((mppr1.std() + mppr1.mean()) - (mppr2.std() + mppr2.mean()) - (mppr3.std() + mppr3.mean()) - \n           (mppr4.std() + mppr4.mean()) - (lm.predict(stx).std() + lm.predict(stx).mean()) - \n           (ecnm.predict(stx).std() + ecnm.predict(stx).mean())) / \n           ((4194  * ttas * ttsm * (np.tanh(dat[\"part15\"])) - (ttas * ttsm * 2624 * (np.tanh(dat[\"part15\"])\n           )))) + (ef + (pred.std() - pred.mean())))\n\nprint(mean_absolute_error(ytr,GUIPred(combo[:xtr.shape[0]])))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b55f464b6d2835b5d1df1b10d5424d49f705aa25"},"cell_type":"markdown","source":"def GUIPred(dat) :\n    return((((ab.mean() + cd.mean()) / 2) + ef) + (0.4194 * np.tanh(((dat[\"part20.0\"]) - ef))) - (0.2624\n           * np.sinh(((dat[\"part7.5\"]) - ef)) + (0.2624 * np.cosh(((dat[\"part7.0\"]) - ef)))) + (0.4194 * \n           np.tanh(((dat[\"part10.0\"]) - ef)) - np.tanh(0.4194 - ((dat[\"part10.1\"]) - ef))) + (0.2624 - \n           np.sinh(ef) + np.cosh(ef) - cd.std()) - ((0.2624 - np.sinh(ef) + np.cosh(ef) - ab.std())) - \n           sigmoid(0.4194 - 0.2624) + ((zz.std()) + zz.mean() / (zz.min() + zz.max())) - ((sigmoid(0.4194) * \n           (np.tanh(dat[\"part22.0\"] + (dat[\"part22.1\"] - dat[\"part22.2\"]))) - ef) / pred.mean()) - \n           ((mppr1.std() + mppr1.mean()) - (mppr2.std() + mppr2.mean()) - (mppr3.std() + mppr3.mean()) - \n           (mppr4.std() + mppr4.mean()) - (lm.predict(stx).std() + lm.predict(stx).mean()) - \n           (ecnm.predict(stx).std() + ecnm.predict(stx).mean())) / \n           ((4194  * ttas * ttsm * (np.tanh(dat[\"part15\"])) - (ttas * ttsm * 2624 * (np.tanh(dat[\"part15\"])\n           )))) + (ef + (pred.std() - pred.mean())))\n\nprint(mean_absolute_error(ytr,GUIPred(combo[:xtr.shape[0]])))"},{"metadata":{"trusted":true,"_uuid":"6c34d2c7fab0184def92a30be74d867b6a3cc9cf"},"cell_type":"code","source":"sub.time_to_failure = pred\nsub.to_csv('sub.csv',index = True)","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}