Kaggle competition: House Prices - Advanced Regression Techniques
best_alpha = 0.52
bad_alpha = 0.33
print('Вычисляем предсказания...')
 probabilities1 = model1.predict(test_dataset, verbose=1)
 probabilities3 = model3.predict(test_dataset, verbose=1)
 probabilities = best_alpha * probabilities1 +(1 - best_alpha)* probabilities3
print(probabilities)
 sub.loc[:, 'healthy':] = probabilities
sub.to_csv('submission.csv', index=False)
 sub.head()<install_modules>
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import skew
import lightgbm as lgb
!pip install fastai2
!pip install pretrainedmodels<set_options>
submission = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/sample_submission.csv')
 submission.head()
warnings.filterwarnings('ignore' )<set_options>
train = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/train.csv')
 train.head()
def seed_everything(seed):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed_all(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
SEED=42
seed_everything(SEED )<define_variables>
test = pd.read_csv('/kaggle/input/house-prices-advanced-regression-techniques/test.csv')
 test.head()
working_path=Path('.. /input/plant-pathology-2020-fgvc7')
 image_path = working_path/'images'
train_path = working_path/'train.csv'
test_path = working_path/'test.csv'
sample_path = working_path/'sample_submission.csv'<load_from_csv>
print('=========== train infomation ===========')
 train.info()
print('
=========== test infomation ===========')
 test.info()
train_df = pd.read_csv(train_path)
 train_df.head(10 )<concatenate>
data = pd.concat([train, test])
 data.shape
train_df.set_index('image_id',inplace=True)
 train_df = train_df[train_df==1].stack().reset_index().drop(0,1 )<load_from_csv>
cat_data = pd.get_dummies(data.loc[:, cat_cols], drop_first=True)
 cat_data.head()
test_df = pd.read_csv(test_path )<choose_model_class>
num_data = data.loc[:,data.dtypes != 'object'].drop('Id', axis=1)
 num_data.head()
def get_model(model, cut=-2, head=None, from_save=None):
children = list(model.children())
 head = ifnone(head, nn.Sequential(nn.AdaptiveAvgPool2d(1), Flatten() ,
nn.Linear(children[-1].in_features,4)))
 model = nn.Sequential(nn.Sequential(*children[:cut]), head)
 if from_save:
state_dict = torch.load(f'models/{from_save}.pth')
 model[0].load_state_dict(state_dict)
 return model<train_model>
optimized_data = pd.concat([data['Id'], cat_data, log_num_data], axis=1)
 optimized_data.head()
def create_model(dls,model,metrics):
model = get_model(model)
 return Learner(dls,model,metrics=metrics,opt_func=ranger)
 def train_learner(learn,lr,epochs):
learn.freeze()
learn.fit_flat_cos(1,lr)
 learn.unfreeze()
lr /= 2
learn.fit_flat_cos(epochs,slice(lr/100,lr))
return learn
def validate_learner(dls,learn,test_df):
test_dl = dls.test_dl(test_df)
 _, metric = learn.validate()
preds, _ = learn.get_preds(dl=test_dl)
 return metric, preds<choose_model_class>
train = optimized_data[:train.shape[0]]
test = optimized_data[train.shape[0]:].drop(['Id', 'SalePrice'], axis=1)
 X_train = train.drop(['Id', 'SalePrice'], axis=1)
 y_train = train['SalePrice']
kf = StratifiedKFold(n_splits=5,shuffle=True,random_state=SEED )<init_hyperparams>
lgb_train = lgb.Dataset(X_train, y_train)
 params = {
'task' : 'train',
'boosting_type' : 'gbdt',
'objective' : 'regression',
'metric' : {'l2'},
'num_leaves' : 40,
'learning_rate' : 0.1,
'feature_fraction' : 0.9,
'bagging_fraction' : 0.8,
'bagging_freq': 5,
'verbose' : 0
}
gbm = lgb.train(params, lgb_train)
 pred = gbm.predict(test )
<find_best_params><EOS> 
pred = np.expm1(pred)
 results = pd.Series(pred, name='SalePrice')
 submission = pd.concat([submission['Id'], results], axis=1)
 submission.to_csv('submission.csv', index=False)
 submission.head()