Use Random Forest in Python

You need to pre-install scikit-learn using pip or easy_install.

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

Recommended Posts

Use Random Forest in Python
Balanced Random Forest in python
Use config.ini in Python
Use Valgrind in Python
Use profiler in Python
Disease classification in Random Forest using Python
Let's use def in python
Use let expression in Python
Use Measurement Protocol in Python
Use callback function in Python
Use parameter store in Python
Use HTTP cache in Python
Use list-keyed dict in Python
Use regular expressions in Python
Use Spyder in Python IDE
Weighted random choice in python
Random Forest (2)
Random Forest
Testing with random numbers in Python
How to use SQLite in Python
Use rospy with virtualenv in Python3
How to use Mysql in python
Use Python in pyenv with NeoVim
How to use ChemSpider in Python
How to use PubChem in Python
Use OpenCV with Python 3 in Window
Create a random string in Python
Quadtree in Python --2
CURL in python
Metaprogramming in Python
[Introduction to Python] How to use class in Python?
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Use print in a Python2 lambda expression
Meta-analysis in Python
Unittest in python
Easily use your own functions in Python
Discord in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Easy way to use Wikipedia in Python
Plink in Python
Constant in python
Don't use \ d in Python 3 regular expressions!
Lifegame in Python.
FizzBuzz in Python
How to use __slots__ in Python class
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
Use pathlib in Maya (Python 2.7) for upcoming Python 3.7
nCr in Python.