Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artembielov #13

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tasks/artembielov_task1/House price/artembielov_house_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.neural_network import MLPRegressor
from sklearn.linear_model import Ridge
from sklearn.linear_model import LinearRegression
from mlxtend.regressor import StackingRegressor


path = '...'
test = pd.read_csv(path + 'test.csv')
train = pd.read_csv(path + 'train.csv')

target = np.log(train.SalePrice)


all_data = pd.concat((train.loc[:, 'MSSubClass':'SaleCondition'], test.loc[:, 'MSSubClass':'SaleCondition']))

all_data = all_data.drop(['Utilities'], axis=1)

useless = ['PoolQC', 'MiscFeature', 'Alley', 'Fence']
all_data.drop(useless, axis=1)


def encode(x):
return 1 if x == 'Partial' else 0


all_data['enc_street'] = pd.get_dummies(all_data.Street, drop_first=True)
all_data['enc_condition'] = all_data.SaleCondition.apply(encode)

data_train = all_data[:train.shape[0]].select_dtypes(include=[np.number]).interpolate().dropna()
data_test = all_data[train.shape[0]:].select_dtypes(include=[np.number]).interpolate().dropna()

X_train = data_train
X_test = data_test
y = target

lr = LinearRegression(n_jobs=-1)
rd = Ridge(alpha=4.84)
rf = RandomForestRegressor(n_estimators=12, max_depth=3, n_jobs=-1)
gb = GradientBoostingRegressor(n_estimators=40, max_depth=2)
nn = MLPRegressor(hidden_layer_sizes=(90, 90), alpha=2.75)

model = StackingRegressor(regressors=[rf, gb, nn, rd], meta_regressor=lr)

model.fit(X_train, y)

y_pred = model.predict(X_train)

Y_pred = model.predict(X_test)

final_predictions = np.exp(Y_pred)
submission = pd.DataFrame()
submission['Id'] = test['Id']
submission['SalePrice'] = final_predictions
submission.to_csv('submission_v3.csv', index=False)
Loading