Question: Hi , This Question is creating so much problem for me . I was able to get the result but when loading to Code Grade,

Hi, This Question is creating so much problem for me. I was able to get the result but when loading to Code Grade, I get an error message - "IndexError: list index out of range "
I spend so much time trying to solve this problem using python and sys.argv but was not successful. This is the code I used
import sys
import pandas as pd
import statsmodels.api as sm
def main():
if len(sys.argv)!=2:
print("Usage: python german.py ")
#sys.exit(1)
return
file_path = sys.argv[1]
try:
data = pd.read_csv(file_path)
except FileNotFoundError:
print("File not found.")
#sys.exit(1)
return
data.rename(columns={'Credit amount': 'Credit_amount'}, inplace=True)
X = sm.add_constant(data[['Age', 'Duration']])
y = data['Credit_amount']
model = sm.OLS(y, X).fit()
#print("Parameters:")
print(model.params.round(2))
#print("nR-squared:")
print(model.rsquared.round(2))
if __name__=="__main__":
main()german.py
Use the german_credit_data.csv file to complete the following assignment.
Create a file,
german.py, that loads the .csv file and runs a regression predicting
credit amount from age and duration, in that order. Add a constant using
sm.add_constant(data).
You will need to rename the column 'Credit amount' to 'Credit_amount'.
Then, print the parameters and R-squared to 2 decimals using
 Hi, This Question is creating so much problem for me. I

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 Databases Questions!