Kaggle competition: House Prices - Advanced Regression Techniques
<SOS> metric: rmsle Kaggle data source: house-prices-advanced-regression-techniques<predict_on_test>
def mean_absolute_percentage_error(y_true, y_pred):
y_true, y_pred = np.array(y_true), np.array(y_pred)
 return np.mean(np.abs(( y_true - y_pred)/ y_true)) * 100
if 0 and not SKIP_VALIDATION:
dataset = get_validation_dataset(valid_ds)
 dataset = dataset.unbatch().batch(20)
 batch = iter(dataset)
 images, labels = next(batch)
 probabilities = model.predict(images)
 predictions = np.argmax(probabilities, axis=-1)
 display_batch_of_images(( images, labels), predictions )<load_from_csv>
df = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/train.csv')
 test = pd.read_csv('.. /input/house-prices-advanced-regression-techniques/test.csv' )
train_data=pd.read_csv('/kaggle/input/DontGetKicked/training.csv' )<load_from_csv>
cat_columns = [cname for cname in df.columns if df[cname].dtype == "object"]
test_data=pd.read_csv('/kaggle/input/DontGetKicked/test.csv')
 test_data.head()<count_missing_values>
for col in df.columns:
if col in cat_columns:
df[col] = df[col].astype('category')
 for col in test.columns:
if col in cat_columns:
test[col] = test[col].astype('category' )
train_data.isnull().sum()<count_missing_values>
X = df.drop('SalePrice', axis=1)
 y = df['SalePrice']
X_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.2, random_state=0 )
test_data.isnull().sum()<count_values>
%%time
best_score = -1
num_leaves = [6, 7]
n_estimators = [100, 400, 450, 500, 550]
learning_rate = [0.1, 0.075, 0.08, 0.07, 0.065]
for rate in learning_rate:
for leave in num_leaves:
for estimator in n_estimators:
lgb = lightgbm.LGBMRegressor(num_leaves=leave, n_estimators=estimator, learning_rate=rate, random_state=0)
 scores = -1 * cross_val_score(lgb, X_train, y_train, cv=5, scoring='neg_mean_squared_log_error')
 if np.mean(scores)< best_score or best_score == -1:
best_score = np.mean(scores)
 best_leaves = leave
best_estimators = estimator
best_learning_rate = rate
print(np.sqrt(best_score))
print(f'
Средняя абсолютная ошибка: {np.sqrt(best_score)} %, листья: {best_leaves}, деревья: {best_estimators}, скорость обучения: {best_learning_rate}' )
train_data['IsBadBuy'].value_counts()<count_values>
lgb = lightgbm.LGBMRegressor(num_leaves=best_leaves, n_estimators=best_estimators, learning_rate=best_learning_rate)
 lgb.fit(X, y, categorical_feature=cat_columns, verbose=False )
train_data['Model'].value_counts()<drop_column>
pred = lgb.predict(test )
train_data.drop('Model',inplace=True,axis=1)
 test_data.drop('Model',inplace=True,axis=1 )<count_values>
output = pd.DataFrame({'Id': test.Id,
'SalePrice': pred})
 output.to_csv('submission.csv', index=False )
<drop_column><EOS> 
lgb.score(X_valid, y_valid )