From 7f68e65c6e13cd7f5f01513e1848053d86949464 Mon Sep 17 00:00:00 2001 From: santoshmayekar Date: Tue, 12 Jun 2018 06:54:20 +0000 Subject: [PATCH] Done --- __pycache__/__init__.cpython-36.pyc | Bin 150 -> 152 bytes .../__pycache__/__init__.cpython-36.pyc | Bin 166 -> 168 bytes .../__pycache__/build.cpython-36.pyc | Bin 809 -> 1122 bytes q01_grid_search/build.py | 29 +++++++----- .../tests/__pycache__/__init__.cpython-36.pyc | Bin 172 -> 174 bytes .../test_q01_grid_search.cpython-36.pyc | Bin 4199 -> 4201 bytes q02_fit/__pycache__/__init__.cpython-36.pyc | Bin 158 -> 160 bytes q02_fit/__pycache__/build.cpython-36.pyc | Bin 1316 -> 1566 bytes q02_fit/build.py | 44 ++++++++++++------ .../tests/__pycache__/__init__.cpython-36.pyc | Bin 164 -> 166 bytes .../__pycache__/test_q02_fit.cpython-36.pyc | Bin 2960 -> 2658 bytes 11 files changed, 46 insertions(+), 27 deletions(-) diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index 494c0e423d78629e57676c58ba01e9e4fe944241..f32997380ab4ab3fb0962176f2c234b394d64fdc 100644 GIT binary patch delta 56 zcmbQnID?VHn3tF9*fO^0i5%uCuKF4IxvBcaiFqaY#TmJYm8sc@Mf&0SMcKs#iOH$@ L$@wX%6BA7V`3MtM delta 54 zcmbQiIE|6Rn3tF9PJCn3L=JN$XZ?))+*JMaqSVU7lKfnKm;B_?+|<01V*P-k{H)aE JlH!TUrU2P=63qYr diff --git a/q01_grid_search/__pycache__/__init__.cpython-36.pyc b/q01_grid_search/__pycache__/__init__.cpython-36.pyc index eed5319ad7e677d36d4aa0a041666797cfc18e79..c48ee1979feea3ad6cea9b23f2fa7213ef99fb3e 100644 GIT binary patch delta 56 zcmZ3+xPp8q!W|GPe^5BE`ywudd_#bZ$KX;+OcT?`XgQ zk~xgjo-!9b&Ai-aKCydl7UT`qsIiCfkcGq%#*on z^j;n52wy~^0}TkFdF6fdSeH$)X*L5bXhXE;LI=7qg?<`lpo4xEBXj8IKYMIeG++Tw zE?!YK2lrtK?tUU{9>|WLgS7+c)t1(f-#Qet!?<4UE2 zR7l*3Hf0Jsg3Dxo1*C~i%VITA$76!o_f{@{z5e#_$BS_jS3PQ) z*O#Pc!bGyZAy%4eVLWvt_1MF|jF**r>*E%}@wzo9);zLi-WuN;il*n8DCZ~fKyW?6 zGEG#(SZtbeT}ow|b`Qi*@0+fLnc#!CC_$(`WIEX2rbmu{hTttn^uY#&EaFJwhtLL)jzp6}Y$R*F? zJ*3dko1s{NdwibF2@?@D>7 zhCC7d1he)hIt}VkK$Xh_k?8)>eh%^BL)W|d@e3}3O23Y&QTx-Tf sGVAJV?rxa}wvzA}7C6epb36CSvKx{Rd&ZZx$Re4gOVma}(xnmo3;nY}7ytkO delta 483 zcmYk0ze`*}5XX1-{c!Jj?>x^$PfNQ4@q(6-V38(G5NyH{IM$oF=R5bkckDhRRu*Cv zEW)*h)VBUPTP6??(g`WjB=Zc2Gwk;}^BHED@A5Xj*iF;q_uV)3RWSC0J&Ty?eR}SW z1Q>9`6hk)UATBxoPlO6+5}2@vRP@L~6Bi3=;jxa0OC>qOVA_KClB)!h=^}98SAul) zN=$OG&Q$vuUYj%|#R%J&f`k?%*Wt%db<~pTs%2P&Hl$eq9aw@c`7-pNL%u@f1^LUH zQ1yTxvO)iz4rlLuoM&Za@yoA=o%_EOwoiDl;^mpPWnN~^cP6>1(LVL@OqZaY7c-cD z4mREewBWn$#2{^KW9hIsGH64>Hfm2d_R);`QlHTKbm(UCSjI&W;7#>#z4l|4Ax~_`h+iHATU|GB2fvu)EuH8HhUTw*} dqJmR{Z<@2*28rYem%QDiNcbx6i9YpB{sTj)fII*I diff --git a/q01_grid_search/build.py b/q01_grid_search/build.py index 20c99a1..fa05dd1 100644 --- a/q01_grid_search/build.py +++ b/q01_grid_search/build.py @@ -1,22 +1,27 @@ -# Default imports - -import warnings -warnings.filterwarnings("ignore") import pandas as pd +import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import GridSearchCV loan_data = pd.read_csv('data/loan_prediction.csv') -X_bal = loan_data.iloc[:, :-1] -y_bal = loan_data.iloc[:, -1] +X = loan_data.iloc[:, :-1] +y = loan_data.iloc[:, -1] + +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=9) + +param_grid1 = {'max_features': ['sqrt', 4, 'log2'], + 'n_estimators': [10, 50, 120], + 'max_depth': [40, 20, 10], + 'max_leaf_nodes': [5, 10, 2]} -X_train, X_test, y_train, y_test = train_test_split(X_bal, y_bal, test_size=0.33, random_state=9) -param_grid = {"max_features": ['sqrt', 4, "log2"], - "n_estimators": [10, 50, 120], - "max_depth": [40, 20, 10], - "max_leaf_nodes": [5, 10, 2]} +rfc = RandomForestClassifier(oob_score=True ,random_state=9) +def grid_search(X_train1, y_train1,modelR,params,cv=3): + GSCV_rfc = GridSearchCV(estimator=modelR, param_grid=params, cv=cv) + GSCV_rfc.fit(X_train1,y_train1) + param_list = GSCV_rfc.cv_results_['params'] + score1 = GSCV_rfc.cv_results_['mean_test_score'] + return GSCV_rfc,param_list,score1 -# Write your solution here : diff --git a/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc b/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc index 31ac32889b610935d2c1830c3823c926b02a7da2..43b7ea297cbd185d65e91469c6c098e90ed26f7e 100644 GIT binary patch delta 56 zcmZ3(xQ>y-n3tDp!58l6i5%uC(fS$rxvBcaiFqaY#TmJYm8sc@Mf&0SMcKs#iOH$@ L$@wX%6BE4w4dxTu delta 54 zcmZ3-xQ3C#n3tF9hU2`bi5%uik@^|=xvBc;MX8mECHcAfF8Rr&xv6<2#rgq7`B|yS JCB+kyy#eIc6CeNp diff --git a/q01_grid_search/tests/__pycache__/test_q01_grid_search.cpython-36.pyc b/q01_grid_search/tests/__pycache__/test_q01_grid_search.cpython-36.pyc index bf1afbe383899abd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motTK4l@t6h--w*Cj2_z0}@z788G10uyk80t@N&*#Nt^uOngPM>|8-Kq4E zJy#gc@Rs}m7!}p1WKi(AyvdeHluemF_-`I4=kQcG+zZN8gy!u2?JTP#D<_-@^C!`< zV1#B+&^obIZt7k81+Q}*yvZhn>tJbB1WcHBBOaM;5%6J0kIl#v(_FVKxi)xlWYCtq yhebEGeV8^!mX$lg6uXX}mo;5*_L(UIX?(<}gZ7|zycQau9d`(JY`>m6^#27_uYmmk diff --git a/q02_fit/build.py b/q02_fit/build.py index fbafb1a..8ae4522 100644 --- a/q02_fit/build.py +++ b/q02_fit/build.py @@ -1,27 +1,41 @@ -# Default imports - import pandas as pd -from greyatomlib.random_forest_project.q01_grid_search.build import grid_search -from sklearn.metrics import confusion_matrix, accuracy_score, classification_report +import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier - +from sklearn.model_selection import GridSearchCV +from sklearn.metrics import confusion_matrix +from sklearn.metrics import classification_report +from sklearn.metrics import accuracy_score loan_data = pd.read_csv('data/loan_prediction.csv') -X_bal = loan_data.iloc[:, :-1] -y_bal = loan_data.iloc[:, -1] +X = loan_data.iloc[:, :-1] +y = loan_data.iloc[:, -1] + +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=9) + +param_grid1 = {'max_features': ['sqrt', 4, 'log2'], + 'n_estimators': [10, 50, 120], + 'max_depth': [40, 20, 10], + 'max_leaf_nodes': [5, 10, 2]} -X_train, X_test, y_train, y_test = train_test_split(X_bal, y_bal, test_size=0.33, random_state=9) -rfc = RandomForestClassifier(oob_score=True, random_state=9) -param_grid = {"max_features": ['sqrt', 4, "log2"], - "n_estimators": [10, 50, 120], - "max_depth": [40, 20, 10], - "max_leaf_nodes": [5, 10, 2]} +rfc = RandomForestClassifier(oob_score = True,random_state=9) -grid, grid_param, grid_score = grid_search(X_train, y_train, rfc, param_grid, cv=3) +def grid_search(X_train1, y_train1,modelR,params,cv): + GSCV_rfc = GridSearchCV(estimator=modelR, param_grid=params, cv=3) + GSCV_rfc.fit(X_train1,y_train1) + param_list = GSCV_rfc.cv_results_['params'] + scoreA = GSCV_rfc.cv_results_['mean_test_score'] + return GSCV_rfc,param_list,scoreA +GSCV_rfc1,param_list1,score1 = grid_search(X_train, y_train,rfc,param_grid1,3) -# Write your solution here : +model = GSCV_rfc1.best_estimator_ +y_pred = model.fit(X_train, y_train).predict(X_test) +def fit(X_test,y_test): + acc_score = accuracy_score(y_test, y_pred) + conf_matrix = confusion_matrix(y_test, y_pred) + c_report = classification_report(y_test, y_pred) + return conf_matrix,c_report,acc_score diff --git a/q02_fit/tests/__pycache__/__init__.cpython-36.pyc b/q02_fit/tests/__pycache__/__init__.cpython-36.pyc index 4a01850f21d216d8ccbec7c32d5325e707bae019..ff396da300cec3cf57b08ad992a2742777170aa5 100644 GIT binary patch delta 56 zcmZ3&xQvm*n3tF9*fO^0i5%uC!TK5bxvBcaiFqaY#TmJYm8sc@Mf&0SMcKs#iOH$@ L$@wX%6BC^Q0ZS8( delta 54 zcmZ3+xP+0zn3tF9hU2`bi5%uif%+NwxvBc;MX8mECHcAfF8Rr&xv6<2#rgq7`B|yS JCB+kyodMui6951J diff --git a/q02_fit/tests/__pycache__/test_q02_fit.cpython-36.pyc b/q02_fit/tests/__pycache__/test_q02_fit.cpython-36.pyc index 413b2fcb0350f27eb149eb2d1be1830ba8545d0c..72e2af49da4a3cb0914573608c3f31a2ce4ddd1b 100644 GIT binary patch delta 561 zcmaiw&o2W(6vsQ;)o!O81Z_(F)>a#_5>LT%}nuO>0vhBj382oG~!n+={94YEj+VW z_Dp73bpM5iL-ur%M_Veg=!Jfss<{rjf{1t$X3^QMTsz)r~SL-!Y@I`iUgv`~xt*Yc|nu2O?