{"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":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.preprocessing import StandardScaler\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import OneHotEncoder\nfrom sklearn.compose import ColumnTransformer\nfrom  sklearn.linear_model import LinearRegression\nfrom sklearn.decomposition import TruncatedSVD","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-20T07:22:44.348870Z","iopub.execute_input":"2022-07-20T07:22:44.349252Z","iopub.status.idle":"2022-07-20T07:22:44.629514Z","shell.execute_reply.started":"2022-07-20T07:22:44.349222Z","shell.execute_reply":"2022-07-20T07:22:44.628512Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"../input/house-prices-advanced-regression-techniques/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:22:49.373169Z","iopub.execute_input":"2022-07-20T07:22:49.373565Z","iopub.status.idle":"2022-07-20T07:22:49.406162Z","shell.execute_reply.started":"2022-07-20T07:22:49.373532Z","shell.execute_reply":"2022-07-20T07:22:49.405077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:22:50.565420Z","iopub.execute_input":"2022-07-20T07:22:50.565837Z","iopub.status.idle":"2022-07-20T07:22:50.592916Z","shell.execute_reply.started":"2022-07-20T07:22:50.565803Z","shell.execute_reply":"2022-07-20T07:22:50.591884Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## drop features don’t  use","metadata":{}},{"cell_type":"code","source":"df.drop(['Id','Alley','MasVnrArea','GarageYrBlt',\"PoolQC\",\"Fence\",\"MiscFeature\",\"GarageYrBlt\",\"FireplaceQu\",\"YearBuilt\",\"YearRemodAdd\",\"YrSold\",\"BsmtFinSF2\",\"2ndFlrSF\",\"LowQualFinSF\",\"WoodDeckSF\",\"EnclosedPorch\",\"3SsnPorch\",\"ScreenPorch\",\"PoolArea\",\"MiscVal\"],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:22:55.738831Z","iopub.execute_input":"2022-07-20T07:22:55.739212Z","iopub.status.idle":"2022-07-20T07:22:55.747317Z","shell.execute_reply.started":"2022-07-20T07:22:55.739179Z","shell.execute_reply":"2022-07-20T07:22:55.746152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## split data ","metadata":{}},{"cell_type":"code","source":"x_train=df.drop(columns=\"SalePrice\")\ny_train=df[\"SalePrice\"]\nx_test=pd.read_csv(\"../input/house-prices-advanced-regression-techniques/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:22:58.380166Z","iopub.execute_input":"2022-07-20T07:22:58.380727Z","iopub.status.idle":"2022-07-20T07:22:58.412891Z","shell.execute_reply.started":"2022-07-20T07:22:58.380695Z","shell.execute_reply":"2022-07-20T07:22:58.411680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## split data to numerical and categorical","metadata":{}},{"cell_type":"code","source":"numeric_columns=x_train.select_dtypes(exclude='object').columns\nnumeric_columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:23:02.020239Z","iopub.execute_input":"2022-07-20T07:23:02.020631Z","iopub.status.idle":"2022-07-20T07:23:02.034267Z","shell.execute_reply.started":"2022-07-20T07:23:02.020598Z","shell.execute_reply":"2022-07-20T07:23:02.033444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cat_columns = x_train.select_dtypes(include='object').columns\ncat_columns","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:23:02.693997Z","iopub.execute_input":"2022-07-20T07:23:02.694411Z","iopub.status.idle":"2022-07-20T07:23:02.703550Z","shell.execute_reply.started":"2022-07-20T07:23:02.694359Z","shell.execute_reply":"2022-07-20T07:23:02.702468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## pipeline for numerical data","metadata":{}},{"cell_type":"code","source":"numeric_feature = Pipeline(steps=[('handlingmissing',SimpleImputer(strategy='median')),('scaling',StandardScaler(with_mean=False))])\nnumeric_feature","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:23:04.085833Z","iopub.execute_input":"2022-07-20T07:23:04.086476Z","iopub.status.idle":"2022-07-20T07:23:04.097787Z","shell.execute_reply.started":"2022-07-20T07:23:04.086429Z","shell.execute_reply":"2022-07-20T07:23:04.096351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## pipeline for categorical data","metadata":{}},{"cell_type":"code","source":"cat_feature=Pipeline(steps=[('handlingmissing',SimpleImputer(strategy='most_frequent')),('encoding',OneHotEncoder()),('scaling',StandardScaler(with_mean=False))])\ncat_feature","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:23:33.681961Z","iopub.execute_input":"2022-07-20T07:23:33.682717Z","iopub.status.idle":"2022-07-20T07:23:33.692251Z","shell.execute_reply.started":"2022-07-20T07:23:33.682682Z","shell.execute_reply":"2022-07-20T07:23:33.691244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## pipeline for all data(preproccessing)","metadata":{}},{"cell_type":"code","source":"processing = ColumnTransformer([('numeic',numeric_feature,numeric_columns),\n                                ('cat',cat_feature,cat_columns)])\nprocessing","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:24:52.063354Z","iopub.execute_input":"2022-07-20T07:24:52.063753Z","iopub.status.idle":"2022-07-20T07:24:52.090930Z","shell.execute_reply.started":"2022-07-20T07:24:52.063720Z","shell.execute_reply":"2022-07-20T07:24:52.089876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_pipe=Pipeline(steps = [('processing',processing),(\"pca\",TruncatedSVD(n_components=210,random_state=0)),('modeling',LinearRegression())])","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:25:11.189254Z","iopub.execute_input":"2022-07-20T07:25:11.189671Z","iopub.status.idle":"2022-07-20T07:25:11.195439Z","shell.execute_reply.started":"2022-07-20T07:25:11.189639Z","shell.execute_reply":"2022-07-20T07:25:11.194244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_pipe","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:25:54.507915Z","iopub.execute_input":"2022-07-20T07:25:54.508296Z","iopub.status.idle":"2022-07-20T07:25:54.560358Z","shell.execute_reply.started":"2022-07-20T07:25:54.508264Z","shell.execute_reply":"2022-07-20T07:25:54.559459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_pipe.fit(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:26:17.600645Z","iopub.execute_input":"2022-07-20T07:26:17.601050Z","iopub.status.idle":"2022-07-20T07:26:18.336048Z","shell.execute_reply.started":"2022-07-20T07:26:17.601018Z","shell.execute_reply":"2022-07-20T07:26:18.334931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_pipe.score(x_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:26:29.486332Z","iopub.execute_input":"2022-07-20T07:26:29.486723Z","iopub.status.idle":"2022-07-20T07:26:29.578247Z","shell.execute_reply.started":"2022-07-20T07:26:29.486691Z","shell.execute_reply":"2022-07-20T07:26:29.576863Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SalePrice=final_pipe.predict(x_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:26:45.551686Z","iopub.execute_input":"2022-07-20T07:26:45.552072Z","iopub.status.idle":"2022-07-20T07:26:45.610315Z","shell.execute_reply.started":"2022-07-20T07:26:45.552041Z","shell.execute_reply":"2022-07-20T07:26:45.609254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"##  final SampleSubmission","metadata":{}},{"cell_type":"code","source":"pd.DataFrame({\"Id\":x_test.Id,\"SalePrice\":SalePrice}).to_csv(\"SampleSubmission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T07:28:31.885107Z","iopub.execute_input":"2022-07-20T07:28:31.885504Z","iopub.status.idle":"2022-07-20T07:28:31.900169Z","shell.execute_reply.started":"2022-07-20T07:28:31.885473Z","shell.execute_reply":"2022-07-20T07:28:31.899307Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## الحمدلله الذي وفقنا لهذا","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}