{"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 des librairies de base\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport sklearn.datasets\nfrom sklearn.model_selection import train_test_split\nfrom xgboost import XGBRegressor\nfrom sklearn.metrics import mean_absolute_error\nfrom sklearn import metrics","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:11.925539Z","iopub.execute_input":"2022-07-09T00:08:11.925978Z","iopub.status.idle":"2022-07-09T00:08:13.539510Z","shell.execute_reply.started":"2022-07-09T00:08:11.925890Z","shell.execute_reply":"2022-07-09T00:08:13.538318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#mise en place des liens\niowa_file_path = '../input/house-prices-advanced-regression-techniques/train.csv'\nhome_data = pd.read_csv(iowa_file_path)\nprint(home_data)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.542473Z","iopub.execute_input":"2022-07-09T00:08:13.542833Z","iopub.status.idle":"2022-07-09T00:08:13.620598Z","shell.execute_reply.started":"2022-07-09T00:08:13.542802Z","shell.execute_reply":"2022-07-09T00:08:13.619577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Description des éléments dans le fichier\nhome_data.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.622034Z","iopub.execute_input":"2022-07-09T00:08:13.622646Z","iopub.status.idle":"2022-07-09T00:08:13.756893Z","shell.execute_reply.started":"2022-07-09T00:08:13.622613Z","shell.execute_reply":"2022-07-09T00:08:13.755625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"home_data.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.760109Z","iopub.execute_input":"2022-07-09T00:08:13.760534Z","iopub.status.idle":"2022-07-09T00:08:13.782055Z","shell.execute_reply.started":"2022-07-09T00:08:13.760488Z","shell.execute_reply":"2022-07-09T00:08:13.780020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#comme c'est le prix que nous voulons prédire \n#nous allons récupérer celà dans la variable y\ny = home_data.SalePrice\nprint(y)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.783835Z","iopub.execute_input":"2022-07-09T00:08:13.784708Z","iopub.status.idle":"2022-07-09T00:08:13.797195Z","shell.execute_reply.started":"2022-07-09T00:08:13.784664Z","shell.execute_reply":"2022-07-09T00:08:13.795645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#selectionnons les labels que nous allons utilisés \nfeatures = ['LotArea', 'YearBuilt', '1stFlrSF', '2ndFlrSF', 'FullBath', 'BedroomAbvGr', 'TotRmsAbvGrd']\nX = home_data[features]","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.801593Z","iopub.execute_input":"2022-07-09T00:08:13.802684Z","iopub.status.idle":"2022-07-09T00:08:13.809775Z","shell.execute_reply.started":"2022-07-09T00:08:13.802636Z","shell.execute_reply":"2022-07-09T00:08:13.808540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.811821Z","iopub.execute_input":"2022-07-09T00:08:13.812643Z","iopub.status.idle":"2022-07-09T00:08:13.829119Z","shell.execute_reply.started":"2022-07-09T00:08:13.812598Z","shell.execute_reply":"2022-07-09T00:08:13.827395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.831505Z","iopub.execute_input":"2022-07-09T00:08:13.832305Z","iopub.status.idle":"2022-07-09T00:08:13.840110Z","shell.execute_reply.started":"2022-07-09T00:08:13.832260Z","shell.execute_reply":"2022-07-09T00:08:13.839014Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, Y_train, Y_test = train_test_split(X, y, test_size = 0.2, random_state = 2)\nprint(X.shape,X_train.shape,X_test.shape)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:13.841711Z","iopub.execute_input":"2022-07-09T00:08:13.842381Z","iopub.status.idle":"2022-07-09T00:08:13.854550Z","shell.execute_reply.started":"2022-07-09T00:08:13.842339Z","shell.execute_reply":"2022-07-09T00:08:13.853047Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = XGBRegressor(n_estimators=1000, learning_rate=0.05, n_jobs=4)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:13:37.686680Z","iopub.execute_input":"2022-07-09T00:13:37.687092Z","iopub.status.idle":"2022-07-09T00:13:37.692704Z","shell.execute_reply.started":"2022-07-09T00:13:37.687059Z","shell.execute_reply":"2022-07-09T00:13:37.691595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(X_train,Y_train)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:13:09.575589Z","iopub.execute_input":"2022-07-09T00:13:09.576007Z","iopub.status.idle":"2022-07-09T00:13:16.437217Z","shell.execute_reply.started":"2022-07-09T00:13:09.575975Z","shell.execute_reply":"2022-07-09T00:13:16.436085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_data_prediction = model.predict(X_train)\nprint(training_data_prediction)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:13:22.118604Z","iopub.execute_input":"2022-07-09T00:13:22.118990Z","iopub.status.idle":"2022-07-09T00:13:22.146618Z","shell.execute_reply.started":"2022-07-09T00:13:22.118960Z","shell.execute_reply":"2022-07-09T00:13:22.145275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# R squared error\nscore_1 = metrics.r2_score(Y_train, training_data_prediction)\n\n# Mean Absolute Error\nscore_2 = metrics.mean_absolute_error(Y_train, training_data_prediction)\n\nprint(\"R squared error : \", score_1)\nprint('Mean Absolute Error : ', score_2)\n","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:13:25.135154Z","iopub.execute_input":"2022-07-09T00:13:25.135534Z","iopub.status.idle":"2022-07-09T00:13:25.143823Z","shell.execute_reply.started":"2022-07-09T00:13:25.135504Z","shell.execute_reply":"2022-07-09T00:13:25.142638Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(Y_train, training_data_prediction)\nplt.xlabel(\"Prix réels\")\nplt.ylabel(\"Prix prédits\")\nplt.title(\"Prix réel vs prix prévu\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:15.159675Z","iopub.execute_input":"2022-07-09T00:08:15.160712Z","iopub.status.idle":"2022-07-09T00:08:15.426142Z","shell.execute_reply.started":"2022-07-09T00:08:15.160667Z","shell.execute_reply":"2022-07-09T00:08:15.424986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = pd.DataFrame({'Id': X_test.index,'SalePrice': score_2})\noutput.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-09T00:08:15.427376Z","iopub.execute_input":"2022-07-09T00:08:15.427710Z","iopub.status.idle":"2022-07-09T00:08:15.438230Z","shell.execute_reply.started":"2022-07-09T00:08:15.427682Z","shell.execute_reply":"2022-07-09T00:08:15.437389Z"},"trusted":true},"execution_count":null,"outputs":[]}]}