Kaggle competition: VSU ML 1 Regression
warnings.filterwarnings('ignore')
 train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )<drop_column>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )
train.drop('Id', inplace = True, axis =1)
 test.drop('Id', inplace = True, axis =1)
<prepare_x_and_y>
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import PolynomialFeatures
test_A = test<drop_column>
pipe = Pipeline([ 
('scaler', StandardScaler()), 
('poly', PolynomialFeatures()), 
('model', LinearRegression()),
] )
train = train.drop(train[(train['GrLivArea']>4000)&(train['SalePrice']<300000)].index )<prepare_x_and_y>
X_train = train[['LotFrontage','LotArea']].fillna(0)
 X_test = test[['LotFrontage','LotArea']].fillna(0)
 y_train = train['SalePrice']
train_A = train.drop(['SalePrice'], axis=1)
 y = pd.DataFrame(train['SalePrice'])
 features = pd.concat([train_A, test_A] ).reset_index(drop=True )<create_dataframe>
from sklearn.model_selection import cross_val_score
from sklearn.metrics import mean_squared_error
y_log = pd.DataFrame(np.log1p(y['SalePrice']))
distribution(y_log,'SalePrice' )<filter>
scores = cross_val_score(pipe, X_train, y_train, scoring='neg_mean_squared_error', cv=10 )
numerical_features = features.dtypes[features.dtypes != "object"].index
categorical_features = features.dtypes[features.dtypes == "object"].index
numerical_df = features[numerical_features]
categorical_df = features[categorical_features]<categorify>
np.mean(pow(-scores, 0.5))
def fill_na_num_mean(df,column_name):
df[column_name] = df[column_name].transform(lambda x: x.fillna(round(x.mean() ,1)))
 return df
def fill_na_num_median(df,column_name):
df[column_name] = df[column_name].transform(lambda x: x.fillna(round(x.median() ,1)))
 return df
def fill_na_cat_none(df,column_name):
df[column_name].fillna('None',inplace=True)
 def fill_na_num_0(df,column_name):
df[column_name].fillna(0,inplace=True)
 def fill_na_mode(df,column_name):
df[column_name].fillna(df[column_name].mode() [0], inplace = True)
<drop_column>
pipe.fit(X_train, y_train )
features.drop(['MiscFeature'], inplace = True, axis = 1)
 features.drop(['MiscVal'], inplace = True, axis = 1 )<drop_column>
preds = pipe.predict(X_test )
features.drop(['Fence'], inplace = True, axis =1)
 features.drop(['Alley'], inplace = True, axis = 1)
 features.drop(['PoolQC'], inplace = True, axis = 1)
 features.drop(['PoolArea'], inplace = True, axis =1 )<categorify>
sub = pd.DataFrame({'Id': test.Id, 'SalePrice': preds})
 sub.to_csv('submission.csv', index=False )