LoginSignup
19
19

More than 5 years have passed since last update.

PythonでRandom Forestを使う

Posted at

pipやeasy_installを使ってscikit-learnを予めインストールしておく必要があります.

rf.py
from sklearn.ensemble import RandomForestClassifier

trainingdata = [[1, 1], [2, 2], [-1, -1], [-2, -2]]
traininglabel = [1, 1, -1, -1]
testdata = [[3, 3], [-3, -3]]

model = RandomForestClassifier()
model.fit(trainingdata, traininglabel)
output = model.predict(testdata)

for label in output: print label
19
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
19