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.
Here's my solution. Not that clean but gets the job done:
# Enter your code here. Read input from STDIN. Print output to STDOUTimportjsonimportosimportsysimportnumpyasnpfromsklearn.linear_modelimportLinearRegressiondefread_input():X_test=[]forlineinsys.stdin.readlines()[1:]:data=json.loads(line.rstrip("\n"))deldata["serial"]X_test.append(list(data.values()))returnnp.array(X_test)defread_training_data():X_train=[]y_train=[]withopen("training.json")asf:np_string=np.array(f.read().split("\n"))[1:-1]forjson_objinnp_string:data=json.loads(json_obj)y_train.append(data["Mathematics"])deldata["Mathematics"]deldata["serial"]X_train.append(list(data.values()))f.close()returnnp.array(X_train),np.array(y_train)deftrain():X_train,y_train=read_training_data()X_test=read_input()lin_reg=LinearRegression()lin_reg.fit(X_train,y_train)y_test=lin_reg.predict(X_test).astype(np.uint8)returny_testdefshow(y):y_string=[str(y[k])forkinrange(len(y))]print("\n".join(y_string))if__name__=="__main__":show(train())
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Predict the Missing Grade
You are viewing a single comment's thread. Return to all comments →
Here's my solution. Not that clean but gets the job done: