Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question: Implement Logistic regression using NumPy. You should implement your code in the provided logistic _ regression.py file. This python file takes two csv files
Question:
Implement Logistic regression using NumPy. You should implement your code in the provided logisticregression.py file. This python file takes two csv files as inputs, which are training and testing csv files. For example, in the following usage scenario, logtraining.csv is the training input csv file and logtesting.csv is the testing input csv file.
$python logisticregression.py logtraining.csv logtesting.csv
Output the Accuracy score of prediction.
provided logisticregression.py file is as follow:
import numpy as np
import pandas as pd
import math
import sys
import os
#todo define necessary functions
def logisticregressionxtrain ytrain, xtest, ytest:
return: Accuracy value
#todo fill code here
return
# do not modify this function
def loaddata:
trainfilename sysargv
testfilename sysargv
trainfeaturematrix pdreadcsvtrainfilename
testfeaturematrix pdreadcsvtestfilename
trainfeaturematrix trainfeaturematrix.dropna
testfeaturematrix testfeaturematrix.dropna
XTRAIN trainfeaturematrix.iloc: :lentrainfeaturematrix.columns
YTRAIN trainfeaturematrix.iloc:
XTEST testfeaturematrix.iloc: :lentestfeaturematrix.columns
YTEST testfeaturematrix.iloc:
return XTRAIN, YTRAIN, XTEST, YTEST
if namemain:
xtrain, ytrain, xtest, ytest loaddata
ACCURACYSCORE logisticregressionxtrain ytrain, xtest, ytest
printACCURACY score is : ACCURACYSCORE
logtesting.csv contains in the following format:
male,age,education,currentSmoker,cigsPerDay,BPMeds,prevalentStroke,prevalentHyp,diabetes,totChol,sysBPdiaBP,BMI,heartRate,glucose,TenYearCHD
There are lines of data structured in this way
logtraining.csv contains in the following format:
male,age,education,currentSmoker,cigsPerDay,BPMeds,prevalentStroke,prevalentHyp,diabetes,totChol,sysBPdiaBP,BMI,heartRate,glucose,TenYearCHD
There are lines of data structured in this way
i have attached the image of logtraining.csv file
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