{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-06T22:35:57.965506Z","iopub.execute_input":"2022-10-06T22:35:57.965967Z","iopub.status.idle":"2022-10-06T22:35:57.979925Z","shell.execute_reply.started":"2022-10-06T22:35:57.965926Z","shell.execute_reply":"2022-10-06T22:35:57.978367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nfrom random import randint\nimport numpy as np\nimport pandas as pd\nfrom scipy.stats import skew\nfrom sklearn.model_selection import cross_val_score\nfrom sklearn.linear_model import LinearRegression, Ridge, Lasso\nfrom datetime import datetime\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import StratifiedKFold,GridSearchCV,RandomizedSearchCV, train_test_split, RepeatedStratifiedKFold#For splitting\nfrom sklearn.preprocessing import StandardScaler, MinMaxScaler\nfrom sklearn.model_selection import train_test_split\n\nimport gc\nfrom tqdm import tqdm\nfrom sklearn.metrics import fbeta_score, make_scorer\nfrom scipy import stats\nfrom random import randint\nfrom sklearn.metrics import accuracy_score, f1_score, roc_auc_score, plot_roc_curve, plot_confusion_matrix, r2_score, mean_absolute_error,mean_squared_error, recall_score, precision_score\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler, MinMaxScaler\nfrom sklearn.preprocessing import OneHotEncoder, LabelEncoder, OrdinalEncoder\nfrom sklearn.model_selection import train_test_split\nimport gc\n\nfrom sklearn.metrics import fbeta_score, make_scorer\nfrom sklearn.svm import SVR, LinearSVR\nfrom sklearn.neighbors import KNeighborsRegressor\nfrom sklearn.tree import DecisionTreeRegressor\nfrom lightgbm import LGBMRegressor\nfrom sklearn.ensemble import GradientBoostingRegressor\nfrom catboost import CatBoostRegressor, Pool \nfrom sklearn.ensemble import RandomForestRegressor\nfrom xgboost import XGBRegressor\nfrom sklearn.ensemble import AdaBoostRegressor\n\nfrom sklearn.metrics import confusion_matrix, classification_report, ConfusionMatrixDisplay\n\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2022-10-06T20:09:34.322805Z","iopub.execute_input":"2022-10-06T20:09:34.323466Z","iopub.status.idle":"2022-10-06T20:09:36.504157Z","shell.execute_reply.started":"2022-10-06T20:09:34.323425Z","shell.execute_reply":"2022-10-06T20:09:36.502887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n\ndtype= {'bidFloorPrice':'float16',\n'eventTimestamp':'float32', \n'has_won':'float16' ,\n'sentPrice':'float16', \n'winBid':'float16' ,\n'unitDisplayType':'category',\n'brandName':'category',\n'bundleId': 'category',\n'appVersion':'category',\n'correctModelName':'category',\n'countryCode':'category',\n'deviceId':'category',\n'osAndVersion':'category',\n'connectionType':'category',\n'c1':'category',\n'c2':'category',\n'c3':'category',\n'c4':'category',\n'size':'category',\n'mediationProviderVersion':'category',\n 'Month':'category',\n 'Day':'category',\n 'Hour':'category',\n 'Date':'category',\n'Weekday': 'category',\n 'Seconds':'int32',\n        \n'c1std_bidWin':'float16' ,\n'c1max_bidWin':'float16' ,\n'c1min_bidWin':'float16' ,\n'c1mean_bidWin':'float16' ,\n'c1median_bidWin':'float16', \n'c3std_bidWin':'float16' ,\n'c3max_bidWin':'float16' ,\n'c3min_bidWin':'float16' ,\n'c3mean_bidWin':'float16' ,\n'c3median_bidWin':'float16', \n'deviceIdstd_bidWin':'float16' ,\n'deviceIdmax_bidWin':'float16' ,\n'deviceIdmin_bidWin':'float16' ,\n'deviceIdmean_bidWin':'float16' ,\n'deviceIdmedian_bidWin':'float16', \n'unitDisplayTypestd_bidWin':'float16' ,\n'unitDisplayTypemax_bidWin':'float16' ,\n'unitDisplayTypemin_bidWin':'float16' ,\n'unitDisplayTypemean_bidWin':'float16' ,\n'unitDisplayTypemedian_bidWin':'float16', \n'bundleIdstd_bidWin':'float16' ,\n'bundleIdmax_bidWin':'float16',\n'bundleIdmin_bidWin':'float16' ,\n'bundleIdmean_bidWin':'float16' ,\n'bundleIdmedian_bidWin':'float16'}\n\n\ndtype1 ={'bidFloorPrice':'float16',\n'eventTimestamp':'float32', \n'sentPrice':'float16', \n'unitDisplayType':'category',\n'brandName':'category',\n'bundleId': 'category',\n'appVersion':'category',\n'correctModelName':'category',\n'countryCode':'category',\n'deviceId':'category',\n'osAndVersion':'category',\n'connectionType':'category',\n'c1':'category',\n'c2':'category',\n'c3':'category',\n'c4':'category',\n'size':'category',\n'mediationProviderVersion':'category',\n 'Month':'category',\n 'Day':'category',\n 'Hour':'category',\n 'Date':'category',\n'Weekday': 'category',\n 'Seconds':'int32',\n'c1std_bidWin':'float16' ,\n'c1max_bidWin':'float16' ,\n'c1min_bidWin':'float16' ,\n'c1mean_bidWin':'float16' ,\n'c1median_bidWin':'float16', \n'c3std_bidWin':'float16' ,\n'c3max_bidWin':'float16' ,\n'c3min_bidWin':'float16' ,\n'c3mean_bidWin':'float16' ,\n'c3median_bidWin':'float16', \n'deviceIdstd_bidWin':'float16' ,\n'deviceIdmax_bidWin':'float16' ,\n'deviceIdmin_bidWin':'float16' ,\n'deviceIdmean_bidWin':'float16' ,\n'deviceIdmedian_bidWin':'float16', \n'unitDisplayTypestd_bidWin':'float16' ,\n'unitDisplayTypemax_bidWin':'float16' ,\n'unitDisplayTypemin_bidWin':'float16' ,\n'unitDisplayTypemean_bidWin':'float16' ,\n'unitDisplayTypemedian_bidWin':'float16', \n'bundleIdstd_bidWin':'float16' ,\n'bundleIdmax_bidWin':'float16',\n'bundleIdmin_bidWin':'float16' ,\n'bundleIdmean_bidWin':'float16' ,\n'bundleIdmedian_bidWin':'float16'}","metadata":{"execution":{"iopub.status.busy":"2022-10-06T20:10:06.684458Z","iopub.execute_input":"2022-10-06T20:10:06.684900Z","iopub.status.idle":"2022-10-06T20:10:06.698918Z","shell.execute_reply.started":"2022-10-06T20:10:06.684863Z","shell.execute_reply":"2022-10-06T20:10:06.697437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digital-turbine/Downloads2/train1.csv', engine ='c',dtype=dtype)\ntest = pd.read_csv('/kaggle/input/digital-turbine/Downloads2/test1.csv', engine ='c',dtype=dtype1)","metadata":{"execution":{"iopub.status.busy":"2022-10-06T20:11:01.803872Z","iopub.execute_input":"2022-10-06T20:11:01.804854Z","iopub.status.idle":"2022-10-06T20:12:57.652790Z","shell.execute_reply.started":"2022-10-06T20:11:01.804805Z","shell.execute_reply":"2022-10-06T20:12:57.650986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X= train.drop(['has_won', 'winBid'],axis=1).reset_index(drop=True)\ny=train['winBid']","metadata":{"execution":{"iopub.status.busy":"2022-10-06T20:13:49.272969Z","iopub.execute_input":"2022-10-06T20:13:49.273415Z","iopub.status.idle":"2022-10-06T20:13:49.933334Z","shell.execute_reply.started":"2022-10-06T20:13:49.273377Z","shell.execute_reply":"2022-10-06T20:13:49.932133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"categorical_features_indices =np.where(X.dtypes == 'category')[0]\n#categorical_features_indices=np.delete(categorical_features_indices, 0)\n\ncateg_cols = X.columns[categorical_features_indices]\ncateg_cols\n","metadata":{"execution":{"iopub.status.busy":"2022-10-06T20:13:53.337878Z","iopub.execute_input":"2022-10-06T20:13:53.338331Z","iopub.status.idle":"2022-10-06T20:13:53.349714Z","shell.execute_reply.started":"2022-10-06T20:13:53.338292Z","shell.execute_reply":"2022-10-06T20:13:53.348808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import time\nlgb = LGBMRegressor(objective= 'rmse',metric= 'rmse', verbose=1, force_row_wise=True, num_iterations=8800)\nstart_time= time.time()\nlgb.fit(X, y)\nend_time = time.time()\ntraining_time = end_time - start_time\nprint(\"Training time: {} hours\".format(training_time/3600))\n\nlgb_pred = lgb.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-10-06T23:39:33.000578Z","iopub.execute_input":"2022-10-06T23:39:33.001042Z","iopub.status.idle":"2022-10-07T00:35:35.005299Z","shell.execute_reply.started":"2022-10-06T23:39:33.001004Z","shell.execute_reply":"2022-10-07T00:35:35.002796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame(columns=['deviceId', 'winBid'])\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-07T00:37:54.215115Z","iopub.execute_input":"2022-10-07T00:37:54.215612Z","iopub.status.idle":"2022-10-07T00:37:54.226898Z","shell.execute_reply.started":"2022-10-07T00:37:54.215574Z","shell.execute_reply":"2022-10-07T00:37:54.226189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test1 = pd.read_csv('/kaggle/input/digital-turbine-auction-bid-price-prediction/test_data.csv', engine ='c')\n","metadata":{"execution":{"iopub.status.busy":"2022-10-07T00:37:54.240673Z","iopub.execute_input":"2022-10-07T00:37:54.241574Z","iopub.status.idle":"2022-10-07T00:37:54.372257Z","shell.execute_reply.started":"2022-10-07T00:37:54.241539Z","shell.execute_reply":"2022-10-07T00:37:54.370951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.deviceId = test1.deviceId\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-07T00:37:54.374138Z","iopub.execute_input":"2022-10-07T00:37:54.374517Z","iopub.status.idle":"2022-10-07T00:37:54.393391Z","shell.execute_reply.started":"2022-10-07T00:37:54.374482Z","shell.execute_reply":"2022-10-07T00:37:54.392100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.winBid = lgb_pred\nsubmission","metadata":{"execution":{"iopub.status.busy":"2022-10-07T00:37:54.395165Z","iopub.execute_input":"2022-10-07T00:37:54.395493Z","iopub.status.idle":"2022-10-07T00:37:54.408865Z","shell.execute_reply.started":"2022-10-07T00:37:54.395465Z","shell.execute_reply":"2022-10-07T00:37:54.407906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nos.chdir(r'/kaggle/working')\nsubmission.to_csv('submission.csv', index = False)\nfrom IPython.display import FileLink\nFileLink(r'submission.csv')\n#submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-10-07T00:37:54.410682Z","iopub.execute_input":"2022-10-07T00:37:54.410980Z","iopub.status.idle":"2022-10-07T00:37:54.525153Z","shell.execute_reply.started":"2022-10-07T00:37:54.410953Z","shell.execute_reply":"2022-10-07T00:37:54.523756Z"},"trusted":true},"execution_count":null,"outputs":[]}]}