{"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":"2023-01-19T14:50:28.497998Z","iopub.execute_input":"2023-01-19T14:50:28.499529Z","iopub.status.idle":"2023-01-19T14:50:28.521834Z","shell.execute_reply.started":"2023-01-19T14:50:28.499473Z","shell.execute_reply":"2023-01-19T14:50:28.520535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Question 1","metadata":{}},{"cell_type":"code","source":"import pandas as pd","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.523751Z","iopub.execute_input":"2023-01-19T14:50:28.524345Z","iopub.status.idle":"2023-01-19T14:50:28.529117Z","shell.execute_reply.started":"2023-01-19T14:50:28.524312Z","shell.execute_reply":"2023-01-19T14:50:28.527837Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"url = \"https://raw.githubusercontent.com/jbrownlee/Datasets/master/housing.data\"\ncolumn_names = ['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT', 'MEDV']\ndataframe = pd.read_csv(url, delim_whitespace=True, names=column_names)\ndataframe","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.532545Z","iopub.execute_input":"2023-01-19T14:50:28.533024Z","iopub.status.idle":"2023-01-19T14:50:28.858481Z","shell.execute_reply.started":"2023-01-19T14:50:28.532986Z","shell.execute_reply":"2023-01-19T14:50:28.856664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.linear_model import LinearRegression\n\nfrom lightgbm import LGBMRegressor\n\nfrom xgboost.sklearn import XGBRegressor\n\nfrom catboost import CatBoostRegressor\n\nfrom sklearn.linear_model import SGDRegressor\n\nfrom sklearn.kernel_ridge import KernelRidge\n\nfrom sklearn.linear_model import ElasticNet\n\nfrom sklearn.linear_model import BayesianRidge\n\nfrom sklearn.ensemble import GradientBoostingRegressor\n\nfrom sklearn.svm import SVR","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.861400Z","iopub.execute_input":"2023-01-19T14:50:28.861957Z","iopub.status.idle":"2023-01-19T14:50:28.870473Z","shell.execute_reply.started":"2023-01-19T14:50:28.861907Z","shell.execute_reply":"2023-01-19T14:50:28.868867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn import model_selection\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.tree import DecisionTreeRegressor\nimport matplotlib.pyplot as plt\nfrom sklearn import metrics","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.872126Z","iopub.execute_input":"2023-01-19T14:50:28.872598Z","iopub.status.idle":"2023-01-19T14:50:28.887412Z","shell.execute_reply.started":"2023-01-19T14:50:28.872555Z","shell.execute_reply":"2023-01-19T14:50:28.886075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sklearn\nfrom xgboost.sklearn import XGBRegressor\nfrom sklearn.svm import SVR\n\nfrom sklearn.linear_model import ElasticNet\nfrom sklearn.ensemble import GradientBoostingRegressor","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.890149Z","iopub.execute_input":"2023-01-19T14:50:28.890534Z","iopub.status.idle":"2023-01-19T14:50:28.903430Z","shell.execute_reply.started":"2023-01-19T14:50:28.890501Z","shell.execute_reply":"2023-01-19T14:50:28.902288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(dataframe.shape)\nprint(dataframe.keys()) ","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.904589Z","iopub.execute_input":"2023-01-19T14:50:28.905168Z","iopub.status.idle":"2023-01-19T14:50:28.920530Z","shell.execute_reply.started":"2023-01-19T14:50:28.905133Z","shell.execute_reply":"2023-01-19T14:50:28.918950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = dataframe.values\n# Input Data \nX = data[:,0:13]\n# Output Data \ny = data[:,13]\nX_train, X_test, y_train, y_test = train_test_split(X, y,test_size=1/3, random_state=0)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.922540Z","iopub.execute_input":"2023-01-19T14:50:28.922964Z","iopub.status.idle":"2023-01-19T14:50:28.935912Z","shell.execute_reply.started":"2023-01-19T14:50:28.922929Z","shell.execute_reply":"2023-01-19T14:50:28.934482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"XGBoost Regressor","metadata":{}},{"cell_type":"code","source":"model = XGBRegressor()\n\nmodel.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:28.937275Z","iopub.execute_input":"2023-01-19T14:50:28.937775Z","iopub.status.idle":"2023-01-19T14:50:29.474745Z","shell.execute_reply.started":"2023-01-19T14:50:28.937728Z","shell.execute_reply":"2023-01-19T14:50:29.473804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predicted = model.predict(X_test)\ny_train_predicted = model.predict(X_train)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.477890Z","iopub.execute_input":"2023-01-19T14:50:29.478260Z","iopub.status.idle":"2023-01-19T14:50:29.492435Z","shell.execute_reply.started":"2023-01-19T14:50:29.478229Z","shell.execute_reply":"2023-01-19T14:50:29.491466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r = metrics.r2_score(y_test, y_predicted)\nmae = metrics.mean_absolute_error(y_test, y_predicted)\n\nprint('R2 score is {}'.format(r))\nprint('Mean Absolute Error - MAE is {}'.format(mae))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.493973Z","iopub.execute_input":"2023-01-19T14:50:29.495055Z","iopub.status.idle":"2023-01-19T14:50:29.508355Z","shell.execute_reply.started":"2023-01-19T14:50:29.494992Z","shell.execute_reply":"2023-01-19T14:50:29.507136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Support Vector Regression","metadata":{}},{"cell_type":"code","source":"model1 = SVR()\n\nmodel1.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.514541Z","iopub.execute_input":"2023-01-19T14:50:29.515960Z","iopub.status.idle":"2023-01-19T14:50:29.533330Z","shell.execute_reply.started":"2023-01-19T14:50:29.515913Z","shell.execute_reply":"2023-01-19T14:50:29.532427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predicted1 = model1.predict(X_test)\ny_train_predicted1 = model1.predict(X_train)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.534870Z","iopub.execute_input":"2023-01-19T14:50:29.535670Z","iopub.status.idle":"2023-01-19T14:50:29.554444Z","shell.execute_reply.started":"2023-01-19T14:50:29.535617Z","shell.execute_reply":"2023-01-19T14:50:29.553434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r1 = metrics.r2_score(y_test, y_predicted1)\nmae1 = metrics.mean_absolute_error(y_test, y_predicted1)\n\nprint('R2 score is {}'.format(r1))\nprint('Mean Absolute Error - MAE is {}'.format(mae1))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.556334Z","iopub.execute_input":"2023-01-19T14:50:29.557288Z","iopub.status.idle":"2023-01-19T14:50:29.567573Z","shell.execute_reply.started":"2023-01-19T14:50:29.557230Z","shell.execute_reply":"2023-01-19T14:50:29.566116Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Decision Tree Regression","metadata":{}},{"cell_type":"code","source":"model2 = DecisionTreeRegressor()\n\nmodel2.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.569167Z","iopub.execute_input":"2023-01-19T14:50:29.569538Z","iopub.status.idle":"2023-01-19T14:50:29.587906Z","shell.execute_reply.started":"2023-01-19T14:50:29.569506Z","shell.execute_reply":"2023-01-19T14:50:29.586868Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predicted2 = model2.predict(X_test)\ny_train_predicted2 = model2.predict(X_train)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.590454Z","iopub.execute_input":"2023-01-19T14:50:29.591703Z","iopub.status.idle":"2023-01-19T14:50:29.598942Z","shell.execute_reply.started":"2023-01-19T14:50:29.591653Z","shell.execute_reply":"2023-01-19T14:50:29.597204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r2 = metrics.r2_score(y_test, y_predicted2)\nmae2 = metrics.mean_absolute_error(y_test, y_predicted2)\n\nprint('R2 score is {}'.format(r2))\nprint('Mean Absolute Error - MAE is {}'.format(mae2))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.600872Z","iopub.execute_input":"2023-01-19T14:50:29.601420Z","iopub.status.idle":"2023-01-19T14:50:29.615283Z","shell.execute_reply.started":"2023-01-19T14:50:29.601373Z","shell.execute_reply":"2023-01-19T14:50:29.613901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Linear Regression\n","metadata":{}},{"cell_type":"code","source":"model3 = LinearRegression()\n\nmodel3.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.616711Z","iopub.execute_input":"2023-01-19T14:50:29.617099Z","iopub.status.idle":"2023-01-19T14:50:29.633897Z","shell.execute_reply.started":"2023-01-19T14:50:29.617057Z","shell.execute_reply":"2023-01-19T14:50:29.631592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predicted3 = model3.predict(X_test)\ny_train_predicted3 = model3.predict(X_train)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.635642Z","iopub.execute_input":"2023-01-19T14:50:29.636150Z","iopub.status.idle":"2023-01-19T14:50:29.644269Z","shell.execute_reply.started":"2023-01-19T14:50:29.636112Z","shell.execute_reply":"2023-01-19T14:50:29.642894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r3 = metrics.r2_score(y_test, y_predicted3)\nmae3 = metrics.mean_absolute_error(y_test, y_predicted3)\n\nprint('R2 score is {}'.format(r3))\nprint('Mean Absolute Error - MAE is {}'.format(mae3))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.646174Z","iopub.execute_input":"2023-01-19T14:50:29.646658Z","iopub.status.idle":"2023-01-19T14:50:29.658730Z","shell.execute_reply.started":"2023-01-19T14:50:29.646623Z","shell.execute_reply":"2023-01-19T14:50:29.657343Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Elastic Net Regression","metadata":{}},{"cell_type":"code","source":"model4 = ElasticNet()\n\nmodel4.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.660736Z","iopub.execute_input":"2023-01-19T14:50:29.661779Z","iopub.status.idle":"2023-01-19T14:50:29.677312Z","shell.execute_reply.started":"2023-01-19T14:50:29.661736Z","shell.execute_reply":"2023-01-19T14:50:29.676003Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predicted4 = model4.predict(X_test)\ny_train_predicted4 = model4.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.678928Z","iopub.execute_input":"2023-01-19T14:50:29.679451Z","iopub.status.idle":"2023-01-19T14:50:29.690532Z","shell.execute_reply.started":"2023-01-19T14:50:29.679408Z","shell.execute_reply":"2023-01-19T14:50:29.689007Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r4 = metrics.r2_score(y_test, y_predicted4)\nmae4 = metrics.mean_absolute_error(y_test, y_predicted4)\n\nprint('R2 score is {}'.format(r4))\nprint('Mean Absolute Error - MAE is {}'.format(mae4))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.692624Z","iopub.execute_input":"2023-01-19T14:50:29.693858Z","iopub.status.idle":"2023-01-19T14:50:29.705755Z","shell.execute_reply.started":"2023-01-19T14:50:29.693819Z","shell.execute_reply":"2023-01-19T14:50:29.704346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Gradient Boosting Regression algorithms\n","metadata":{}},{"cell_type":"code","source":"model5 = GradientBoostingRegressor()\n\nmodel5.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.706969Z","iopub.execute_input":"2023-01-19T14:50:29.707733Z","iopub.status.idle":"2023-01-19T14:50:29.836575Z","shell.execute_reply.started":"2023-01-19T14:50:29.707697Z","shell.execute_reply":"2023-01-19T14:50:29.835214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_predicted5 = model5.predict(X_test)\ny_train_predicted5 = model5.predict(X_train)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.837864Z","iopub.execute_input":"2023-01-19T14:50:29.838228Z","iopub.status.idle":"2023-01-19T14:50:29.849064Z","shell.execute_reply.started":"2023-01-19T14:50:29.838199Z","shell.execute_reply":"2023-01-19T14:50:29.846230Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r5 = metrics.r2_score(y_test, y_predicted5)\nmae5 = metrics.mean_absolute_error(y_test, y_predicted5)\n\nprint('R2 score is {}'.format(r5))\nprint('Mean Absolute Error - MAE is {}'.format(mae5))\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.852667Z","iopub.execute_input":"2023-01-19T14:50:29.853304Z","iopub.status.idle":"2023-01-19T14:50:29.861808Z","shell.execute_reply.started":"2023-01-19T14:50:29.853264Z","shell.execute_reply":"2023-01-19T14:50:29.860480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Part B and C","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\nXtrain_scaled = scaler.fit_transform(X_train)\nXtrain_scaled\nXtest_scaled = scaler.transform(X_test)\nXtest_scaled","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.863028Z","iopub.execute_input":"2023-01-19T14:50:29.863412Z","iopub.status.idle":"2023-01-19T14:50:29.883559Z","shell.execute_reply.started":"2023-01-19T14:50:29.863365Z","shell.execute_reply":"2023-01-19T14:50:29.882488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scalery = StandardScaler().fit(y_train.reshape(-1, 1))\n\nY_Train_Scaled = scalery.transform(y_train.reshape(-1, 1))\nY_Test_Scaled= scalery.transform(y_test.reshape(-1, 1))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.884874Z","iopub.execute_input":"2023-01-19T14:50:29.886270Z","iopub.status.idle":"2023-01-19T14:50:29.897957Z","shell.execute_reply.started":"2023-01-19T14:50:29.886220Z","shell.execute_reply":"2023-01-19T14:50:29.896520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"XGBoost Regressor","metadata":{}},{"cell_type":"code","source":"model.fit(Xtrain_scaled,Y_Train_Scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:29.899697Z","iopub.execute_input":"2023-01-19T14:50:29.901696Z","iopub.status.idle":"2023-01-19T14:50:30.398312Z","shell.execute_reply.started":"2023-01-19T14:50:29.901602Z","shell.execute_reply":"2023-01-19T14:50:30.397292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_Train_Scaled_pedict=model.predict(Xtrain_scaled)\nY_Test_Scaled_predict=model.predict(Xtest_scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.407384Z","iopub.execute_input":"2023-01-19T14:50:30.408526Z","iopub.status.idle":"2023-01-19T14:50:30.425021Z","shell.execute_reply.started":"2023-01-19T14:50:30.408460Z","shell.execute_reply":"2023-01-19T14:50:30.424010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs = metrics.r2_score(Y_Test_Scaled, Y_Test_Scaled_predict)\nmaes = metrics.mean_absolute_error(Y_Test_Scaled, Y_Test_Scaled_predict)\n\nprint('R2 score is {}'.format(rs))\nprint('Mean Absolute Error - MAE is {}'.format(maes))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.426453Z","iopub.execute_input":"2023-01-19T14:50:30.427987Z","iopub.status.idle":"2023-01-19T14:50:30.437952Z","shell.execute_reply.started":"2023-01-19T14:50:30.427725Z","shell.execute_reply":"2023-01-19T14:50:30.436961Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Support Vector Regression","metadata":{}},{"cell_type":"code","source":"model1.fit(Xtrain_scaled,Y_Train_Scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.439423Z","iopub.execute_input":"2023-01-19T14:50:30.440404Z","iopub.status.idle":"2023-01-19T14:50:30.466242Z","shell.execute_reply.started":"2023-01-19T14:50:30.440360Z","shell.execute_reply":"2023-01-19T14:50:30.465351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_Train_Scaled1_predict=model1.predict(Xtrain_scaled)\nY_Test_Scaled1_predict=model1.predict(Xtest_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.467563Z","iopub.execute_input":"2023-01-19T14:50:30.468312Z","iopub.status.idle":"2023-01-19T14:50:30.483879Z","shell.execute_reply.started":"2023-01-19T14:50:30.468275Z","shell.execute_reply":"2023-01-19T14:50:30.482675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs1 = metrics.r2_score(Y_Test_Scaled, Y_Test_Scaled1_predict)\nmaes1 = metrics.mean_absolute_error(Y_Test_Scaled, Y_Test_Scaled1_predict)\n\nprint('R2 score is {}'.format(rs1))\nprint('Mean Absolute Error - MAE is {}'.format(maes1))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.485710Z","iopub.execute_input":"2023-01-19T14:50:30.486922Z","iopub.status.idle":"2023-01-19T14:50:30.495101Z","shell.execute_reply.started":"2023-01-19T14:50:30.486884Z","shell.execute_reply":"2023-01-19T14:50:30.494128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Decision Tree Regression","metadata":{}},{"cell_type":"code","source":"model2.fit(Xtrain_scaled,Y_Train_Scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.496950Z","iopub.execute_input":"2023-01-19T14:50:30.497387Z","iopub.status.idle":"2023-01-19T14:50:30.517411Z","shell.execute_reply.started":"2023-01-19T14:50:30.497354Z","shell.execute_reply":"2023-01-19T14:50:30.516155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_Train_Scaled2_predict=model2.predict(Xtrain_scaled)\nY_Test_Scaled2_predict=model2.predict(Xtest_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.519558Z","iopub.execute_input":"2023-01-19T14:50:30.520412Z","iopub.status.idle":"2023-01-19T14:50:30.528366Z","shell.execute_reply.started":"2023-01-19T14:50:30.520361Z","shell.execute_reply":"2023-01-19T14:50:30.526857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs2 = metrics.r2_score(Y_Test_Scaled, Y_Test_Scaled2_predict)\nmaes2 = metrics.mean_absolute_error(Y_Test_Scaled, Y_Test_Scaled2_predict)\n\nprint('R2 score is {}'.format(rs2))\nprint('Mean Absolute Error - MAE is {}'.format(maes2))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.529994Z","iopub.execute_input":"2023-01-19T14:50:30.530761Z","iopub.status.idle":"2023-01-19T14:50:30.546427Z","shell.execute_reply.started":"2023-01-19T14:50:30.530714Z","shell.execute_reply":"2023-01-19T14:50:30.544937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Linear Regression\n","metadata":{}},{"cell_type":"code","source":"model3.fit(Xtrain_scaled,Y_Train_Scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.548403Z","iopub.execute_input":"2023-01-19T14:50:30.548862Z","iopub.status.idle":"2023-01-19T14:50:30.565853Z","shell.execute_reply.started":"2023-01-19T14:50:30.548824Z","shell.execute_reply":"2023-01-19T14:50:30.564807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_Train_Scaled3_predict=model3.predict(Xtrain_scaled)\nY_Test_Scaled3_predict=model3.predict(Xtest_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.567795Z","iopub.execute_input":"2023-01-19T14:50:30.569260Z","iopub.status.idle":"2023-01-19T14:50:30.580610Z","shell.execute_reply.started":"2023-01-19T14:50:30.569202Z","shell.execute_reply":"2023-01-19T14:50:30.579340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs3 = metrics.r2_score(Y_Test_Scaled, Y_Test_Scaled3_predict)\nmaes3 = metrics.mean_absolute_error(Y_Test_Scaled, Y_Test_Scaled3_predict)\n\nprint('R2 score is {}'.format(rs3))\nprint('Mean Absolute Error - MAE is {}'.format(maes3))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.581945Z","iopub.execute_input":"2023-01-19T14:50:30.583415Z","iopub.status.idle":"2023-01-19T14:50:30.597218Z","shell.execute_reply.started":"2023-01-19T14:50:30.583356Z","shell.execute_reply":"2023-01-19T14:50:30.595841Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Elastic Net Regression\n","metadata":{}},{"cell_type":"code","source":"model4.fit(Xtrain_scaled,Y_Train_Scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.599292Z","iopub.execute_input":"2023-01-19T14:50:30.600143Z","iopub.status.idle":"2023-01-19T14:50:30.615090Z","shell.execute_reply.started":"2023-01-19T14:50:30.600091Z","shell.execute_reply":"2023-01-19T14:50:30.613676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_Train_Scaled4_predict=model4.predict(Xtrain_scaled)\nY_Test_Scaled4_predict=model4.predict(Xtest_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.616840Z","iopub.execute_input":"2023-01-19T14:50:30.617447Z","iopub.status.idle":"2023-01-19T14:50:30.630312Z","shell.execute_reply.started":"2023-01-19T14:50:30.617407Z","shell.execute_reply":"2023-01-19T14:50:30.629072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs4 = metrics.r2_score(Y_Test_Scaled, Y_Test_Scaled4_predict)\nmaes4 = metrics.mean_absolute_error(Y_Test_Scaled, Y_Test_Scaled4_predict)\n\nprint('R2 score is {}'.format(rs4))\nprint('Mean Absolute Error - MAE is {}'.format(maes4))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.632576Z","iopub.execute_input":"2023-01-19T14:50:30.633618Z","iopub.status.idle":"2023-01-19T14:50:30.652216Z","shell.execute_reply.started":"2023-01-19T14:50:30.633577Z","shell.execute_reply":"2023-01-19T14:50:30.650261Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Gradient Boosting Regression algorithms\n","metadata":{}},{"cell_type":"code","source":"model5.fit(Xtrain_scaled,Y_Train_Scaled)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.654493Z","iopub.execute_input":"2023-01-19T14:50:30.654959Z","iopub.status.idle":"2023-01-19T14:50:30.785734Z","shell.execute_reply.started":"2023-01-19T14:50:30.654923Z","shell.execute_reply":"2023-01-19T14:50:30.783388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Y_Train_Scaled5_predict=model5.predict(Xtrain_scaled)\nY_Test_Scaled5_predict=model5.predict(Xtest_scaled)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.788534Z","iopub.execute_input":"2023-01-19T14:50:30.788966Z","iopub.status.idle":"2023-01-19T14:50:30.797878Z","shell.execute_reply.started":"2023-01-19T14:50:30.788932Z","shell.execute_reply":"2023-01-19T14:50:30.796603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rs5 = metrics.r2_score(Y_Test_Scaled, Y_Test_Scaled5_predict)\nmaes5 = metrics.mean_absolute_error(Y_Test_Scaled, Y_Test_Scaled5_predict)\n\nprint('R2 score is {}'.format(rs5))\nprint('Mean Absolute Error - MAE is {}'.format(maes5))","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.799688Z","iopub.execute_input":"2023-01-19T14:50:30.800088Z","iopub.status.idle":"2023-01-19T14:50:30.820255Z","shell.execute_reply.started":"2023-01-19T14:50:30.800017Z","shell.execute_reply":"2023-01-19T14:50:30.818945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Question 2\n","metadata":{}},{"cell_type":"markdown","source":"Part A","metadata":{}},{"cell_type":"code","source":"train = pd.read_csv(\"../input/digit-recognizer/train.csv\")\ntest = pd.read_csv('../input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:30.821593Z","iopub.execute_input":"2023-01-19T14:50:30.822329Z","iopub.status.idle":"2023-01-19T14:50:35.227846Z","shell.execute_reply.started":"2023-01-19T14:50:30.822290Z","shell.execute_reply":"2023-01-19T14:50:35.226565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.229123Z","iopub.execute_input":"2023-01-19T14:50:35.229597Z","iopub.status.idle":"2023-01-19T14:50:35.255357Z","shell.execute_reply.started":"2023-01-19T14:50:35.229555Z","shell.execute_reply":"2023-01-19T14:50:35.253490Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.head()","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.257493Z","iopub.execute_input":"2023-01-19T14:50:35.258006Z","iopub.status.idle":"2023-01-19T14:50:35.281377Z","shell.execute_reply.started":"2023-01-19T14:50:35.257962Z","shell.execute_reply":"2023-01-19T14:50:35.279576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Xtrain1 = train.drop(columns ='label')\nytrain1 = train['label']","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.282580Z","iopub.execute_input":"2023-01-19T14:50:35.282892Z","iopub.status.idle":"2023-01-19T14:50:35.465772Z","shell.execute_reply.started":"2023-01-19T14:50:35.282864Z","shell.execute_reply":"2023-01-19T14:50:35.463861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Xtrain1","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.467702Z","iopub.execute_input":"2023-01-19T14:50:35.468209Z","iopub.status.idle":"2023-01-19T14:50:35.495497Z","shell.execute_reply.started":"2023-01-19T14:50:35.468154Z","shell.execute_reply":"2023-01-19T14:50:35.494337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.svm import SVC\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.497066Z","iopub.execute_input":"2023-01-19T14:50:35.498086Z","iopub.status.idle":"2023-01-19T14:50:35.505215Z","shell.execute_reply.started":"2023-01-19T14:50:35.498020Z","shell.execute_reply":"2023-01-19T14:50:35.503754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random_seed = 2\nX_train1, X_test1, y_train1, y_test1 = train_test_split(Xtrain1, ytrain1, test_size = 0.1, random_state=random_seed)","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.507173Z","iopub.execute_input":"2023-01-19T14:50:35.508296Z","iopub.status.idle":"2023-01-19T14:50:35.914424Z","shell.execute_reply.started":"2023-01-19T14:50:35.508255Z","shell.execute_reply":"2023-01-19T14:50:35.912990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC = SVC(gamma='scale')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:35.916635Z","iopub.execute_input":"2023-01-19T14:50:35.917691Z","iopub.status.idle":"2023-01-19T14:50:35.923087Z","shell.execute_reply.started":"2023-01-19T14:50:35.917640Z","shell.execute_reply":"2023-01-19T14:50:35.921761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC.fit(X_train1, y_train1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:50:43.972585Z","iopub.execute_input":"2023-01-19T14:50:43.973076Z","iopub.status.idle":"2023-01-19T14:53:35.256676Z","shell.execute_reply.started":"2023-01-19T14:50:43.973012Z","shell.execute_reply":"2023-01-19T14:53:35.255225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_predS = modelSVC.predict(X_test1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:58:20.736746Z","iopub.execute_input":"2023-01-19T14:58:20.737775Z","iopub.status.idle":"2023-01-19T14:59:02.020844Z","shell.execute_reply.started":"2023-01-19T14:58:20.737739Z","shell.execute_reply":"2023-01-19T14:59:02.019535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(metrics.classification_report(y_test1, y_predS))\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:59:11.493147Z","iopub.execute_input":"2023-01-19T14:59:11.494279Z","iopub.status.idle":"2023-01-19T14:59:11.518610Z","shell.execute_reply.started":"2023-01-19T14:59:11.494238Z","shell.execute_reply":"2023-01-19T14:59:11.517017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC2 = SVC(kernel='rbf')\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:54:08.369308Z","iopub.execute_input":"2023-01-19T14:54:08.369782Z","iopub.status.idle":"2023-01-19T14:54:08.376848Z","shell.execute_reply.started":"2023-01-19T14:54:08.369750Z","shell.execute_reply":"2023-01-19T14:54:08.375321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC2.fit(X_train1, y_train1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T14:55:02.018419Z","iopub.execute_input":"2023-01-19T14:55:02.018865Z","iopub.status.idle":"2023-01-19T14:57:49.226436Z","shell.execute_reply.started":"2023-01-19T14:55:02.018833Z","shell.execute_reply":"2023-01-19T14:57:49.225425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_predS2 = modelSVC2.predict(X_test1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:00:02.438802Z","iopub.execute_input":"2023-01-19T15:00:02.439268Z","iopub.status.idle":"2023-01-19T15:00:47.344484Z","shell.execute_reply.started":"2023-01-19T15:00:02.439233Z","shell.execute_reply":"2023-01-19T15:00:47.342708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(metrics.classification_report(y_test1, y_predS2))\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:01:52.819788Z","iopub.execute_input":"2023-01-19T15:01:52.820941Z","iopub.status.idle":"2023-01-19T15:01:52.844268Z","shell.execute_reply.started":"2023-01-19T15:01:52.820888Z","shell.execute_reply":"2023-01-19T15:01:52.842796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC3 = SVC(shrinking=True)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:02:01.852304Z","iopub.execute_input":"2023-01-19T15:02:01.852699Z","iopub.status.idle":"2023-01-19T15:02:01.859618Z","shell.execute_reply.started":"2023-01-19T15:02:01.852668Z","shell.execute_reply":"2023-01-19T15:02:01.857917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC3.fit(X_train1, y_train1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:02:06.356983Z","iopub.execute_input":"2023-01-19T15:02:06.357655Z","iopub.status.idle":"2023-01-19T15:04:54.661898Z","shell.execute_reply.started":"2023-01-19T15:02:06.357621Z","shell.execute_reply":"2023-01-19T15:04:54.660641Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_predS3 = modelSVC3.predict(X_test1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:04:54.664433Z","iopub.execute_input":"2023-01-19T15:04:54.664880Z","iopub.status.idle":"2023-01-19T15:05:34.505552Z","shell.execute_reply.started":"2023-01-19T15:04:54.664838Z","shell.execute_reply":"2023-01-19T15:05:34.504080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(metrics.classification_report(y_test1, y_predS3))\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:05:34.507917Z","iopub.execute_input":"2023-01-19T15:05:34.508554Z","iopub.status.idle":"2023-01-19T15:05:34.530419Z","shell.execute_reply.started":"2023-01-19T15:05:34.508509Z","shell.execute_reply":"2023-01-19T15:05:34.529152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC4 = SVC(gamma='auto')\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:05:34.533922Z","iopub.execute_input":"2023-01-19T15:05:34.534403Z","iopub.status.idle":"2023-01-19T15:05:34.540609Z","shell.execute_reply.started":"2023-01-19T15:05:34.534357Z","shell.execute_reply":"2023-01-19T15:05:34.539291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC4.fit(X_train1, y_train1)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-19T15:05:34.542814Z","iopub.execute_input":"2023-01-19T15:05:34.543258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_predS4 = modelSVC4.predict(X_test1)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(metrics.classification_report(y_test1, y_predS4))\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC5 = SVC(kernel='sigmoid')\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelSVC5.fit(X_train1, y_train1)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#y_predS5 = modelSVC5.predict(X_test1)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(metrics.classification_report(y_test1, y_predS5))\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#import scikitplot as skplt\n#y_predS = model.predict(X_test1)\n#skplt.metrics.plot_confusion_matrix(y_test1, y_predS,\n#                                    normalize=False,\n#                                    title=\"Confusion Matrix\",\n#                                    cmap=\"Purples\",\n#                                    );","metadata":{},"execution_count":null,"outputs":[]}]}