{"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 numpy as np \nimport pandas as pd \nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.naive_bayes import GaussianNB\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.svm import SVC\nfrom sklearn.preprocessing import LabelEncoder\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.model_selection import cross_val_score\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-08-12T07:30:13.140928Z","iopub.execute_input":"2022-08-12T07:30:13.141467Z","iopub.status.idle":"2022-08-12T07:30:13.359818Z","shell.execute_reply.started":"2022-08-12T07:30:13.141417Z","shell.execute_reply":"2022-08-12T07:30:13.358471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data= pd.read_csv('../input/feedback-prize-effectiveness/train.csv')\ndata.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:44:16.846139Z","iopub.execute_input":"2022-08-12T07:44:16.846816Z","iopub.status.idle":"2022-08-12T07:44:17.063080Z","shell.execute_reply.started":"2022-08-12T07:44:16.846760Z","shell.execute_reply":"2022-08-12T07:44:17.061708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(x='discourse_effectiveness',data=data)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:42:13.201964Z","iopub.execute_input":"2022-08-12T07:42:13.202501Z","iopub.status.idle":"2022-08-12T07:42:13.568145Z","shell.execute_reply.started":"2022-08-12T07:42:13.202461Z","shell.execute_reply":"2022-08-12T07:42:13.566648Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data PreProcessing**","metadata":{}},{"cell_type":"code","source":"new_data= data.drop(['discourse_effectiveness','discourse_id','discourse_text'],axis=1)\nnew_data.head(4)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:44:49.591037Z","iopub.execute_input":"2022-08-12T07:44:49.592438Z","iopub.status.idle":"2022-08-12T07:44:49.608166Z","shell.execute_reply.started":"2022-08-12T07:44:49.592381Z","shell.execute_reply":"2022-08-12T07:44:49.606481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label =LabelEncoder()\ny=label.fit_transform(data.discourse_effectiveness)\ny","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:46:07.464118Z","iopub.execute_input":"2022-08-12T07:46:07.464624Z","iopub.status.idle":"2022-08-12T07:46:07.483488Z","shell.execute_reply.started":"2022-08-12T07:46:07.464585Z","shell.execute_reply":"2022-08-12T07:46:07.482446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data.discourse_type= label.fit_transform(new_data.discourse_type)\nnew_data.essay_id= label.fit_transform(new_data.essay_id) ","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:46:51.445107Z","iopub.execute_input":"2022-08-12T07:46:51.445588Z","iopub.status.idle":"2022-08-12T07:46:51.483407Z","shell.execute_reply.started":"2022-08-12T07:46:51.445551Z","shell.execute_reply":"2022-08-12T07:46:51.481978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data.head(4)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:47:35.955716Z","iopub.execute_input":"2022-08-12T07:47:35.956238Z","iopub.status.idle":"2022-08-12T07:47:35.967348Z","shell.execute_reply.started":"2022-08-12T07:47:35.956197Z","shell.execute_reply":"2022-08-12T07:47:35.966446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Splitting Data","metadata":{}},{"cell_type":"code","source":"X_train,X_test,y_train,y_test= train_test_split(new_data,y,test_size=0.1)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:48:49.463321Z","iopub.execute_input":"2022-08-12T07:48:49.463983Z","iopub.status.idle":"2022-08-12T07:48:49.480130Z","shell.execute_reply.started":"2022-08-12T07:48:49.463926Z","shell.execute_reply":"2022-08-12T07:48:49.478666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**using Cross Validation To Pick the best Classification Algorithm**","metadata":{}},{"cell_type":"code","source":"cross_val_score(GaussianNB(),X_train,y_train,cv=5)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:51:07.205298Z","iopub.execute_input":"2022-08-12T07:51:07.205834Z","iopub.status.idle":"2022-08-12T07:51:07.294656Z","shell.execute_reply.started":"2022-08-12T07:51:07.205789Z","shell.execute_reply":"2022-08-12T07:51:07.293249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cross_val_score(MultinomialNB(),X_train,y_train,cv=5)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:51:29.669453Z","iopub.execute_input":"2022-08-12T07:51:29.671111Z","iopub.status.idle":"2022-08-12T07:51:29.748518Z","shell.execute_reply.started":"2022-08-12T07:51:29.671050Z","shell.execute_reply":"2022-08-12T07:51:29.747435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cross_val_score(DecisionTreeClassifier(),X_train,y_train,cv=5)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:52:00.582691Z","iopub.execute_input":"2022-08-12T07:52:00.584149Z","iopub.status.idle":"2022-08-12T07:52:01.159703Z","shell.execute_reply.started":"2022-08-12T07:52:00.584093Z","shell.execute_reply":"2022-08-12T07:52:01.158669Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cross_val_score(LogisticRegression(),X_train,y_train,cv=5)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:52:36.563629Z","iopub.execute_input":"2022-08-12T07:52:36.564487Z","iopub.status.idle":"2022-08-12T07:52:38.999491Z","shell.execute_reply.started":"2022-08-12T07:52:36.564426Z","shell.execute_reply":"2022-08-12T07:52:38.998081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cross_val_score(RandomForestClassifier(),X_train,y_train,cv=5)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T07:53:50.313684Z","iopub.execute_input":"2022-08-12T07:53:50.315081Z","iopub.status.idle":"2022-08-12T07:54:19.545307Z","shell.execute_reply.started":"2022-08-12T07:53:50.315017Z","shell.execute_reply":"2022-08-12T07:54:19.544018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Decison Tree Gave us Maximum Result**","metadata":{}},{"cell_type":"code","source":"model = DecisionTreeClassifier()\nmodel.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:01:00.826389Z","iopub.execute_input":"2022-08-12T08:01:00.826909Z","iopub.status.idle":"2022-08-12T08:01:00.969696Z","shell.execute_reply.started":"2022-08-12T08:01:00.826867Z","shell.execute_reply":"2022-08-12T08:01:00.968327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:01:29.594263Z","iopub.execute_input":"2022-08-12T08:01:29.594781Z","iopub.status.idle":"2022-08-12T08:01:29.609790Z","shell.execute_reply.started":"2022-08-12T08:01:29.594726Z","shell.execute_reply":"2022-08-12T08:01:29.608242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Using RandomForest**","metadata":{}},{"cell_type":"code","source":"model1 = RandomForestClassifier()\nmodel1.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:04:03.514659Z","iopub.execute_input":"2022-08-12T08:04:03.515174Z","iopub.status.idle":"2022-08-12T08:04:10.762277Z","shell.execute_reply.started":"2022-08-12T08:04:03.515131Z","shell.execute_reply":"2022-08-12T08:04:10.761288Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model1.score(X_test,y_test)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:04:26.372187Z","iopub.execute_input":"2022-08-12T08:04:26.372712Z","iopub.status.idle":"2022-08-12T08:04:26.573104Z","shell.execute_reply.started":"2022-08-12T08:04:26.372669Z","shell.execute_reply":"2022-08-12T08:04:26.571829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**load test csv file**","metadata":{}},{"cell_type":"code","source":"load= pd.read_csv('../input/feedback-prize-effectiveness/test.csv')\nload.head(4)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:09:34.017654Z","iopub.execute_input":"2022-08-12T08:09:34.018170Z","iopub.status.idle":"2022-08-12T08:09:34.037189Z","shell.execute_reply.started":"2022-08-12T08:09:34.018131Z","shell.execute_reply":"2022-08-12T08:09:34.036113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_load=load.drop(['discourse_id','discourse_text'],axis=1)\nnew_load.head(7)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:18:16.351062Z","iopub.execute_input":"2022-08-12T09:18:16.351556Z","iopub.status.idle":"2022-08-12T09:18:16.370053Z","shell.execute_reply.started":"2022-08-12T09:18:16.351507Z","shell.execute_reply":"2022-08-12T09:18:16.368187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_load.essay_id","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:18:16.612606Z","iopub.execute_input":"2022-08-12T09:18:16.613519Z","iopub.status.idle":"2022-08-12T09:18:16.623055Z","shell.execute_reply.started":"2022-08-12T09:18:16.613477Z","shell.execute_reply":"2022-08-12T09:18:16.621696Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_load.discourse_type= label.fit_transform(new_load.discourse_type)\nnew_load.essay_id= label.fit_transform(new_load.essay_id)\nnew_load.head(4)\n#new=new_load.drop(['target'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:18:31.837676Z","iopub.execute_input":"2022-08-12T09:18:31.838866Z","iopub.status.idle":"2022-08-12T09:18:31.853330Z","shell.execute_reply.started":"2022-08-12T09:18:31.838818Z","shell.execute_reply":"2022-08-12T09:18:31.852001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new.head(4)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:10:21.024090Z","iopub.execute_input":"2022-08-12T09:10:21.024543Z","iopub.status.idle":"2022-08-12T09:10:21.036278Z","shell.execute_reply.started":"2022-08-12T09:10:21.024511Z","shell.execute_reply":"2022-08-12T09:10:21.035097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission= model.predict_proba(new)\nsubmission= pd.DataFrame(submission,columns=['Ineffective','Adequate','Effective'])\n#sumbmisson['discourse_id']=load.discourse_id\nsubmission.head(4)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:10:34.199178Z","iopub.execute_input":"2022-08-12T09:10:34.199685Z","iopub.status.idle":"2022-08-12T09:10:34.235107Z","shell.execute_reply.started":"2022-08-12T09:10:34.199644Z","shell.execute_reply":"2022-08-12T09:10:34.233956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data1= pd.concat([load.essay_id,submission],axis=1)\nnew_data1","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:23:09.592327Z","iopub.execute_input":"2022-08-12T09:23:09.592710Z","iopub.status.idle":"2022-08-12T09:23:09.608127Z","shell.execute_reply.started":"2022-08-12T09:23:09.592679Z","shell.execute_reply":"2022-08-12T09:23:09.607090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_data1.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T09:41:00.818014Z","iopub.execute_input":"2022-08-12T09:41:00.818482Z","iopub.status.idle":"2022-08-12T09:41:00.825948Z","shell.execute_reply.started":"2022-08-12T09:41:00.818447Z","shell.execute_reply":"2022-08-12T09:41:00.824617Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**TESTING THE TRAIN MODEL ON TEST DATASET**","metadata":{}},{"cell_type":"code","source":"#Using Decision Tree Classifier\n\nimport joblib\njoblib.dump(model,'job_l')\ntest= joblib.load('job_l')\np= test.predict(new_load)\ntest.score(new_load,p)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:31:34.334882Z","iopub.execute_input":"2022-08-12T08:31:34.335312Z","iopub.status.idle":"2022-08-12T08:31:35.018478Z","shell.execute_reply.started":"2022-08-12T08:31:34.335278Z","shell.execute_reply":"2022-08-12T08:31:35.017320Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Using Random Forest Classifier\n\nimport joblib\njoblib.dump(model1,'job_l')\ntest= joblib.load('job_l')\np= test.predict(new_load)\ntest.score(new_load,p)","metadata":{"execution":{"iopub.status.busy":"2022-08-12T08:14:12.635050Z","iopub.execute_input":"2022-08-12T08:14:12.635493Z","iopub.status.idle":"2022-08-12T08:14:13.215653Z","shell.execute_reply.started":"2022-08-12T08:14:12.635455Z","shell.execute_reply":"2022-08-12T08:14:13.214417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}