{"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":"markdown","source":"# Setup","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns \nimport matplotlib as plt\nfrom matplotlib import pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:45:48.337995Z","iopub.execute_input":"2022-07-04T13:45:48.338352Z","iopub.status.idle":"2022-07-04T13:45:49.54504Z","shell.execute_reply.started":"2022-07-04T13:45:48.338322Z","shell.execute_reply":"2022-07-04T13:45:49.543916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load Data ","metadata":{}},{"cell_type":"code","source":"x_train=pd.read_csv('../input/winwinewine/wine_x_train.csv')\nx_test = pd.read_csv('../input/winwinewine/wine_test.csv')\ny_train =pd.read_csv('../input/winwinewine/wine_y_train.csv')\n#y_test = ? #to be predicted\nx = pd.concat([x_train , x_test])\nx.set_index('id' , inplace =True)\ny_train.set_index('id' , inplace =True)\nx['price'] = y_train['price']\ntrain = x.copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:05.376678Z","iopub.execute_input":"2022-07-04T13:50:05.37736Z","iopub.status.idle":"2022-07-04T13:50:06.365411Z","shell.execute_reply.started":"2022-07-04T13:50:05.377325Z","shell.execute_reply":"2022-07-04T13:50:06.364367Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:11.556907Z","iopub.execute_input":"2022-07-04T13:50:11.55733Z","iopub.status.idle":"2022-07-04T13:50:11.563451Z","shell.execute_reply.started":"2022-07-04T13:50:11.557297Z","shell.execute_reply":"2022-07-04T13:50:11.562487Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:11.726749Z","iopub.execute_input":"2022-07-04T13:50:11.727903Z","iopub.status.idle":"2022-07-04T13:50:11.735158Z","shell.execute_reply.started":"2022-07-04T13:50:11.72785Z","shell.execute_reply":"2022-07-04T13:50:11.733965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = train[train.price.isna() == False]\ntest_data = train[train.price.isna()]","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:12.070219Z","iopub.execute_input":"2022-07-04T13:50:12.070619Z","iopub.status.idle":"2022-07-04T13:50:12.091963Z","shell.execute_reply.started":"2022-07-04T13:50:12.070588Z","shell.execute_reply":"2022-07-04T13:50:12.091026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = train_data.append(test_data, ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:12.999759Z","iopub.execute_input":"2022-07-04T13:50:13.000461Z","iopub.status.idle":"2022-07-04T13:50:13.04351Z","shell.execute_reply.started":"2022-07-04T13:50:13.000425Z","shell.execute_reply":"2022-07-04T13:50:13.042597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:13.159606Z","iopub.execute_input":"2022-07-04T13:50:13.160419Z","iopub.status.idle":"2022-07-04T13:50:13.18522Z","shell.execute_reply.started":"2022-07-04T13:50:13.160382Z","shell.execute_reply":"2022-07-04T13:50:13.184415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:13.305319Z","iopub.execute_input":"2022-07-04T13:50:13.305881Z","iopub.status.idle":"2022-07-04T13:50:13.333099Z","shell.execute_reply.started":"2022-07-04T13:50:13.305851Z","shell.execute_reply":"2022-07-04T13:50:13.332164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:13.60071Z","iopub.execute_input":"2022-07-04T13:50:13.601324Z","iopub.status.idle":"2022-07-04T13:50:13.626621Z","shell.execute_reply.started":"2022-07-04T13:50:13.601292Z","shell.execute_reply":"2022-07-04T13:50:13.625675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA","metadata":{}},{"cell_type":"code","source":"df.isnull().sum().sort_values(ascending=False)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:14.157198Z","iopub.execute_input":"2022-07-04T13:50:14.157769Z","iopub.status.idle":"2022-07-04T13:50:14.270905Z","shell.execute_reply.started":"2022-07-04T13:50:14.157736Z","shell.execute_reply":"2022-07-04T13:50:14.269833Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"counts = df[\"country\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:14.471974Z","iopub.execute_input":"2022-07-04T13:50:14.472735Z","iopub.status.idle":"2022-07-04T13:50:14.490917Z","shell.execute_reply.started":"2022-07-04T13:50:14.472696Z","shell.execute_reply":"2022-07-04T13:50:14.489671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def country_map(x) : \n    if counts[x]<100 :\n        return 'others'\n    else : \n        return x \ndf['country'].fillna('US' , inplace = True)\ndf['country'] = df[\"country\"].apply(country_map)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:14.815322Z","iopub.execute_input":"2022-07-04T13:50:14.816122Z","iopub.status.idle":"2022-07-04T13:50:15.350744Z","shell.execute_reply.started":"2022-07-04T13:50:14.816072Z","shell.execute_reply":"2022-07-04T13:50:15.3498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.country.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:15.352565Z","iopub.execute_input":"2022-07-04T13:50:15.352852Z","iopub.status.idle":"2022-07-04T13:50:15.372759Z","shell.execute_reply.started":"2022-07-04T13:50:15.352826Z","shell.execute_reply":"2022-07-04T13:50:15.371636Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.price.hist()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:15.374605Z","iopub.execute_input":"2022-07-04T13:50:15.374923Z","iopub.status.idle":"2022-07-04T13:50:15.576155Z","shell.execute_reply.started":"2022-07-04T13:50:15.374885Z","shell.execute_reply":"2022-07-04T13:50:15.575415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,6))\nsns.boxplot(x = 'country', y = 'price', data = df )\nplt.xticks(rotation = 90)\n#plt.ylim(top = 0.1)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:15.577649Z","iopub.execute_input":"2022-07-04T13:50:15.578103Z","iopub.status.idle":"2022-07-04T13:50:16.229734Z","shell.execute_reply.started":"2022-07-04T13:50:15.578075Z","shell.execute_reply":"2022-07-04T13:50:16.228646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.231777Z","iopub.execute_input":"2022-07-04T13:50:16.232098Z","iopub.status.idle":"2022-07-04T13:50:16.301924Z","shell.execute_reply.started":"2022-07-04T13:50:16.232068Z","shell.execute_reply":"2022-07-04T13:50:16.301184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"variety\"].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.303045Z","iopub.execute_input":"2022-07-04T13:50:16.303516Z","iopub.status.idle":"2022-07-04T13:50:16.324486Z","shell.execute_reply.started":"2022-07-04T13:50:16.303487Z","shell.execute_reply":"2022-07-04T13:50:16.323415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[\"variety\"].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.326639Z","iopub.execute_input":"2022-07-04T13:50:16.326941Z","iopub.status.idle":"2022-07-04T13:50:16.344057Z","shell.execute_reply.started":"2022-07-04T13:50:16.326915Z","shell.execute_reply":"2022-07-04T13:50:16.343032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.34542Z","iopub.execute_input":"2022-07-04T13:50:16.345745Z","iopub.status.idle":"2022-07-04T13:50:16.351836Z","shell.execute_reply.started":"2022-07-04T13:50:16.345715Z","shell.execute_reply":"2022-07-04T13:50:16.351176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import preprocessing","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.426687Z","iopub.execute_input":"2022-07-04T13:50:16.427323Z","iopub.status.idle":"2022-07-04T13:50:16.431404Z","shell.execute_reply.started":"2022-07-04T13:50:16.427287Z","shell.execute_reply":"2022-07-04T13:50:16.430456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_encoder = preprocessing.LabelEncoder()\ndf['country']= label_encoder.fit_transform(df['country'])\n  ","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.698974Z","iopub.execute_input":"2022-07-04T13:50:16.699354Z","iopub.status.idle":"2022-07-04T13:50:16.742829Z","shell.execute_reply.started":"2022-07-04T13:50:16.699325Z","shell.execute_reply":"2022-07-04T13:50:16.741848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(2)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:16.85996Z","iopub.execute_input":"2022-07-04T13:50:16.860343Z","iopub.status.idle":"2022-07-04T13:50:16.879412Z","shell.execute_reply.started":"2022-07-04T13:50:16.860314Z","shell.execute_reply":"2022-07-04T13:50:16.8785Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(\"region_2\", axis='columns', inplace=True)\ndf.drop(\"description\", axis='columns', inplace=True)\n\n","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:17.176844Z","iopub.execute_input":"2022-07-04T13:50:17.177794Z","iopub.status.idle":"2022-07-04T13:50:17.218923Z","shell.execute_reply.started":"2022-07-04T13:50:17.17774Z","shell.execute_reply":"2022-07-04T13:50:17.218087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(\"title\", axis='columns', inplace=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:17.384974Z","iopub.execute_input":"2022-07-04T13:50:17.385701Z","iopub.status.idle":"2022-07-04T13:50:17.398058Z","shell.execute_reply.started":"2022-07-04T13:50:17.385665Z","shell.execute_reply":"2022-07-04T13:50:17.397172Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['designation'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:17.599997Z","iopub.execute_input":"2022-07-04T13:50:17.600706Z","iopub.status.idle":"2022-07-04T13:50:17.626574Z","shell.execute_reply.started":"2022-07-04T13:50:17.600671Z","shell.execute_reply":"2022-07-04T13:50:17.625421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['designation'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:17.820011Z","iopub.execute_input":"2022-07-04T13:50:17.820401Z","iopub.status.idle":"2022-07-04T13:50:17.84067Z","shell.execute_reply.started":"2022-07-04T13:50:17.820369Z","shell.execute_reply":"2022-07-04T13:50:17.839435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['designation'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:18.035168Z","iopub.execute_input":"2022-07-04T13:50:18.03557Z","iopub.status.idle":"2022-07-04T13:50:18.071457Z","shell.execute_reply.started":"2022-07-04T13:50:18.035539Z","shell.execute_reply":"2022-07-04T13:50:18.070521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(\"designation\", axis='columns', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:18.243368Z","iopub.execute_input":"2022-07-04T13:50:18.244439Z","iopub.status.idle":"2022-07-04T13:50:18.256031Z","shell.execute_reply.started":"2022-07-04T13:50:18.2444Z","shell.execute_reply":"2022-07-04T13:50:18.254986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(\"winery\", axis='columns', inplace=True)\ndf.drop(\"region_1\", axis='columns', inplace=True)\ndf.drop(\"province\", axis='columns', inplace=True)\ndf.drop(\"taster_twitter_handle\", axis='columns', inplace=True)\ndf.drop(\"taster_name\", axis='columns', inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:18.452858Z","iopub.execute_input":"2022-07-04T13:50:18.453277Z","iopub.status.idle":"2022-07-04T13:50:18.479596Z","shell.execute_reply.started":"2022-07-04T13:50:18.453239Z","shell.execute_reply":"2022-07-04T13:50:18.478596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:18.66367Z","iopub.execute_input":"2022-07-04T13:50:18.664619Z","iopub.status.idle":"2022-07-04T13:50:18.681264Z","shell.execute_reply.started":"2022-07-04T13:50:18.664572Z","shell.execute_reply":"2022-07-04T13:50:18.680178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['variety'].nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:18.870016Z","iopub.execute_input":"2022-07-04T13:50:18.87095Z","iopub.status.idle":"2022-07-04T13:50:18.887578Z","shell.execute_reply.started":"2022-07-04T13:50:18.870909Z","shell.execute_reply":"2022-07-04T13:50:18.886291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['variety'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:33.136562Z","iopub.execute_input":"2022-07-04T13:50:33.136959Z","iopub.status.idle":"2022-07-04T13:50:33.156296Z","shell.execute_reply.started":"2022-07-04T13:50:33.136926Z","shell.execute_reply":"2022-07-04T13:50:33.1552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import preprocessing\nle = preprocessing.LabelEncoder()\ndf['variety']= le.fit_transform(df['variety'])\n  \n","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:33.478556Z","iopub.execute_input":"2022-07-04T13:50:33.479309Z","iopub.status.idle":"2022-07-04T13:50:33.518336Z","shell.execute_reply.started":"2022-07-04T13:50:33.479263Z","shell.execute_reply":"2022-07-04T13:50:33.517441Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sp_untransformed = sns.distplot(x['price'])","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:33.936084Z","iopub.execute_input":"2022-07-04T13:50:33.936864Z","iopub.status.idle":"2022-07-04T13:50:34.479191Z","shell.execute_reply.started":"2022-07-04T13:50:33.936815Z","shell.execute_reply":"2022-07-04T13:50:34.478141Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"log_transformed = np.log(df['price'])","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:34.481713Z","iopub.execute_input":"2022-07-04T13:50:34.482155Z","iopub.status.idle":"2022-07-04T13:50:34.488014Z","shell.execute_reply.started":"2022-07-04T13:50:34.482094Z","shell.execute_reply":"2022-07-04T13:50:34.486906Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sp_transformed = sns.distplot(log_transformed)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:34.489634Z","iopub.execute_input":"2022-07-04T13:50:34.490058Z","iopub.status.idle":"2022-07-04T13:50:35.018713Z","shell.execute_reply.started":"2022-07-04T13:50:34.49002Z","shell.execute_reply":"2022-07-04T13:50:35.017731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import MinMaxScaler\nfrom sklearn.preprocessing import StandardScaler","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:38.240059Z","iopub.execute_input":"2022-07-04T13:50:38.240449Z","iopub.status.idle":"2022-07-04T13:50:38.245459Z","shell.execute_reply.started":"2022-07-04T13:50:38.240418Z","shell.execute_reply":"2022-07-04T13:50:38.244344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(x=x['points'])","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:38.568147Z","iopub.execute_input":"2022-07-04T13:50:38.569284Z","iopub.status.idle":"2022-07-04T13:50:38.6868Z","shell.execute_reply.started":"2022-07-04T13:50:38.569229Z","shell.execute_reply":"2022-07-04T13:50:38.685632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(x=x['price'])","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:38.781927Z","iopub.execute_input":"2022-07-04T13:50:38.783443Z","iopub.status.idle":"2022-07-04T13:50:38.947738Z","shell.execute_reply.started":"2022-07-04T13:50:38.783392Z","shell.execute_reply":"2022-07-04T13:50:38.946506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"price = x.plot.scatter(x='points',\n                      y='price')","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:38.994226Z","iopub.execute_input":"2022-07-04T13:50:38.995344Z","iopub.status.idle":"2022-07-04T13:50:39.394858Z","shell.execute_reply.started":"2022-07-04T13:50:38.995293Z","shell.execute_reply":"2022-07-04T13:50:39.394096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby('country')['price'].agg(['mean','count','std','min','max'])","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:39.396139Z","iopub.execute_input":"2022-07-04T13:50:39.396802Z","iopub.status.idle":"2022-07-04T13:50:39.420033Z","shell.execute_reply.started":"2022-07-04T13:50:39.396771Z","shell.execute_reply":"2022-07-04T13:50:39.418955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X= df.drop(labels = 'price',axis = 1).values\ny= df.price","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:39.549458Z","iopub.execute_input":"2022-07-04T13:50:39.550243Z","iopub.status.idle":"2022-07-04T13:50:39.558755Z","shell.execute_reply.started":"2022-07-04T13:50:39.550207Z","shell.execute_reply":"2022-07-04T13:50:39.557632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:39.938753Z","iopub.execute_input":"2022-07-04T13:50:39.939871Z","iopub.status.idle":"2022-07-04T13:50:39.954621Z","shell.execute_reply.started":"2022-07-04T13:50:39.939828Z","shell.execute_reply":"2022-07-04T13:50:39.953304Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = df[df.price.isna() == False]\ntest_df= df[df.price.isna()]","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:41.654675Z","iopub.execute_input":"2022-07-04T13:50:41.655041Z","iopub.status.idle":"2022-07-04T13:50:41.66408Z","shell.execute_reply.started":"2022-07-04T13:50:41.65501Z","shell.execute_reply":"2022-07-04T13:50:41.663209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:42.351098Z","iopub.execute_input":"2022-07-04T13:50:42.351762Z","iopub.status.idle":"2022-07-04T13:50:42.368027Z","shell.execute_reply.started":"2022-07-04T13:50:42.351714Z","shell.execute_reply":"2022-07-04T13:50:42.366884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:50:42.692292Z","iopub.execute_input":"2022-07-04T13:50:42.692853Z","iopub.status.idle":"2022-07-04T13:50:42.696568Z","shell.execute_reply.started":"2022-07-04T13:50:42.692822Z","shell.execute_reply":"2022-07-04T13:50:42.695657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.drop('Unnamed: 0' , 1 , inplace = True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X= train_df.drop(labels = 'price',axis = 1).values\ny= train_df.price","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:52:42.499015Z","iopub.execute_input":"2022-07-04T13:52:42.49955Z","iopub.status.idle":"2022-07-04T13:52:42.508231Z","shell.execute_reply.started":"2022-07-04T13:52:42.499503Z","shell.execute_reply":"2022-07-04T13:52:42.50704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size = 0.3)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:52:43.493688Z","iopub.execute_input":"2022-07-04T13:52:43.494371Z","iopub.status.idle":"2022-07-04T13:52:43.507863Z","shell.execute_reply.started":"2022-07-04T13:52:43.494333Z","shell.execute_reply":"2022-07-04T13:52:43.506985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:52:44.066345Z","iopub.execute_input":"2022-07-04T13:52:44.066932Z","iopub.status.idle":"2022-07-04T13:52:44.073738Z","shell.execute_reply.started":"2022-07-04T13:52:44.066898Z","shell.execute_reply":"2022-07-04T13:52:44.0725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = LinearRegression()\nmodel.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:52:45.01518Z","iopub.execute_input":"2022-07-04T13:52:45.01554Z","iopub.status.idle":"2022-07-04T13:52:45.028754Z","shell.execute_reply.started":"2022-07-04T13:52:45.015511Z","shell.execute_reply":"2022-07-04T13:52:45.027805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\nfrom math import sqrt\n# calculate rmse on the training set \ny_train_hat = model.predict(X_train)\nrmse_train = sqrt(mean_squared_error(y_train_hat, y_train)) \nprint(f'training score = {rmse_train}')\n\n# calculate rmse on the valid set \ny_valid_hat = model.predict(X_valid)\nrmse_vaild = sqrt(mean_squared_error(y_valid_hat, y_valid)) \nprint(f'validation score = {rmse_vaild}')","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:52:45.653967Z","iopub.execute_input":"2022-07-04T13:52:45.654363Z","iopub.status.idle":"2022-07-04T13:52:45.673394Z","shell.execute_reply.started":"2022-07-04T13:52:45.654332Z","shell.execute_reply":"2022-07-04T13:52:45.672167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#make submission \ny_test = model.predict(test_df.drop(['Unnamed: 0','price'] , 1 ).values)\ntest_df['price'] = y_test\ntest_df.index.name = 'id'\nsub = test_df[['price']].reset_index()\nsub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:53:13.386128Z","iopub.execute_input":"2022-07-04T13:53:13.386508Z","iopub.status.idle":"2022-07-04T13:53:13.543011Z","shell.execute_reply.started":"2022-07-04T13:53:13.386476Z","shell.execute_reply":"2022-07-04T13:53:13.542182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub","metadata":{"execution":{"iopub.status.busy":"2022-07-04T13:53:14.793547Z","iopub.execute_input":"2022-07-04T13:53:14.794247Z","iopub.status.idle":"2022-07-04T13:53:14.806884Z","shell.execute_reply.started":"2022-07-04T13:53:14.794214Z","shell.execute_reply":"2022-07-04T13:53:14.80582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}