text_html_output_1.png
from sklearn.ensemble import RandomForestRegressor

from sklearn.ensemble import RandomForestRegressor

from sklearn.ensemble import RandomForestRegressor

from sklearn.metrics import mean_absolute_error

from sklearn.metrics import mean_absolute_error

from sklearn.metrics import mean_absolute_error

from sklearn.metrics import mean_absolute_error

from sklearn.model_selection import cross_val_score

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

from sklearn.preprocessing import Imputer

from sklearn.tree import DecisionTreeRegressor

from sklearn.tree import DecisionTreeRegressor

import pandas as pd

import pandas as pd

import pandas as pd

import pandas as pd

import pandas as pd
main_file_path = '../input/train.csv'
data_train = pd.read_csv(main_file_path)

y = data_train.SalePrice

predicators = ['YearBuilt', 'YrSold', 'TotalBsmtSF', 'LotShape', 'SaleType', 'SaleCondition']
one_hot_encoded_training_predictors = pd.get_dummies(predicators)
one_hot_encoded_training_predictors

X = data_train[predicators]
X

from sklearn.tree import DecisionTreeRegressor
housing_model = DecisionTreeRegressor()
housing_model.fit(X, y)

from sklearn.metrics import mean_absolute_error
from sklearn.tree import DecisionTreeRegressor
def get_mae(max_leaf_nodes, predictors_train, predictors_val, targ_train, targ_val):
    model = DecisionTreeRegressor(max_leaf_nodes=max_leaf_nodes, random_state=0)
    model.fit(predictors_train, targ_train)
    preds_val = model.predict(predictors_val)
    mae = mean_absolute_error(targ_val, preds_val)
    return mae

import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
train = pd.read_csv('../input/train.csv')
train_y = train.SalePrice
predictor_cols = ['LotArea', 'OverallQual', 'YearBuilt', 'TotRmsAbvGrd']
train_X = train[predictor_cols]
my_model = RandomForestRegressor()
my_model.fit(train_X, train_y)

test = pd.read_csv('../input/test.csv')
test_X = test[predictor_cols]
predict_prices = my_model.predict(test_X)

my_submission = pd.DataFrame({'Id': test.Id, 'SalePrice': predict_prices})
my_submission.to_csv('submission.csv', index=False)

import pandas as pd
train_data = pd.read_csv('../input/train.csv')
test_data = pd.read_csv('../input/test.csv')

train_data.dropna(axis=0, subset=['SalePrice'], inplace=True)
target = train_data.SalePrice
cols_with_missing = [col for col in train_data.columns if train_data[col].isnull().any()]
candidate_train_predictors = train_data.drop(['Id', 'SalePrice'] + cols_with_missing, axis=1)
candidate_test_predictors = test_data.drop(['Id'] + cols_with_missing, axis=1)
low_cardinality_cols = [cname for cname in candidate_train_predictors.columns if candidate_train_predictors[cname].nunique() < 10 and candidate_train_predictors[cname].dtype == 'object']
numeric_cols = [cname for cname in candidate_train_predictors.columns if candidate_train_predictors[cname].dtype in ['int64', 'float64']]
my_cols = low_cardinality_cols + numeric_cols
train_predictors = candidate_train_predictors[my_cols]
test_predictors = candidate_test_predictors[my_cols]
train_predictors.dtypes.sample(10)

one_hot_encoded_training_predictors = pd.get_dummies(train_predictors)
one_hot_encoded_training_predictors

from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestRegressor
def get_mae(X, y):
    return -1 * cross_val_score(RandomForestRegressor(50), X, y, scoring='neg_mean_absolute_error').mean()
predictors_without_categoricals = train_predictors.select_dtypes(exclude=['object'])
mae_without_categoricals = get_mae(one_hot_encoded_training_predictors, target)
mae_one_hot_encoded = get_mae(one_hot_encoded_training_predictors, target)

one_hot_encoded_training_predictors = pd.get_dummies(train_predictors)
one_hot_encoded_test_predictors = pd.get_dummies(test_predictors)
final_train, final_test = one_hot_encoded_training_predictors.align(one_hot_encoded_test_predictors, join='left', axis=1)
final_train
final_test

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Imputer
data_train = pd.read_csv('../input/train.csv')
data_train.dropna(axis=0, subset=['SalePrice'], inplace=True)
y = data_train.SalePrice
X = data_train.drop(['SalePrice'], axis=1).select_dtypes(exclude=['object'])
train_X, test_X, train_Y, test_y = train_test_split(X.as_matrix(), y.as_matrix(), test_size=0.25)
my_imputer = Imputer()
train_X = my_imputer.fit_transform(train_X)
test_X = my_imputer.transform(test_X)

data_train.columns