Question: Please from the attached PDF; Please can you assist with code for questions in lines 14 , 15, 16, 17, 20, 21, 22, 23, 26,

Please from the attached PDF;

Please can you assist with code for questions in lines 14 , 15, 16, 17, 20, 21, 22, 23, 26, 27, 28, 29, 32, 33, 34, 35, last line

Please from the attached PDF;Please can you assist with code for questionsin lines 14 , 15, 16, 17, 20, 21, 22, 23, 26,27, 28, 29, 32, 33, 34, 35, last line Out [3] :InMichelin Restaurant Name Food Decor Service Price 0 0 14 Wall Street19 20 19 50 O 212 17 17 16 43 N 0

Out [3] : InMichelin Restaurant Name Food Decor Service Price 0 0 14 Wall Street 19 20 19 50 O 212 17 17 16 43 N 0 26 Seats 23 17 21 35 44 19 23 16 52 4 0 A 23 12 19 24 In [4]: MichelinNY . describe ( ) Out [4] : InMichelin Food Decor Service Price count 164.000000 164.000000 164.000000 164.000000 164.000000 mean 0.451220 21.243902 19.164634 19.701220 50.097561 std 0.499139 2.776152 3.792594 3.263819 22.129352 min 0.000000 15.000000 12.000000 13.000000 13.000000 25% 0.000000 19.000000 16.000000 17.000000 39.000000 50% 0.000000 21.000000 19.000000 19.000000 45.000000 75% 1.000000 23.000000 22.000000 21.250000 53.000000 max 1.000000 28.000000 28.000000 28.000000 201.000000 In [5]: import statsmodels . api as sm MichelinNY [ ' Intercept ' ] = np. ones( (len(MichelinNY) , ) ) MichelinNY . head (5) Out [5] : InMichelin Restaurant Name Food Decor Service Price Intercept 0 14 Wall Street 19 20 19 50 1.0 0 212 17 17 16 43 1.0 N 0 26 Seats 23 17 21 35 1.0 44 19 23 16 52 1.0 A 23 12 19 24 1.0 In [6]: "Set Food and Intercept as predictors, and the target is InMichelin. "!' X_logit = MichelinNY[ [ 'Food' , ' Intercept' ]] . values Y_logit = MichelinNY[ 'InMichelin' ]. values . astype (np. float) "Perform the fit with Logit method. " ! ' logitReg = sm. Logit(Y_logit, x_logit) logit_fit = logitReg . fit()X_logit_all = MichelinNY[[ 'Food', 'Decor', 'Service', 'Price', 'Intercept' ]]. values Y_logit = MichelinNY[ 'InMichelin' ]. values . astype (np. float ) "perform the fit with Logit method. ' ! ' logitReg_all = sm. Logit (Y_logit, X_logit_all) logit_fit_all = logitReg_all. fit( ) Optimization terminated successfully. Current function value: 0. 452430 Iterations 7 C:\\Users\\phemm\\AppData\\Local\\Temp\\ipykernel_28188\\781382260. py:7: DeprecationWarning use "float by itself. Doing this will not modify any behavior and is safe. If you s Deprecated in NumPy 1.20; for more details and guidance: https:/umpy . org/devdocs/r Y_logit = MichelinNY[ ' InMichelin' ] . values . astype (np. float) In [13]: logit_fit_all. summary ( ) Out [13 ] : Logit Regression Results Dep. Variable: y No. Observations: 164 Model: Logit Df Residua 159 Method: MLE Df Model: Date: Mon, 12 Dec 2022 Pseudo R-squ.: 0.3428 Time: 22:01:24 Log-Likelihood: -74.198 converged: True LL-Null: -112.89 Covariance Type: nonrobust LLR p-value: 6.213e-16 coef std err z P>/z| [0.025 0.975] x1 0.4048 0.131 3.080 0.002 0.147 0.662 x2 0.1000 0.089 1.121 0.262 -0.075 0.275 x3 -0.1924 0.124 -1.557 0.119 -0.435 0.050 x4 0.0917 0.032 2.889 0.004 0.029 0.154 const -11.1975 2.309 -4.850 0.000 -15.723 -6.672 In [14]: # Calculate the Probability to be included in Catalog, # predicted by this 'logit_fit_all' model In [15]: # Calculate values predicted by this model, # and add new column to DataFrame with prediction In [16]: # calculate Confusion Matrix using Pandas crosstab( ) method In [17]: # Find accuracy of this model using formula ACC=(TP+TN)/NIn [18 ] : # Let's try model with 3 variables and Intercept # Decor variable was dropped X_logit_3 = MichelinNY[ [ 'Food', 'Service', 'Price', 'Intercept' ]]. values Y_logit = MichelinNY[ ' InMichelin' ] . values . astype (np. float ) "Perform the fit with Logit method. ' ! ' logitReg_3 = sm. Logit (Y_logit, X_logit_3) logit_fit_3 = logitReg_3. fit() Optimization terminated successfully. Current function value: 0. 456301 Iterations 7 /var/folders/57/b7cbk2zx5qgowczw9nj9jxqm0000gn/T/ipykernel_13477/20751649 ce this warning, use float by itself. Doing this will not modify any be Deprecated in NumPy 1.20; for more details and guidance: https:/umpy. or Y_logit = MichelinNY[ 'InMichelin' ]. values . astype (np . float) In [19]: logit_fit_3. summary ( ) Out [19] : Logit Regression Results Dep. Variable: y No. Observations: 164 Model: Logit Df Residuals: 160 Method: MLE Df Model: 3 Date: Mon, 12 Dec 2022 Pseudo R-squ.: 0.3371 Time: 22:01:47 Log-Likelihood: -74.833 converged: True LL-Null: -112.89 Covariance Type: nonrobust LLR p-value: 2.083e-16 coef std err z P>/z| [0.025 0.975] x1 0.4317 0.128 3.363 0.001 0.180 0.683 x2 -0.2037 0.122 -1.672 0.094 -0.442 0.035 x3 0.1135 0.026 4.392 0.000 0.063 0.164 const -10.6559 2.261 -4.713 0.000 -15.088 -6.224 In [20]: # Calculate the Probability to be included in Catalog, # predicted by this 'logit_fit_3' model In [21] : # Calculate values predicted by this model, # and add new column to DataFrame with prediction In [22]: # calculate Confusion Matrix using Pandas crosstab( ) method In [23]: # Find accuracy of this model using formula ACC=(TP+TN)/NIn [24]: # Now we can try another model with 3 variable and Intercept. # This time the Service variable is dropped. X_logit_3d = MichelinNY[ [ 'Food', 'Decor', 'Price', 'Intercept' ]]. values Y_logit = MichelinNY[ ' InMichelin' ]. values . astype (np. float ) perform the fit with Logit method. ! ! ' logitReg_3d = sm. Logit(Y_logit, X_logit_3d) logit_fit_3d = logitReg_3d . fit( ) Optimization terminated successfully. Current function value: 0. 459952 Iterations 7 /var/folders/57/b7cbk2zx5qgowczw9nj9jxqm0000gn/T/ipykernel_13477/592995128. e this warning, use "float by itself. Doing this will not modify any behavi Deprecated in NumPy 1.20; for more details and guidance: https:/umpy.org/ Y_logit = MichelinNY[ 'InMichelin' ]. values . astype (np. float) In [25]: logit_fit_3d . summary( ) Out [ 25 ] : Logit Regression Results Dep. Variable: y No. Observations: 164 Model: Logit Df Residuals: 160 Method: MLE Df Model: 3 Date: Mon, 12 Dec 2022 Pseudo R-squ.: 0.3318 Time: 22:02:08 Log-Likelihood: -75.432 converged: True LL-Null: -112.89 Covariance Type: nonrobust LLR p-value: 3.761e-16 coef std err z P>|z| [0.025 0.975] x1 0.2893 0.110 2.619 0.009 0.073 0.506 x2 0.1140 0.089 1.286 0.198 -0.060 0.288 x3 0.0694 0.029 2.419 0.016 0.013 0.126 const -11.7168 2.278 -5.143 0.000 -16.182 -7.252 In [26]: # Calculate the Probability to be included in Catalog, # predicted by this 'logit_fit_3d' model In [27]: # Calculate values predicted by this model, # and add new column to DataFrame with prediction In [28]: # calculate Confusion Matrix using Pandas crosstab( ) method In [29]: # Find accuracy of this model using formula ACC=(TP+TN)/NIn [30]: # Finally, we can try model with only two varables Food and Price X_logit_2 = MichelinNY[ [ 'Food', 'Price', 'Intercept' ]]. values Y_logit = MichelinNY[ ' InMichelin' ]. values . astype (np. float) "perform the fit with Logit method. ! ! ' logitReg_2 = sm. Logit(Y_logit, X_logit_2) logit_fit_2 = logitReg_2. fit( ) Optimization terminated successfully. Current function value: 0. 465088 Iterations 7 /var/folders/57/b7cbk2zx5qgowczw9nj9jxqm0000gn/T/ipykernel_13477/80785423 e this warning, use 'float by itself. Doing this will not modify any beh Deprecated in NumPy 1.20; for more details and guidance: https:/umpy . or Y_logit = MichelinNY[ 'InMichelin' ] . values . astype(np. float) In [31]: logit_fit_2. summary ( ) Out [ 31] : Logit Regression Results Dep. Variable: y No. Observations: 164 Model: Logit Df Residuals: 161 Method: MLE Df Model: 2 Date: Mon, 12 Dec 2022 Pseudo R-squ.: 0.3244 Time: 22:02:26 Log-Likelihood: -76.274 converged: True LL-Null: -112.89 Covariance Type: nonrobust LLR p-value: 1.248e-16 coef std err z P>/z] [0.025 0.975] x1 0.3133 0.109 2.876 0.004 0.100 0.527 x2 0.0932 0.023 4.086 0.000 0.048 0.138 const -11.1674 2.242 -4.982 0.000 -15.561 -6.774 In [32]: # Calculate the Probability to be included in Catalog, # predicted by this 'logit_fit_2' model In [33]: # Calculate values predicted by this model, # and add new column to DataFrame with prediction In [34]: # calculate Confusion Matrix using Pandas crosstab( ) method In [35]: # Find accuracy of this model using formula ACC=(TP+TN)/N In [ ]: # Which model is the most accurate

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!