You are on page 1of 7
2115122, 048 AM In [1]: import pandas as pd import numpy as np import warnings warnings. filterwarnings("ignore") import seaborn as sns In [38]: mydata=pd.read_csv("bank-additional-full.csv", sep: In [39]: mydata ‘SYM CLASS PROJECT -Jupyter Notebook out{39]: age job marital ducation default housing loan contact month day. 056 housemaid marred basicéyn0.—=~=«no.—no. telephone may 457 services married high school unknown nono. telephone may 257 services. maried highschool no—=«yes_— no. telephone may 340 admin, marred basicéy no-no. telephone may 456 services: married highschool —-—sno.—=Ssno_yes. telephone may 41183. 73. retired married professionalcourse —-no.=Ssyes, no cllar nov 41104 45 blue-collar married professionalcourse non n—cellar. nov 41185 5 retired married universiy.degree = no.=Ssyes, «no. celllar nov 41106 44 technician married professionalcourse nono. n cellar nov 41187 74 retired maried professionalcourse —-no.=Ssyes,n.cellar— nov 41188 rows * 21 columns localhost 8888inotebooks/SVM CLASS PROJECT.pynb 4 2115122, 048 AM ‘SYM CLASS PROJECT -Jupyter Notebook In [23]: mydata.info() Rangelndex: 41188 entries, @ to 41187 Data columns (total 21 columns): # Column Non-Null Count vty; @ age 41188 non-null int 1 job 41188 non-null obj 2 marital 41188 non-null obj 3 education 41188 non-null obj 4 default 41188 non-null obj 5 housing 41188 non-null obj 6 loan 41188 non-null obj 7 contact 41188 non-null obj 8 month 41188 non-null obj 9 day of_week 41188 non-null obj 1@ duration 41188 non-null int 11 campaign 41188 non-null int 12 pdays 41188 non-null int 13 previous 41188 non-null int 14° poutcome 41188 non-null obj 15 emp.var.rate 41188 non-null flo: 16 cons.price.idx 41188 non-null flo: 17 cons.conf.idx 41188 non-null flo: 18 euribor3m 41188 non-null lo 19 nr.employed 41188 non-null flo: 20 y 41188 non-null obj dtypes: floatea(s), int6a(s), object(11) memory usage: 6.6+ MB In [25]: mydata.describe() pe 64 ject ject ject, ject. ject, ject, ject, ject, ject, 64 64 64 64 ject, ated ated ated ated ates ject, out [25]: age duration campaign pdays previous emp.varrate cons.pri ‘eount 41188,00000 41188.000000 41188,000000 41188,000000 41188.000000 41188.000000 4188.0 mean 40.02406 258.285010 2.867593 962.475454 0.172963 «0.081886 93.5 std 1042125 259.279249 «2.770014 186.910907 0.494901 1.570960 os min 17.0000 «0.000000 -~—=«1.000000-©»«0.000000 ©» 0,000000-«-3.400000 922 25% — 32,00000 102.0000 —1,000000 + 999,000000 0.000000 -1,800000 «93.0 50% 38,00000 180.000000 2.000000 999.0000 0.000000 «1.100000 «93.7 75% 47.0000 319.000000 3.000000 999.000000 0.000000 «1.400000 93.9. max 98,0000 4918.000000 56,0000 999.0000 7.000000 «1.400000 94,7 localhost 8888inotebooks/SVM CLASS PROJECT.pynb » 211522, 948 AM ‘SVM GLASS PROJECT - Jupyter Notebook In [26]: mydata.isnull().sum() out [26]: age job marital education default housing Joan contact month day_of_week duration campaign pdays previous poutcone emp.var.rate cons.price. idx cons.conf. idx euribor3n nr employed y dtype: intes In [40]: mydata-nydata.drop("job",axis=1) In [41]: mydata-nydata.drop(" education" axis=1) In [42]: mydata=mydata.drop("default", axis=1 In [43]: mydata=nydata.drop("month" , axis=1; In [44]: mydata=nydata.drop("day_of_week" , axis=1) localhost 8888inotebooks/SVM CLASS PROJECT.pynb 2115122, 048 AM ‘SYM CLASS PROJECT -Jupyter Notebook In [45]: mydata out 45]: age marital housing loan contact duration campaign pdays previous poutcome ei 0 56 married nono telephone 261 1 999 0 nonexistent 1 ST mamied nono. telephone 149 1 999 0 nonexistent 2 37 maried yes no. telephone 226 1 999 0 nonexistent 3 40 married nono. telephone 151 1 999 0 nonexistent 4 56 manied —no_yes telephone 307 + 999 0 nonexistent 41183. 73 married yes. no. collar, «334 1+ 9099 0 nonexistent 4118448 married nono caller 383 + 999 0 nonexistent 41185 55 married yes. no. collar, 189 2 999 © nonexistant 4118644 martied nono cellular 442 + 999 © nonexistent 4187 74 married yes. no collar 288 3 999 1 tallure 41188 rows x 16 columns In [46]: from sklearn.preprocessing import Labelencoder In [47]: le=Labelencoder() In [48]: mydata[ "marital: le. Fit_transform(mydata.marital) In [49]: mydata["housing’ le. Fit_transform(mydata. housing) In [58]: mydata["loan"]=1e. fit_transform(mydata.loan) In [51]: mydata["contact” ]=le.it_transform(mydata. contact) In [52]: mydata["poutcome" ]=1e.fit_transform(mydata.poutcome) In [53]: mydata["y"]=1e.fit_transform(nydata.y) localhost 8888inotebooks/SVM CLASS PROJECT.pynb 2115122, 048 AM ‘SYM CLASS PROJECT -Jupyter Notebook In [54]: mydata out(s4]: ‘age marital housing loan contact duration campaign 0 56 1 oO 1261 1 1 97 1 oo 1 149 1 999 ° 1 2 37 1 2 0 1 226 1 999 ° 1 3 40 1 oo 1 181 1 999 ° 1 4 56 1 0 2 1 307 1 999 ° 1 ames 734 200 0334 1 999 ° 1 aes 46 0 0 a8 1 999 ° 1 ames 55 200 0 189 2 999 ° 1 4ne8 44 1 0 0 0 aaa, 1 999 ° 1 ane 44 200 0 239 3 999 1 ° 41188 rows x 16 columns In [55]: mydata_corr=mydata.corr localhost 8888inotebooks/SVM CLASS PROJECT.pynb 2115122, 048 AM ‘SYM CLASS PROJECT -Jupyter Notebook In [56]: mydata_corr() out (56): ‘age marital housing loan contact duration campaign —_pday: age 1.000000 -0.389753 -0,001603 -0.007368 0.007021 -0.000866 0.004594 -0.03436) ‘marital -0.389753 1.000000 0.010467 0.005788 -0.054501 0.010290 -0.007240 -0.03794: housing -0.001603 0.010467 1.000000 0.044296 0.082186 0.007658 -0,011010 -0.01055 Joan -0.007368 0.005788 0.044296 1.000000 0.008556 0.000916 0.005166 0.00034 contact 0.007021 -0.054501 -0.082186 -0.008558 1.000000 -0.028657 0.077368 0.117971 duration -0,000866 0.010290 -0,007658 -0,000916 -0.026657 1.000000 -0.071699 -0.04757 campaign 0.004594 -0.007240 -0.011010 0.005166 0.077368 -0.071889 1.000000 0.05258: Pdays -0.034969 -0.037942 0.010551 0.000845 0.117970 0.047577 0.052584 1.000001 provious 0.024365 0.038689 0.021314 -0.001327 -0.212848 0.020640 -0.079141 0.58751 outcome 0,019750 0,001912 0.011783 0.001811 0.118744 0,033360 0.032586 0.47561 emp.varrate -0,000371 -0,084210 -0.060196 0.001849 0.393584 -0.027968 0.150754 0.27100 cons.price.idx 0.000857 0.057477 0.080504 0.002430 0.591474 0.005312 0.127836 0.07888" cons.contidx 0.129372 -0.033783 -0,033845 -0,012025 0.251614 -0,008173 -0.013733 -0,09134: euribor3m 0.010767 0.091939 0.059277 0.000125 0.309773 0.032897 0.135133 0.29889: nremployed -0.017725 -0.086199 -0.045862 0.003903 0.269155 -0.044703 0.144095 0.37260: y 0.030399 0.046203 0.011552 -0.004909 -0.144773 0.405274 0.086357 0.32491 » In [57]: x_ind=nydata.drop("y",axis=1) In [58]: y_dep=mydata.y In [59]: from sklearn.model_selection import train _test_split In [60]: x_train,x_test,y_train,y test-train_test_split(x_ind,y_dep,test_size-9.2,random_s In [61]: from sklearn.svm import svc In [62]: model=SVC(kerne’ Linear” In [63]: fit_model=model.fit(x_train,y_train) In [65]: y_pred=fit_model.predict(x_test) In [66]: y_pred Out[66]: array([®, ® 8, .--, @ 8 2]) localhost 8888inotebooks/SVM CLASS PROJECT.pynb 2115122, 048 AM In [67]: In [68]: out (68): In [69]: out [69]: In [70]: out [79]: In [71]: In [72]: In [ ‘SYM CLASS PROJECT -Jupyter Notebook from sklearn.metrics import confusion_matrix,accuracy_score confusion_natrix(y_test,y_pred) array([{[7147, 171], [ 695, 315]], dtype=intea) accuracy_score(y_test,y_pred) @.9058023792182569 fit_model .n_support_ array([2118, 2112]) kernel=| linear", "poly", "rbf", "sigmoid"] for i in kernel: mmodel1=SVC(kernel=i) modeli=nodel.fit(x_train,y train) print("kernel: ",i,) print("Ace score: ",accuracy_score(y test,model1.predict(x_test))) kernel: linear Acc score: @,9058023792182569 kernel: poly Acc score: @,905823792182569 kernel: rbf Acc score: @,905823792182569 kernel: sigmoid Acc score: @,9@5823792182569, localhost 8888inotebooks/SVM CLASS PROJECT.pynb

You might also like