Answered step by step
Verified Expert Solution
Link Copied!

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

14.11 HW2_LAB4: 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 21st,11:59 PM EDT
The file Invistico_Airline_LR.csv 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, Arrival_Delay_in_Minutes, and satisfaction.
Read the file Invistico_Airline_LR.csv into a data frame.
Obtain user defined values female, age, economy, and delay.
Re-code the categorical variables Gender, Class, and satisfaction into dummy variables.
Create a new data frame X from the predictor variables Gender_female, Age, Class_Eco, and Arrival_Delay_in_Minutes, in that order.
Create a response variable Y from the dummy variable satisfaction_satisfied.
Perform logistic regression on x and Y.
Use the user defined values to predict the probability that a customer with those values is satisfied.
Ex: If the input is 134010 the ouput is:
[0.62343979]
here is the code:
# import the necessary modules
import pandas as pd
female = int(input())
age = float(input())
economy = int(input())
delay = float(input())
# read in the file Invistico_Airline_LR.csv
flights = pd.read_csv ('Invistico_Airline_LR.csv')
# remove missing data
flights.dropna(axis =0, inplace = True)
# recode the categorical variables Gender, Class, and satisfaction as dummy variables
flights = pd.get_dummies (flights, columns=['Gender', 'Class', 'satisfaction'], drop_first = True)
# create a new data frame from the variables Gender_Female, Age, Class_Eco, and Arrival_Delay_in_Minutes, in that order.
X = flights[['Gender_female', 'Age', 'Class_Eco', 'Arrival_Delay_in_Minutes']]
X = add_constant(X)
Y = flights['satisfaction_satisfied']
# set Y as the response variable satisfaction_satisfied
# perform logistic regression on X and Y
model = Logit(Y, X).fit()
# create an array with 1 for the intercept, and the user input values female, age, economy, and delay
ex =[1, female, age, economy, delay]
prediction = model.predict(ex)
# find the predicted probablility that a customer with the user input values is satisfied
print(prediction)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

What reward policy would you suggest to the university?

Answered: 1 week ago