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.
# Enter your code here. Read input from STDIN. Print output to STDOUTimportsysimportnumpyasnpfromsklearn.linear_modelimportLogisticRegressionfromsklearn.ensembleimportRandomForestClassifierdata=[]forlineinsys.stdin:l=[iforiinline.split()]data.append(l)#print(data)num=int(data[0][0])param=int(data[0][1])q=int(data[num+1][0])#print(num,param,q)X=np.array(data[1:num])X_train=[]y_train=[]foriinX:X_train.append(i[2:])y_train.append(int(i[1]))l=[]temp=[]forjinX_train:l=[]foriinj:t=i.split(":")l.append(float(t[1]))temp.append(l)X_train=np.array(temp)#print(X_train)y_train=np.array(y_train)X_t=np.array(data[num+2:])X_test=[]foriinX_t:X_test.append(i[1:])temp=[]l1=[]forjinX_test:l1=[]foriinj:t1=i.split(":")l1.append(float(t1[1]))temp.append(l1)X_test=np.array(temp)#print(X_test)#print(X_train.shape,y_train.shape,X_test.shape)rfc=RandomForestClassifier()clf=rfc.fit(X_train,y_train)predict=clf.predict(X_test)foriinrange(len(predict)):ifpredict[i]>0:print(X_t[i][0],"+1")else:print(X_t[i][0],"-1")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Quora Answer Classifier
You are viewing a single comment's thread. Return to all comments →