Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 4 . 1 1 HW 2 _ LAB 4 : Prediction with Logistic Regression Run your program as often as you'd like, before submitting
HWLAB: Prediction with Logistic Regression Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
second box.
This lab will be available until June st: PM EDT
The file InvisticoAirlineLRcsv contains information from an airline using the alias Invistico Airline on customer satisfaction, as well as
details on each customer. The columns of interest are Gender, Age, Class, ArrivalDelayinMinutes, and satisfaction.
Read the file InvisticoAirlineLRcsv into a data frame.
Obtain user defined values female, age, economy, and delay.
Recode the categorical variables Gender, Class, and satisfaction into dummy variables.
Create a new data frame X from the predictor variables Genderfemale, Age, ClassEco, and ArrivalDelayinMinutes, in that order.
Create a response variable from the dummy variable satisfactionsatisfied.
Perform logistic regression on and
Use the user defined values to predict the probability that a customer with those values is satisfied.
Ex: If the input is the ouput is:
here is the code:
# import the necessary modules
import pandas as pd
female intinput
age floatinput
economy intinput
delay floatinput
# read in the file InvisticoAirlineLRcsv
flights pdreadcsv InvisticoAirlineLRcsv
# remove missing data
flights.dropnaaxis inplace True
# recode the categorical variables Gender, Class, and satisfaction as dummy variables
flights pdgetdummies flights columnsGender 'Class', 'satisfaction' dropfirst True
# create a new data frame from the variables GenderFemale, Age, ClassEco, and ArrivalDelayinMinutes, in that order.
X flightsGenderfemale', 'Age', 'ClassEco', 'ArrivalDelayinMinutes'
X addconstantX
Y flightssatisfactionsatisfied'
# set Y as the response variable satisfactionsatisfied
# perform logistic regression on X and Y
model LogitY Xfit
# create an array with for the intercept, and the user input values female, age, economy, and delay
ex female, age, economy, delay
prediction model.predictex
# find the predicted probablility that a customer with the user input values is satisfied
printprediction
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started