{"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\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-08-14T05:43:32.733470Z","iopub.execute_input":"2022-08-14T05:43:32.734732Z","iopub.status.idle":"2022-08-14T05:43:32.745109Z","shell.execute_reply.started":"2022-08-14T05:43:32.734687Z","shell.execute_reply":"2022-08-14T05:43:32.743802Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n%matplotlib inline\nimport matplotlib.style\nmatplotlib.style.use('classic')\n\nfrom sklearn.decomposition import PCA\nfrom sklearn.impute import SimpleImputer\nfrom sklearn import preprocessing\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.preprocessing import LabelEncoder","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:32.760128Z","iopub.execute_input":"2022-08-14T05:43:32.761457Z","iopub.status.idle":"2022-08-14T05:43:33.789945Z","shell.execute_reply.started":"2022-08-14T05:43:32.761405Z","shell.execute_reply":"2022-08-14T05:43:33.788552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data = pd.read_csv(\"/kaggle/input/house-prices-advanced-regression-techniques/train.csv\")\nData.head()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:33.791947Z","iopub.execute_input":"2022-08-14T05:43:33.792374Z","iopub.status.idle":"2022-08-14T05:43:33.875146Z","shell.execute_reply.started":"2022-08-14T05:43:33.792309Z","shell.execute_reply":"2022-08-14T05:43:33.873857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"A parallel coordinates plot displays the relationships between variables in parallel.\nArrange the coordinates with each variable on the vertical axis in parallel, and connect the coordinates of the elements with line segments.\nWhen visualizing the relationship of data, a scatter plot is suitable for two variables, but a parallel coordinate plot is suitable for visualizing the relationship of multiple variables.","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"#parallel coordinates plot \nimport plotly.graph_objects as go\nimport plotly.express as px\na=Data\ncol_1=Data.select_dtypes(exclude ='object').columns\ncol_1=col_1.drop(['HalfBath','BsmtFullBath','BsmtHalfBath','BedroomAbvGr','KitchenAbvGr','TotRmsAbvGrd','EnclosedPorch'])\nfig = go.Figure(data=go.Parcoords(line = dict(color = a['SalePrice'], colorscale =px.colors.sequential.Reds),\n        dimensions = [dict(label=col, values=a[col]) for col in col_1]))\nfig.update_layout(title=\"Dates\")\nfig.update_layout(autosize=False,width=200,height=600)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:33.876590Z","iopub.execute_input":"2022-08-14T05:43:33.876986Z","iopub.status.idle":"2022-08-14T05:43:35.288728Z","shell.execute_reply.started":"2022-08-14T05:43:33.876948Z","shell.execute_reply":"2022-08-14T05:43:35.287411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:35.291756Z","iopub.execute_input":"2022-08-14T05:43:35.292815Z","iopub.status.idle":"2022-08-14T05:43:35.404910Z","shell.execute_reply.started":"2022-08-14T05:43:35.292763Z","shell.execute_reply":"2022-08-14T05:43:35.403693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:35.406620Z","iopub.execute_input":"2022-08-14T05:43:35.407053Z","iopub.status.idle":"2022-08-14T05:43:35.433600Z","shell.execute_reply.started":"2022-08-14T05:43:35.407017Z","shell.execute_reply":"2022-08-14T05:43:35.432405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(25, 25))\nsns.heatmap(Data.corr(), annot = True)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:35.434884Z","iopub.execute_input":"2022-08-14T05:43:35.435921Z","iopub.status.idle":"2022-08-14T05:43:42.044042Z","shell.execute_reply.started":"2022-08-14T05:43:35.435879Z","shell.execute_reply":"2022-08-14T05:43:42.042753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### check the outlier ","metadata":{}},{"cell_type":"code","source":"fig,ax = plt.subplots(4,1,figsize=(20,12))\nData.iloc[:,0:20].plot.box(ax = ax[0])\nData.iloc[:,20:40].plot.box(ax = ax[1])\nData.iloc[:,40:60].plot.box(ax = ax[2])\nData.iloc[:,60:].plot.box(ax = ax[3])","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:42.045870Z","iopub.execute_input":"2022-08-14T05:43:42.046294Z","iopub.status.idle":"2022-08-14T05:43:43.128268Z","shell.execute_reply.started":"2022-08-14T05:43:42.046256Z","shell.execute_reply":"2022-08-14T05:43:43.126574Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#remove outlier\nfor i in Data.select_dtypes(exclude='object').columns.drop(['Id','1stFlrSF','2ndFlrSF','3SsnPorch']):\n    # IQR\n    q1=Data.loc[:,i].quantile(.25)\n    q3=Data.loc[:,i].quantile(.75)\n    iqr=q3-q1\n    # boundary(upper)\n    upper = q3+iqr*3.0\n    # boundary(lower)\n    lower = q1-iqr*3.0\n    if upper != lower:\n        Data = Data.query('@lower < {} < @upper'.format(i))\n        print(len(Data),i,lower,upper)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:43.130069Z","iopub.execute_input":"2022-08-14T05:43:43.130463Z","iopub.status.idle":"2022-08-14T05:43:43.451689Z","shell.execute_reply.started":"2022-08-14T05:43:43.130426Z","shell.execute_reply":"2022-08-14T05:43:43.450402Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# re-check\nfig,ax = plt.subplots(4,1,figsize=(20,12))\nData.iloc[:,0:20].plot.box(ax = ax[0])\nData.iloc[:,20:40].plot.box(ax = ax[1])\nData.iloc[:,40:60].plot.box(ax = ax[2])\nData.iloc[:,60:].plot.box(ax = ax[3])","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:43.453055Z","iopub.execute_input":"2022-08-14T05:43:43.453442Z","iopub.status.idle":"2022-08-14T05:43:44.586768Z","shell.execute_reply.started":"2022-08-14T05:43:43.453374Z","shell.execute_reply":"2022-08-14T05:43:44.585197Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Shape = ',Data.shape)\nencode_columns = list(Data.select_dtypes(exclude='object').columns)\nDrop=[]\nfor i in encode_columns:\n    if((Data[i].corr(Data['SalePrice']) <= 0.07) and (Data[i].corr(Data['SalePrice'])>= -0.07)):\n        #New_Data.drop(i, axis=1, inplace=True)\n        Drop.append(i)\n        print(i)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:44.591178Z","iopub.execute_input":"2022-08-14T05:43:44.592358Z","iopub.status.idle":"2022-08-14T05:43:44.622729Z","shell.execute_reply.started":"2022-08-14T05:43:44.592277Z","shell.execute_reply":"2022-08-14T05:43:44.621339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.drop(Drop, axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:44.624590Z","iopub.execute_input":"2022-08-14T05:43:44.624961Z","iopub.status.idle":"2022-08-14T05:43:44.632253Z","shell.execute_reply.started":"2022-08-14T05:43:44.624926Z","shell.execute_reply":"2022-08-14T05:43:44.630898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Shape = ',Data.shape)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:44.634128Z","iopub.execute_input":"2022-08-14T05:43:44.635470Z","iopub.status.idle":"2022-08-14T05:43:44.644894Z","shell.execute_reply.started":"2022-08-14T05:43:44.635421Z","shell.execute_reply":"2022-08-14T05:43:44.643579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:44.646507Z","iopub.execute_input":"2022-08-14T05:43:44.647237Z","iopub.status.idle":"2022-08-14T05:43:44.670578Z","shell.execute_reply.started":"2022-08-14T05:43:44.647124Z","shell.execute_reply":"2022-08-14T05:43:44.669582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Check for missing values","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(figsize=(60, 50))\nsns.heatmap(Data.isnull(),yticklabels = False,cbar = False)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:44.672219Z","iopub.execute_input":"2022-08-14T05:43:44.672572Z","iopub.status.idle":"2022-08-14T05:43:47.063531Z","shell.execute_reply.started":"2022-08-14T05:43:44.672541Z","shell.execute_reply":"2022-08-14T05:43:47.062224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = Data.isnull().sum()\nmissing = [[name,i] for name,i in zip(check.index,check) if i != 0]       \nmissing","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.065729Z","iopub.execute_input":"2022-08-14T05:43:47.066441Z","iopub.status.idle":"2022-08-14T05:43:47.079122Z","shell.execute_reply.started":"2022-08-14T05:43:47.066404Z","shell.execute_reply":"2022-08-14T05:43:47.077558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_data = [missing[i][0] for i in range(len(missing)) if missing[i][1] > 500]\nprint(missing_data)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.080622Z","iopub.execute_input":"2022-08-14T05:43:47.081021Z","iopub.status.idle":"2022-08-14T05:43:47.091548Z","shell.execute_reply.started":"2022-08-14T05:43:47.080983Z","shell.execute_reply":"2022-08-14T05:43:47.089898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_data","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.092721Z","iopub.execute_input":"2022-08-14T05:43:47.093901Z","iopub.status.idle":"2022-08-14T05:43:47.106470Z","shell.execute_reply.started":"2022-08-14T05:43:47.093846Z","shell.execute_reply":"2022-08-14T05:43:47.104684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data = Data.drop(missing_data,axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.108414Z","iopub.execute_input":"2022-08-14T05:43:47.108884Z","iopub.status.idle":"2022-08-14T05:43:47.117767Z","shell.execute_reply.started":"2022-08-14T05:43:47.108835Z","shell.execute_reply":"2022-08-14T05:43:47.116737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.119466Z","iopub.execute_input":"2022-08-14T05:43:47.120230Z","iopub.status.idle":"2022-08-14T05:43:47.144165Z","shell.execute_reply.started":"2022-08-14T05:43:47.120182Z","shell.execute_reply":"2022-08-14T05:43:47.142922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Encode categorical variables\ndef label_encode_columns(df, columns):\n    encoders = {}\n    for col in columns:\n        le = LabelEncoder().fit(df[col])\n        df[col] = le.transform(df[col])\n        encoders[col] = le\n    return df, encoders\n\nencode_columns = list(Data.select_dtypes(['object']).columns)\ncol=Data.columns\nData, encoders = label_encode_columns(df=Data, columns=encode_columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.145805Z","iopub.execute_input":"2022-08-14T05:43:47.146503Z","iopub.status.idle":"2022-08-14T05:43:47.188414Z","shell.execute_reply.started":"2022-08-14T05:43:47.146454Z","shell.execute_reply":"2022-08-14T05:43:47.187120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Interpolation of missing values\nimp = SimpleImputer(missing_values=np.NAN, strategy='mean')\nimp = imp.fit(Data)\nData = imp.transform(Data)\nData= np.reshape(Data,(len(Data),len(Data[0])))\nData = pd.DataFrame(Data,columns=col)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.189792Z","iopub.execute_input":"2022-08-14T05:43:47.190886Z","iopub.status.idle":"2022-08-14T05:43:47.206166Z","shell.execute_reply.started":"2022-08-14T05:43:47.190842Z","shell.execute_reply":"2022-08-14T05:43:47.204856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#check\nfig, ax = plt.subplots(figsize=(60, 50))\nsns.heatmap(Data.isnull(),yticklabels = False,cbar = False)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:47.208048Z","iopub.execute_input":"2022-08-14T05:43:47.208807Z","iopub.status.idle":"2022-08-14T05:43:49.324223Z","shell.execute_reply.started":"2022-08-14T05:43:47.208764Z","shell.execute_reply":"2022-08-14T05:43:49.322610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=Data.loc[:,'SalePrice']\nX=Data.drop('SalePrice',axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.326096Z","iopub.execute_input":"2022-08-14T05:43:49.326598Z","iopub.status.idle":"2022-08-14T05:43:49.333715Z","shell.execute_reply.started":"2022-08-14T05:43:49.326547Z","shell.execute_reply":"2022-08-14T05:43:49.332412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Preparing test data and preprocessing","metadata":{}},{"cell_type":"code","source":"Test_Data = pd.read_csv('/kaggle//input/house-prices-advanced-regression-techniques/test.csv')\nTest_Data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.335839Z","iopub.execute_input":"2022-08-14T05:43:49.336293Z","iopub.status.idle":"2022-08-14T05:43:49.389349Z","shell.execute_reply.started":"2022-08-14T05:43:49.336248Z","shell.execute_reply":"2022-08-14T05:43:49.387838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check = Test_Data.isnull().sum()\nmissing = [[name,i] for name,i in zip(check.index,check) if i != 0]  \nmissing","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.390930Z","iopub.execute_input":"2022-08-14T05:43:49.391300Z","iopub.status.idle":"2022-08-14T05:43:49.408358Z","shell.execute_reply.started":"2022-08-14T05:43:49.391265Z","shell.execute_reply":"2022-08-14T05:43:49.406819Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data.drop(Drop, axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.411769Z","iopub.execute_input":"2022-08-14T05:43:49.412718Z","iopub.status.idle":"2022-08-14T05:43:49.420120Z","shell.execute_reply.started":"2022-08-14T05:43:49.412675Z","shell.execute_reply":"2022-08-14T05:43:49.419006Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_data = [missing[i][0] for i in range(len(missing)) if missing[i][1] > 500]\nprint(missing_data)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.421457Z","iopub.execute_input":"2022-08-14T05:43:49.421916Z","iopub.status.idle":"2022-08-14T05:43:49.432371Z","shell.execute_reply.started":"2022-08-14T05:43:49.421883Z","shell.execute_reply":"2022-08-14T05:43:49.431022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data.drop(missing_data, axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.439650Z","iopub.execute_input":"2022-08-14T05:43:49.440059Z","iopub.status.idle":"2022-08-14T05:43:49.449783Z","shell.execute_reply.started":"2022-08-14T05:43:49.440018Z","shell.execute_reply":"2022-08-14T05:43:49.448363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Test_Data.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.450828Z","iopub.execute_input":"2022-08-14T05:43:49.451201Z","iopub.status.idle":"2022-08-14T05:43:49.475880Z","shell.execute_reply.started":"2022-08-14T05:43:49.451164Z","shell.execute_reply":"2022-08-14T05:43:49.474396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Encode categorical variables\nencode_columns = list(Test_Data.select_dtypes(['object']).columns)\ncol=Test_Data.columns\nTest_Data, encoders = label_encode_columns(df=Test_Data, columns=encode_columns)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.479203Z","iopub.execute_input":"2022-08-14T05:43:49.480259Z","iopub.status.idle":"2022-08-14T05:43:49.523304Z","shell.execute_reply.started":"2022-08-14T05:43:49.480216Z","shell.execute_reply":"2022-08-14T05:43:49.522096Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Interpolation of missing values\nimp = SimpleImputer(missing_values=np.NAN, strategy='mean')\nimp = imp.fit(Test_Data)\nX_Test = imp.transform(Test_Data)\nX_Test= np.reshape(X_Test,(len(X_Test),len(X_Test[0])))\nX_Test = pd.DataFrame(X_Test,columns=col)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.524479Z","iopub.execute_input":"2022-08-14T05:43:49.525316Z","iopub.status.idle":"2022-08-14T05:43:49.541570Z","shell.execute_reply.started":"2022-08-14T05:43:49.525280Z","shell.execute_reply":"2022-08-14T05:43:49.540469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Preparing correct answer labels","metadata":{}},{"cell_type":"code","source":"Test_Data = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/sample_submission.csv',skiprows= 0)\nprint(Test_Data)\nans=Test_Data.iloc[:,1]\n\nprint(ans.shape)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.542792Z","iopub.execute_input":"2022-08-14T05:43:49.543605Z","iopub.status.idle":"2022-08-14T05:43:49.563395Z","shell.execute_reply.started":"2022-08-14T05:43:49.543567Z","shell.execute_reply":"2022-08-14T05:43:49.562168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# other regression","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\nfrom sklearn.svm import SVR\nfrom sklearn.tree import DecisionTreeRegressor\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.linear_model import Ridge\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.metrics import mean_squared_error \nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.564651Z","iopub.execute_input":"2022-08-14T05:43:49.565022Z","iopub.status.idle":"2022-08-14T05:43:49.674132Z","shell.execute_reply.started":"2022-08-14T05:43:49.564985Z","shell.execute_reply":"2022-08-14T05:43:49.672745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### SVM","metadata":{}},{"cell_type":"code","source":"LR = SVR()\nLR.fit(X,y)\nprint('score = ',LR.score(X,y))\nans_predict_SVR=LR.predict(X_Test)\nMSEValue = mean_squared_error(ans, ans_predict_SVR, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:49.675772Z","iopub.execute_input":"2022-08-14T05:43:49.677072Z","iopub.status.idle":"2022-08-14T05:43:50.030336Z","shell.execute_reply.started":"2022-08-14T05:43:49.677029Z","shell.execute_reply":"2022-08-14T05:43:50.028274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"check\nLR = SVR(C=650)#C=650\nLR.fit(X,y)\nprint('score = ',LR.score(X,y))\nans_predict_SVR_1=LR.predict(X_Test)\nMSEValue = mean_squared_error(ans, ans_predict_SVR_1, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:50.031674Z","iopub.execute_input":"2022-08-14T05:43:50.032305Z","iopub.status.idle":"2022-08-14T05:43:50.386098Z","shell.execute_reply.started":"2022-08-14T05:43:50.032265Z","shell.execute_reply":"2022-08-14T05:43:50.384739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### DecisionTreeRegressor","metadata":{}},{"cell_type":"code","source":"DTR = DecisionTreeRegressor(random_state=True)\nDTR.fit(X,y)\nprint('score = ',DTR.score(X,y))\nans_predict_DTR=DTR.predict(X_Test)\nMSEValue = mean_squared_error(ans, ans_predict_DTR, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:50.388187Z","iopub.execute_input":"2022-08-14T05:43:50.388566Z","iopub.status.idle":"2022-08-14T05:43:50.429740Z","shell.execute_reply.started":"2022-08-14T05:43:50.388530Z","shell.execute_reply":"2022-08-14T05:43:50.428276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### RandomForestRegressor","metadata":{}},{"cell_type":"code","source":"RFR = RandomForestRegressor(random_state=True)\nRFR.fit(X,y)\nprint('score = ',RFR.score(X,y))\nans_predict_RFR=RFR.predict(X_Test)\nMSEValue = mean_squared_error(ans, ans_predict_RFR, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:50.431206Z","iopub.execute_input":"2022-08-14T05:43:50.432554Z","iopub.status.idle":"2022-08-14T05:43:51.880067Z","shell.execute_reply.started":"2022-08-14T05:43:50.432502Z","shell.execute_reply":"2022-08-14T05:43:51.878777Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ans_predict_RFR","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:51.881505Z","iopub.execute_input":"2022-08-14T05:43:51.881869Z","iopub.status.idle":"2022-08-14T05:43:51.889537Z","shell.execute_reply.started":"2022-08-14T05:43:51.881835Z","shell.execute_reply":"2022-08-14T05:43:51.888270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### LinearRegression","metadata":{}},{"cell_type":"code","source":"LR = LinearRegression(n_jobs=-1)\nLR.fit(X,y)\n\nprint('LinearRegression')\n\nprint('score = ',LR.score(X,y))\nans_predict_LR=LR.predict(X_Test)\nMSEValue = mean_squared_error(ans, ans_predict_LR, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:51.890995Z","iopub.execute_input":"2022-08-14T05:43:51.891636Z","iopub.status.idle":"2022-08-14T05:43:51.944792Z","shell.execute_reply.started":"2022-08-14T05:43:51.891598Z","shell.execute_reply":"2022-08-14T05:43:51.941918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Hyperparameter tuning(RandomForestRegressor)","metadata":{}},{"cell_type":"code","source":"'''\n#膨大な時間がかかる\nfrom sklearn.model_selection import GridSearchCV\nsearch_params = {\n    'n_estimators'      : [5, 10, 20, 30, 50, 100, 300], # the number of decision tree models\n    'max_features'      : [i for i in range(1,X.shape[1])], # the number of random features\n    'random_state'      : [2525],\n    'n_jobs'            : [1],\n    'min_samples_split' : [3, 5, 10, 15, 20, 25, 30, 40, 50, 100],\n    'max_depth'         : [3, 5, 10, 15, 20, 25, 30, 40, 50, 100] # decision tree node depth limit\n}\ngsr = GridSearchCV(\n    RandomForestRegressor(),\n    search_params,\n    cv = 3,\n    n_jobs = -1,\n    verbose=True\n)\ngsr.fit(X, y)\n'''","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:51.949192Z","iopub.execute_input":"2022-08-14T05:43:51.952600Z","iopub.status.idle":"2022-08-14T05:43:51.978664Z","shell.execute_reply.started":"2022-08-14T05:43:51.952523Z","shell.execute_reply":"2022-08-14T05:43:51.975424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print('score = ',gsr.best_estimator_.score(X,y))\n#y_pred_2 = gsr.best_estimator_.predict(X_Test)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:51.982908Z","iopub.execute_input":"2022-08-14T05:43:51.985051Z","iopub.status.idle":"2022-08-14T05:43:51.992996Z","shell.execute_reply.started":"2022-08-14T05:43:51.984988Z","shell.execute_reply":"2022-08-14T05:43:51.991467Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_pred_2","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:51.996111Z","iopub.execute_input":"2022-08-14T05:43:51.998882Z","iopub.status.idle":"2022-08-14T05:43:52.135192Z","shell.execute_reply.started":"2022-08-14T05:43:51.998807Z","shell.execute_reply":"2022-08-14T05:43:52.132748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#from sklearn import metrics \n#print(\"MSE=\", metrics.mean_squared_error(ans, y_pred_2))","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:52.136105Z","iopub.status.idle":"2022-08-14T05:43:52.136593Z","shell.execute_reply.started":"2022-08-14T05:43:52.136346Z","shell.execute_reply":"2022-08-14T05:43:52.136368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Hyperparameter tuning(SVR)","metadata":{}},{"cell_type":"code","source":"'''\n# ハイパーパラメータのチューニング\nparams_cnt = 600\nparams = {\"C\":np.logspace(6,params_cnt), \"epsilon\":np.logspace(-1,1,params_cnt)}\ngridsearch = GridSearchCV(SVR(), params, cv=3, scoring=\"r2\", return_train_score=True)\ngridsearch.fit(X, y)\nprint(\"C, εのチューニング\")\nprint(\"最適なパラメーター =\", gridsearch.best_params_)\nprint(\"精度 =\", gridsearch.best_score_)\nprint()\n'''","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:52.139107Z","iopub.status.idle":"2022-08-14T05:43:52.140051Z","shell.execute_reply.started":"2022-08-14T05:43:52.139823Z","shell.execute_reply":"2022-08-14T05:43:52.139848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\n# チューニングしたC,εでフィット\nregr = SVR(C=gridsearch.best_params_[\"C\"], epsilon=gridsearch.best_params_[\"epsilon\"])\n\n\nans_predict_SVR_best=regr.best_estimator_.predict(X_Test)\nMSEValue = mean_squared_error(ans, ans_predict_SVR_best, multioutput='uniform_average')\nprint('Mean_squared_error = ',MSEValue)\n'''\n","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:52.141483Z","iopub.status.idle":"2022-08-14T05:43:52.142460Z","shell.execute_reply.started":"2022-08-14T05:43:52.142185Z","shell.execute_reply":"2022-08-14T05:43:52.142217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Output optimal regression result","metadata":{}},{"cell_type":"code","source":"Test_Data = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/sample_submission.csv',skiprows= 0)\nsub = {'Id': Test_Data.Id, 'SalePrice': ans_predict_RFR}\nsubmission = pd.DataFrame(data=sub)\nsubmission.to_csv(\"/kaggle/working/submission.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:44:25.558612Z","iopub.execute_input":"2022-08-14T05:44:25.559057Z","iopub.status.idle":"2022-08-14T05:44:25.573832Z","shell.execute_reply.started":"2022-08-14T05:44:25.559021Z","shell.execute_reply":"2022-08-14T05:44:25.572748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for dirname, _, filenames in os.walk('./'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:44:26.030389Z","iopub.execute_input":"2022-08-14T05:44:26.030792Z","iopub.status.idle":"2022-08-14T05:44:26.037673Z","shell.execute_reply.started":"2022-08-14T05:44:26.030757Z","shell.execute_reply":"2022-08-14T05:44:26.036410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''\n#ファイルの読み出し\nsubmission = pd.read_csv('../working/submission_house_prices.csv')\nsubmission = pd.DataFrame(data=sub)\n#ファイルの書き出し\nsubmission.to_csv('submission.csv', index=False)\n'''\n","metadata":{"execution":{"iopub.status.busy":"2022-08-14T05:43:52.148585Z","iopub.status.idle":"2022-08-14T05:43:52.148981Z","shell.execute_reply.started":"2022-08-14T05:43:52.148792Z","shell.execute_reply":"2022-08-14T05:43:52.148811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}