check in softmax multiclass

This commit is contained in:
tqchen
2014-08-17 19:16:17 -07:00
parent e77df13815
commit 9df8bb1397
5 changed files with 116 additions and 22 deletions

View File

@@ -42,8 +42,9 @@ print ('predicting, classification error=%f' % (sum( int(pred[i]) != test_Y[i] f
# do the same thing again, but output probabilities
param['objective'] = 'multi:softprob'
bst = xgb.train(param, xg_train, num_round, watchlist );
# get prediction, this is in 1D array, need reshape to (nclass, ndata)
yprob = bst.predict( xg_test ).reshape( 6, test_Y.shape[0] )
ylabel = np.argmax( yprob, axis=0)
# Note: this convention has been changed since xgboost-unity
# get prediction, this is in 1D array, need reshape to (ndata, nclass)
yprob = bst.predict( xg_test ).reshape( test_Y.shape[0], 6 )
ylabel = np.argmax(yprob, axis=1)
print ('predicting, classification error=%f' % (sum( int(ylabel[i]) != test_Y[i] for i in range(len(test_Y))) / float(len(test_Y)) ))