mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Added Random Forest training section.
This commit is contained in:
parent
ad54e0ae70
commit
3fcbc8364f
|
@ -2352,6 +2352,56 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 37
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Random Forest: Training"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Create the random forest object:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"forest = RandomForestClassifier(n_estimators=100)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 38
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Fit the training data and create the decision trees:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"# Training data (features), skip the first column 'Survived'\n",
|
||||
"training_input = train_data[0::, 1::]\n",
|
||||
"\n",
|
||||
"# 'Survived' column values\n",
|
||||
"target_values = train_data[0::, 0]\n",
|
||||
"\n",
|
||||
"# Fit the model to our training data\n",
|
||||
"forest = forest.fit(training_input, target_values)"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"prompt_number": 39
|
||||
}
|
||||
],
|
||||
"metadata": {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user