1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

■Kaggle Practice for Beginners -House SalePrice (PyCaretを使ってみた)- by Google Colaboratory

Last updated at Posted at 2020-04-27

0. Introduction

I'd like to show how to use PyCaret thru House Sale Price Competition to introduce how easy to use this library.
This introduction is only to show very basic flow, so if you want to improve your score on Kaggle, you need to add some procedures, such as preprocessing steps and modeling techniques.

1. Setting for Google Colaboratory

Setup thru Google Colaboratory environment using these command below to activate connection with Kaggle.

from google.colab import files
files.upload()
!pip install kaggle
!mkdir -p ~/.kaggle
!mv kaggle.json ~/.kaggle/
!chmod 600 /root/.kaggle/kaggle.json

Copy and paste the API linked to datasets you want to download from Kaggle.
Don't forget putting "!" mark into front of this command.

# This is an example of House SalePrice
!kaggle competitions download -c house-prices-advanced-regression-techniques

2. Install PyCaret

!pip install pycaret

3. Import Dataset

import numpy as np 
import pandas as pd 

train = pd.read_csv("/content/train.csv")
test = pd.read_csv("/content/test.csv")
train.head() 

4. Setup PyCaret

from pycaret.regression import *
reg = setup(train, target='SalePrice', session_id= 0)   

session_id: int, default = None
If None, a random seed is generated and returned in the Information grid. The unique number is then distributed as a seed in all functions used during the experiment. This can be used for later reproducibility of the entire experiment.

5. Compare Models

Compare Models
compare_models(blacklist = None, fold = 10, round = 4, sort = ‘R2’, turbo = True)
This function uses all models in the model library and scores them using K-fold Cross Validation. The output prints a score grid that shows MAE, MSE, RMSE, R2, RMSLE and MAPE by fold (default CV = 10 Folds) of all the available models in model library.

['tr'] Thielsen Regressor required long training time, so I removed the method this time.
['lar'] Least Angle Regression showed too large amount of MAE, so I omitted this time.

compare_models(blacklist=['tr', 'lar'])

image.png

6.Create Models

llar1 = create_model('llar', verbose=False)

7. Predictions

predict_model(llar1)
predictions_llar1 = predict_model(llar1, data=test)
test_ID = test['Id']
predictions_llar_Label = predictions_llar1['Label']
my_submission = pd.DataFrame()
my_submission["Id"] = test_ID
my_submission["SalePrice"] = predictions_llar_Label
my_submission.to_csv('submission_llar.csv', index=False)

8. Submission

Copy and paste the API linked to submission page you want to submit to Kaggle.
Don't forget putting "!" mark into front of this command.


# Submission to Kaggle
!kaggle competitions submit -c house-prices-advanced-regression-techniques -f submission_llar.csv -m "Message" 

References:

LINKS

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?