text_plain_output_1.png
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.metrics import mean_absolute_error

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

from sklearn.pipeline import make_pipeline

from sklearn.preprocessing import Imputer

from sklearn.preprocessing import Imputer

from sklearn.preprocessing import Imputer

from sklearn.tree import DecisionTreeRegressor

from sklearn.tree import DecisionTreeRegressor

from xgboost import XGBRegressor

import pandas as pd

import pandas as pd

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

price = df.SalePrice

columns_of_interest = ['HouseStyle', 'SaleCondition']
two_columns_of_data = df[columns_of_interest]

y = price

columns_of_interest = ['LotArea', 'YearBuilt', '1stFlrSF', '2ndFlrSF', 'FullBath', 'BedroomAbvGr', 'TotRmsAbvGrd']
X = df[columns_of_interest]

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

from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error
forest_model = RandomForestRegressor()
forest_model.fit(train_X, train_y)
preds = forest_model.predict(val_X)

cols_with_missing = [col for col in df.columns if df[col].isnull().any()]
cols_with_missing

def score_dataset(Xtrain, Xtest, ytrain, ytest):
    forest_model = RandomForestRegressor()
    forest_model.fit(Xtrain, ytrain)
    preds = forest_model.predict(Xtest)
    return mean_absolute_error(ytest, preds)

df = pd.read_csv(main_file_path)
target = df.SalePrice
predictors = df.drop(['SalePrice'], axis=1)
numeric_predictors = df.select_dtypes(exclude=['object'])

cols_with_missing = [col for col in X_train.columns if X_train[col].isnull().any()]
reduced_X_train = X_train.drop(cols_with_missing, axis=1)
reduced_X_test = X_test.drop(cols_with_missing, axis=1)

from sklearn.preprocessing import Imputer
my_imputer = Imputer()
imputed_X_train = my_imputer.fit_transform(X_train)
imputed_X_test = my_imputer.transform(X_test)

imputed_X_train_plus = X_train.copy()
imputed_X_test_plus = X_test.copy()
cols_with_missing = (col for col in X_train.columns if X_train[col].isnull().any())
for col in cols_with_missing:
    imputed_X_train_plus[col + '_was_missing'] = imputed_X_train_plus[col].isnull()
    imputed_X_test_plus[col + '_was_missing'] = imputed_X_test_plus[col].isnull()
my_imputer = Imputer()
imputed_X_train_plus = my_imputer.fit_transform(imputed_X_train_plus)
imputed_X_test_plus = my_imputer.transform(imputed_X_test_plus)

from sklearn.ensemble import RandomForestRegressor
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import Imputer
my_pipeline = make_pipeline(Imputer(), RandomForestRegressor())

my_pipeline.fit(X_train, y_train)
predictions = my_pipeline.predict(X_test)

my_imputer = Imputer()
my_model = RandomForestRegressor()
imputed_train_X = my_imputer.fit_transform(X_train)
imputed_test_X = my_imputer.transform(X_test)
my_model.fit(imputed_train_X, y_train)
predictions = my_model.predict(imputed_test_X)

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Imputer
data = pd.read_csv('../input/train.csv')
data.dropna(axis=0, subset=['SalePrice'], inplace=True)
y = data.SalePrice
X = data.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)

from xgboost import XGBRegressor
my_model = XGBRegressor()
my_model.fit(train_X, train_y, verbose=False)
predictions = my_model.predict(test_X)
from sklearn.metrics import mean_absolute_error

my_model = XGBRegressor(n_estimators=1000)
my_model.fit(train_X, train_y, early_stopping_rounds=5, eval_set=[(test_X, test_y)], verbose=False)
predictions = my_model.predict(test_X)
from sklearn.metrics import mean_absolute_error
print('Mean Absolute Error : ' + str(mean_absolute_error(predictions, test_y)))