We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Currently,Iamatabeginnerlevel,soifyounoticeanymistakes,pleaseletmeknow.importnumpyasnpimportpandasaspdfromsklearn.linear_modelimportLinearRegressiondefread_input_data():x_train,y_train=[],[]withopen('trainingdata.txt','r')asfile:data=[list(map(float,line.strip().split(',')))forlineinfile]data=np.array(data)# Identify minimum charge time for full chargefull_charge=8.0filtered_data=data[data[:,1]!=full_charge]x_train=filtered_data[:,0].reshape(-1,1)#Chargingtimey_train=filtered_data[:,1]#Batterylifereturnx_train,y_traindefprediction_model(x,y):lr_model=LinearRegression()lr_model.fit(x,y)returnlr_modeldefprediction(model,t):returnmodel.predict(np.array([[t]]))[0]if__name__=='__main__':x_train,y_train=read_input_data()lrr_model=prediction_model(x_train,y_train)timeCharged=float(input().strip())iftimeCharged>4:result=8.00else:result=prediction(lrr_model,timeCharged)print(round(result,2))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Laptop Battery Life
You are viewing a single comment's thread. Return to all comments →