Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.ensemble import RandomForestClassifier
- #assume data is already loaded as xtrain, ytrain and xdev, ydev
- clf = RandomForestClassifier()
- clf.fit(xtrain,ytrain)
- closed_out = clf.predict(xtrain)
- open_out = clf.predict(xdev)
- #calculate error -- note: he actually has a script for this and you should use his style but this will work while you're just figuring shit out
- #closed loop
- num_wrong = 0.
- for i in xrange(len(ytrain)):
- if closed_out[i]!=ytrain[i]:
- num_wrong+=1.
- print("open loop error: " + str(num_wrong/len(ytrain)))
- #open loop
- num_wrong = 0.
- for i in xrange(len(ydev)):
- if open_out[i]!=ydev[i]:
- num_wrong+=1.
- print("open loop error: " + str(num_wrong/len(ydev)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement