<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 As a warm-up, you'll review some machine learning fundamentals and submit your initial results to a Kaggle competition.
Setup
The questions below will give you feedback on your work. Run the following cell to set up the feedback system.
Step1:  You will work with data from the Housing Prices Competition for Kaggle Learn Users to predict home prices in Iowa using 79 explanatory variables describing (almost) every aspect of the homes.  
Run the next code cell without changes to load the training and validation features in X_train and X_valid, along with the prediction targets in y_train and y_valid.  The test features are loaded in X_test.  (If you need to review features and prediction targets, please check out this short tutorial.  To read about model validation, look here.  Alternatively, if you'd prefer to look through a full course to review all of these topics, start here.)
Step2:  Use the next cell to print the first several rows of the data. It's a nice way to get an overview of the data you will use in your price prediction model.
Step3:  The next code cell defines five different random forest models.  Run this code cell without changes.  (To review random forests, look here.)
Step4:  To select the best model out of the five, we define a function score_model() below.  This function returns the mean absolute error (MAE) from the validation set.  Recall that the best model will obtain the lowest MAE.  (To review mean absolute error, look here.)
Run the code cell without changes.
Step5:  Step 1
Step6:  Step 2
Step7:  Run the next code cell without changes.  The code fits the model to the training and validation data, and then generates test predictions that are saved to a CSV file.  These test predictions can be submitted directly to the competition!
<ASSISTANT_TASK:>
Python Code:
# Set up code checking
import os
if not os.path.exists("../input/train.csv"):
    os.symlink("../input/home-data-for-ml-course/train.csv", "../input/train.csv")  
    os.symlink("../input/home-data-for-ml-course/test.csv", "../input/test.csv")  
from learntools.core import binder
binder.bind(globals())
from learntools.ml_intermediate.ex1 import *
print("Setup Complete")
Explanation: As a warm-up, you'll review some machine learning fundamentals and submit your initial results to a Kaggle competition.
Setup
The questions below will give you feedback on your work. Run the following cell to set up the feedback system.
End of explanation
import pandas as pd
from sklearn.model_selection import train_test_split
# Read the data
X_full = pd.read_csv('../input/train.csv', index_col='Id')
X_test_full = pd.read_csv('../input/test.csv', index_col='Id')
# Obtain target and predictors
y = X_full.SalePrice
features = ['LotArea', 'YearBuilt', '1stFlrSF', '2ndFlrSF', 'FullBath', 'BedroomAbvGr', 'TotRmsAbvGrd']
X = X_full[features].copy()
X_test = X_test_full[features].copy()
# Break off validation set from training data
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8, test_size=0.2,
                                                      random_state=0)
Explanation: You will work with data from the Housing Prices Competition for Kaggle Learn Users to predict home prices in Iowa using 79 explanatory variables describing (almost) every aspect of the homes.  
Run the next code cell without changes to load the training and validation features in X_train and X_valid, along with the prediction targets in y_train and y_valid.  The test features are loaded in X_test.  (If you need to review features and prediction targets, please check out this short tutorial.  To read about model validation, look here.  Alternatively, if you'd prefer to look through a full course to review all of these topics, start here.)
End of explanation
X_train.head()
Explanation: Use the next cell to print the first several rows of the data. It's a nice way to get an overview of the data you will use in your price prediction model.
End of explanation
from sklearn.ensemble import RandomForestRegressor
# Define the models
model_1 = RandomForestRegressor(n_estimators=50, random_state=0)
model_2 = RandomForestRegressor(n_estimators=100, random_state=0)
model_3 = RandomForestRegressor(n_estimators=100, criterion='absolute_error', random_state=0)
model_4 = RandomForestRegressor(n_estimators=200, min_samples_split=20, random_state=0)
model_5 = RandomForestRegressor(n_estimators=100, max_depth=7, random_state=0)
models = [model_1, model_2, model_3, model_4, model_5]
Explanation: The next code cell defines five different random forest models.  Run this code cell without changes.  (To review random forests, look here.)
End of explanation
from sklearn.metrics import mean_absolute_error
# Function for comparing different models
def score_model(model, X_t=X_train, X_v=X_valid, y_t=y_train, y_v=y_valid):
    model.fit(X_t, y_t)
    preds = model.predict(X_v)
    return mean_absolute_error(y_v, preds)
for i in range(0, len(models)):
    mae = score_model(models[i])
    print("Model %d MAE: %d" % (i+1, mae))
Explanation: To select the best model out of the five, we define a function score_model() below.  This function returns the mean absolute error (MAE) from the validation set.  Recall that the best model will obtain the lowest MAE.  (To review mean absolute error, look here.)
Run the code cell without changes.
End of explanation
# Fill in the best model
best_model = ____
# Check your answer
step_1.check()
#%%RM_IF(PROD)%%
best_model = model_3
step_1.assert_check_passed()
# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
step_1.hint()
#_COMMENT_IF(PROD)_
step_1.solution()
Explanation: Step 1: Evaluate several models
Use the above results to fill in the line below.  Which model is the best model?  Your answer should be one of model_1, model_2, model_3, model_4, or model_5.
End of explanation
# Define a model
my_model = ____ # Your code here
# Check your answer
step_2.check()
#%%RM_IF(PROD)%%
my_model = 3
step_2.assert_check_failed()
#%%RM_IF(PROD)%%
my_model = best_model
step_2.assert_check_passed()
# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
step_2.hint()
#_COMMENT_IF(PROD)_
step_2.solution()
Explanation: Step 2: Generate test predictions
Great. You know how to evaluate what makes an accurate model. Now it's time to go through the modeling process and make predictions. In the line below, create a Random Forest model with the variable name my_model.
End of explanation
# Fit the model to the training data
my_model.fit(X, y)
# Generate test predictions
preds_test = my_model.predict(X_test)
# Save predictions in format used for competition scoring
output = pd.DataFrame({'Id': X_test.index,
                       'SalePrice': preds_test})
output.to_csv('submission.csv', index=False)
Explanation: Run the next code cell without changes.  The code fits the model to the training and validation data, and then generates test predictions that are saved to a CSV file.  These test predictions can be submitted directly to the competition!
End of explanation
<END_TASK>