{"id":5380,"date":"2018-06-11T16:46:45","date_gmt":"2018-06-11T07:46:45","guid":{"rendered":"https:\/\/www.lancard.com\/blog\/?p=5380"},"modified":"2025-03-12T11:26:05","modified_gmt":"2025-03-12T02:26:05","slug":"kaggle%e3%82%92%e8%a9%a6%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2018\/06\/11\/kaggle%e3%82%92%e8%a9%a6%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f\/","title":{"rendered":"kaggle\u3092\u8a66\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>\u6700\u8fd1\u6a5f\u68b0\u5b66\u7fd2\u306e\u52c9\u5f37\u3092\u306f\u3058\u3081\u307e\u3057\u305f\u3002\u4f55\u518a\u304b\u672c\u3092\u8cfc\u5165\u3057\u30b6\u30fc\u30c3\u3068\u76ee\u3092\u901a\u3057\uff08\u6df1\u304f\u306f\u7406\u89e3\u3067\u304d\u3066\u307e\u305b\u3093\uff09\u3001\u6b21\u306b\u4f55\u304b\u9069\u5f53\u306a\u30b5\u30f3\u30d7\u30eb\u3067\u6a5f\u68b0\u5b66\u7fd2\u3092\u8a66\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u306a\u304b\u306a\u304b\u90fd\u5408\u304c\u826f\u3044\u30c7\u30fc\u30bf\u3068\u3044\u3046\u306e\u306f\u306a\u3044\u3067\u3059\u3002<br \/>\n\u305d\u3093\u306a\u6642\u306bKaggle\u3092\u898b\u3064\u3051\u307e\u3057\u305f\u3002Kaggle\u306f\u30c7\u30fc\u30bf\u5206\u6790\u30b3\u30f3\u30da\u3092\u884c\u3046\u30b5\u30a4\u30c8\u3067\u3059\u304c\u3001\u6a5f\u68b0\u5b66\u7fd2\u3092\u52c9\u5f37\u3059\u308b\u306e\u306b\u3082\u3001\u3059\u3054\u304f\u5f79\u7acb\u3064\u30b5\u30a4\u30c8\u3067\u3059\u3002<\/p>\n<p>\u300cTitanic: Machine Learning from Disaster\u300d\u3068\u3044\u3046\u5b66\u7fd2\u7528\u306e\u30b3\u30f3\u30da\u3092\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u6700\u521d\u306b\u3084\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u307e\u3059\u304c\u3001\u3059\u3067\u306b\u65e5\u672c\u8a9e\u3067\u305f\u304f\u3055\u3093\u7d39\u4ecb\u3055\u308c\u3066\u308b\u306e\u3067\u300cHouse Prices: Advanced Regression Techniques\u300d\u3068\u3044\u3046\u306e\u3092\u3084\u3063\u3066\u307f\u307e\u3059\u3002\u30bf\u30a4\u30bf\u30cb\u30c3\u30af\u304c\u5206\u985e\u306b\u5bfe\u3057\u3066\u3053\u308c\u306f\u56de\u5e30\u306e\u554f\u984c\u3067\u3059\u3002<\/p>\n<p>\u3084\u3063\u3066\u307f\u308b\u3001\u3068\u3044\u3063\u3066\u3082\u521d\u5fc3\u8005\u306b\u306f\u4f55\u304b\u3089\u3084\u308b\u306e\u304b\u691c\u8a0e\u304c\u3064\u304d\u307e\u305b\u3093\u304c\u3001Kaggle\u306b\u306f\u591a\u304f\u306e\u65b9\u3005\u304c\u81ea\u5206\u304c\u884c\u3063\u305f\u30b3\u30fc\u30c9\u7b49\uff08Kernels\uff09\u3092\u8aac\u660e\u4ed8\u304d\u3067\u516c\u958b\u3057\u3066\u304f\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u305d\u308c\u3089\u3092\u771f\u4f3c\u3059\u308c\u3070\u3067\u304d\u307e\u3059\u3002<br \/>\n\u6700\u521d\u306f\u4eba\u304c\u4f5c\u3063\u305fKernels\u3092\u3072\u305f\u3059\u3089\u898b\u3066\u81ea\u5206\u306e\u3082\u306e\u306b\u3059\u308b\u3001\u3068\u3044\u3046\u611f\u3058\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u3082\u57fa\u672c\u3001\u4eba\u304c\u4f5c\u3063\u305fKernels\u3092\u53c2\u8003\u306b\u66f8\u3044\u3066\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001Kaggle\u306b\u306f\u958b\u767a\u74b0\u5883\u3082\u3042\u308a\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u307e\u305f\u306f\u30ce\u30fc\u30c8\u30d6\u30c3\u30af(Jupyter Notebook)\u306e\u5f62\u5f0f\u3067\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u8a66\u3059\u3053\u3068\u3067\u304d\u307e\u3059\u3002\u30b7\u30b9\u30c6\u30e0\u3068\u3057\u3066\u3088\u304f\u3067\u304d\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>\u76ee\u7684<\/h1>\n<p>\u30a2\u30a4\u30aa\u30ef\u5dde\u306e\u30a8\u30a4\u30e0\u30ba\u306b\u3042\u308b\u4f4f\u5b85\u4fa1\u683c\u309279\u306e\u7279\u5fb4\u91cf\u3088\u308a\u4e88\u6e2c\u3057\u307e\u3059\u3002<a href=\"http:\/\/www.amstat.org\/publications\/jse\/v19n3\/decock.pdf\" target=\"_blank\" rel=\"noopener\">Ames Housing dataset<\/a><\/p>\n<p><!--more--><\/p>\n<h1>\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406<\/h1>\n<p>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<pre>import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib\nimport matplotlib.pyplot as plt\nfrom scipy.stats import skew\nfrom scipy.stats.stats import pearsonr\n%config InlineBackend.figure_format = 'retina' #set 'png' here when working on notebook\n%matplotlib inline\n<\/pre>\n<p>\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre>train = pd.read_csv(\"..\/input\/train.csv\")\ntest = pd.read_csv(\"..\/input\/test.csv\")\ntrain.head()\n<\/pre>\n<div style=\"overflow-x: scroll;\">\n<table>\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>Id<\/th>\n<th>MSSubClass<\/th>\n<th>MSZoning<\/th>\n<th>LotFrontage<\/th>\n<th>LotArea<\/th>\n<th>Street<\/th>\n<th>Alley<\/th>\n<th>LotShape<\/th>\n<th>LandContour<\/th>\n<th>Utilities<\/th>\n<th>LotConfig<\/th>\n<th>LandSlope<\/th>\n<th>Neighborhood<\/th>\n<th>Condition1<\/th>\n<th>Condition2<\/th>\n<th>BldgType<\/th>\n<th>HouseStyle<\/th>\n<th>OverallQual<\/th>\n<th>OverallCond<\/th>\n<th>YearBuilt<\/th>\n<th>YearRemodAdd<\/th>\n<th>RoofStyle<\/th>\n<th>RoofMatl<\/th>\n<th>Exterior1st<\/th>\n<th>Exterior2nd<\/th>\n<th>MasVnrType<\/th>\n<th>MasVnrArea<\/th>\n<th>ExterQual<\/th>\n<th>ExterCond<\/th>\n<th>Foundation<\/th>\n<th>BsmtQual<\/th>\n<th>BsmtCond<\/th>\n<th>BsmtExposure<\/th>\n<th>BsmtFinType1<\/th>\n<th>BsmtFinSF1<\/th>\n<th>BsmtFinType2<\/th>\n<th>BsmtFinSF2<\/th>\n<th>BsmtUnfSF<\/th>\n<th>TotalBsmtSF<\/th>\n<th>Heating<\/th>\n<th>&#8230;<\/th>\n<th>CentralAir<\/th>\n<th>Electrical<\/th>\n<th>1stFlrSF<\/th>\n<th>2ndFlrSF<\/th>\n<th>LowQualFinSF<\/th>\n<th>GrLivArea<\/th>\n<th>BsmtFullBath<\/th>\n<th>BsmtHalfBath<\/th>\n<th>FullBath<\/th>\n<th>HalfBath<\/th>\n<th>BedroomAbvGr<\/th>\n<th>KitchenAbvGr<\/th>\n<th>KitchenQual<\/th>\n<th>TotRmsAbvGrd<\/th>\n<th>Functional<\/th>\n<th>Fireplaces<\/th>\n<th>FireplaceQu<\/th>\n<th>GarageType<\/th>\n<th>GarageYrBlt<\/th>\n<th>GarageFinish<\/th>\n<th>GarageCars<\/th>\n<th>GarageArea<\/th>\n<th>GarageQual<\/th>\n<th>GarageCond<\/th>\n<th>PavedDrive<\/th>\n<th>WoodDeckSF<\/th>\n<th>OpenPorchSF<\/th>\n<th>EnclosedPorch<\/th>\n<th>3SsnPorch<\/th>\n<th>ScreenPorch<\/th>\n<th>PoolArea<\/th>\n<th>PoolQC<\/th>\n<th>Fence<\/th>\n<th>MiscFeature<\/th>\n<th>MiscVal<\/th>\n<th>MoSold<\/th>\n<th>YrSold<\/th>\n<th>SaleType<\/th>\n<th>SaleCondition<\/th>\n<th>SalePrice<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>1<\/td>\n<td>60<\/td>\n<td>RL<\/td>\n<td>65.0<\/td>\n<td>8450<\/td>\n<td>Pave<\/td>\n<td>NaN<\/td>\n<td>Reg<\/td>\n<td>Lvl<\/td>\n<td>AllPub<\/td>\n<td>Inside<\/td>\n<td>Gtl<\/td>\n<td>CollgCr<\/td>\n<td>Norm<\/td>\n<td>Norm<\/td>\n<td>1Fam<\/td>\n<td>2Story<\/td>\n<td>7<\/td>\n<td>5<\/td>\n<td>2003<\/td>\n<td>2003<\/td>\n<td>Gable<\/td>\n<td>CompShg<\/td>\n<td>VinylSd<\/td>\n<td>VinylSd<\/td>\n<td>BrkFace<\/td>\n<td>196.0<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>PConc<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>No<\/td>\n<td>GLQ<\/td>\n<td>706<\/td>\n<td>Unf<\/td>\n<td>0<\/td>\n<td>150<\/td>\n<td>856<\/td>\n<td>GasA<\/td>\n<td>&#8230;<\/td>\n<td>Y<\/td>\n<td>SBrkr<\/td>\n<td>856<\/td>\n<td>854<\/td>\n<td>0<\/td>\n<td>1710<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>3<\/td>\n<td>1<\/td>\n<td>Gd<\/td>\n<td>8<\/td>\n<td>Typ<\/td>\n<td>0<\/td>\n<td>NaN<\/td>\n<td>Attchd<\/td>\n<td>2003.0<\/td>\n<td>RFn<\/td>\n<td>2<\/td>\n<td>548<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>Y<\/td>\n<td>0<\/td>\n<td>61<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>0<\/td>\n<td>2<\/td>\n<td>2008<\/td>\n<td>WD<\/td>\n<td>Normal<\/td>\n<td>208500<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>2<\/td>\n<td>20<\/td>\n<td>RL<\/td>\n<td>80.0<\/td>\n<td>9600<\/td>\n<td>Pave<\/td>\n<td>NaN<\/td>\n<td>Reg<\/td>\n<td>Lvl<\/td>\n<td>AllPub<\/td>\n<td>FR2<\/td>\n<td>Gtl<\/td>\n<td>Veenker<\/td>\n<td>Feedr<\/td>\n<td>Norm<\/td>\n<td>1Fam<\/td>\n<td>1Story<\/td>\n<td>6<\/td>\n<td>8<\/td>\n<td>1976<\/td>\n<td>1976<\/td>\n<td>Gable<\/td>\n<td>CompShg<\/td>\n<td>MetalSd<\/td>\n<td>MetalSd<\/td>\n<td>None<\/td>\n<td>0.0<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>CBlock<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>Gd<\/td>\n<td>ALQ<\/td>\n<td>978<\/td>\n<td>Unf<\/td>\n<td>0<\/td>\n<td>284<\/td>\n<td>1262<\/td>\n<td>GasA<\/td>\n<td>&#8230;<\/td>\n<td>Y<\/td>\n<td>SBrkr<\/td>\n<td>1262<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>1262<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>2<\/td>\n<td>0<\/td>\n<td>3<\/td>\n<td>1<\/td>\n<td>TA<\/td>\n<td>6<\/td>\n<td>Typ<\/td>\n<td>1<\/td>\n<td>TA<\/td>\n<td>Attchd<\/td>\n<td>1976.0<\/td>\n<td>RFn<\/td>\n<td>2<\/td>\n<td>460<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>Y<\/td>\n<td>298<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>0<\/td>\n<td>5<\/td>\n<td>2007<\/td>\n<td>WD<\/td>\n<td>Normal<\/td>\n<td>181500<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>3<\/td>\n<td>60<\/td>\n<td>RL<\/td>\n<td>68.0<\/td>\n<td>11250<\/td>\n<td>Pave<\/td>\n<td>NaN<\/td>\n<td>IR1<\/td>\n<td>Lvl<\/td>\n<td>AllPub<\/td>\n<td>Inside<\/td>\n<td>Gtl<\/td>\n<td>CollgCr<\/td>\n<td>Norm<\/td>\n<td>Norm<\/td>\n<td>1Fam<\/td>\n<td>2Story<\/td>\n<td>7<\/td>\n<td>5<\/td>\n<td>2001<\/td>\n<td>2002<\/td>\n<td>Gable<\/td>\n<td>CompShg<\/td>\n<td>VinylSd<\/td>\n<td>VinylSd<\/td>\n<td>BrkFace<\/td>\n<td>162.0<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>PConc<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>Mn<\/td>\n<td>GLQ<\/td>\n<td>486<\/td>\n<td>Unf<\/td>\n<td>0<\/td>\n<td>434<\/td>\n<td>920<\/td>\n<td>GasA<\/td>\n<td>&#8230;<\/td>\n<td>Y<\/td>\n<td>SBrkr<\/td>\n<td>920<\/td>\n<td>866<\/td>\n<td>0<\/td>\n<td>1786<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>3<\/td>\n<td>1<\/td>\n<td>Gd<\/td>\n<td>6<\/td>\n<td>Typ<\/td>\n<td>1<\/td>\n<td>TA<\/td>\n<td>Attchd<\/td>\n<td>2001.0<\/td>\n<td>RFn<\/td>\n<td>2<\/td>\n<td>608<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>Y<\/td>\n<td>0<\/td>\n<td>42<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>0<\/td>\n<td>9<\/td>\n<td>2008<\/td>\n<td>WD<\/td>\n<td>Normal<\/td>\n<td>223500<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>4<\/td>\n<td>70<\/td>\n<td>RL<\/td>\n<td>60.0<\/td>\n<td>9550<\/td>\n<td>Pave<\/td>\n<td>NaN<\/td>\n<td>IR1<\/td>\n<td>Lvl<\/td>\n<td>AllPub<\/td>\n<td>Corner<\/td>\n<td>Gtl<\/td>\n<td>Crawfor<\/td>\n<td>Norm<\/td>\n<td>Norm<\/td>\n<td>1Fam<\/td>\n<td>2Story<\/td>\n<td>7<\/td>\n<td>5<\/td>\n<td>1915<\/td>\n<td>1970<\/td>\n<td>Gable<\/td>\n<td>CompShg<\/td>\n<td>Wd Sdng<\/td>\n<td>Wd Shng<\/td>\n<td>None<\/td>\n<td>0.0<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>BrkTil<\/td>\n<td>TA<\/td>\n<td>Gd<\/td>\n<td>No<\/td>\n<td>ALQ<\/td>\n<td>216<\/td>\n<td>Unf<\/td>\n<td>0<\/td>\n<td>540<\/td>\n<td>756<\/td>\n<td>GasA<\/td>\n<td>&#8230;<\/td>\n<td>Y<\/td>\n<td>SBrkr<\/td>\n<td>961<\/td>\n<td>756<\/td>\n<td>0<\/td>\n<td>1717<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>3<\/td>\n<td>1<\/td>\n<td>Gd<\/td>\n<td>7<\/td>\n<td>Typ<\/td>\n<td>1<\/td>\n<td>Gd<\/td>\n<td>Detchd<\/td>\n<td>1998.0<\/td>\n<td>Unf<\/td>\n<td>3<\/td>\n<td>642<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>Y<\/td>\n<td>0<\/td>\n<td>35<\/td>\n<td>272<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>0<\/td>\n<td>2<\/td>\n<td>2006<\/td>\n<td>WD<\/td>\n<td>Abnorml<\/td>\n<td>140000<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>5<\/td>\n<td>60<\/td>\n<td>RL<\/td>\n<td>84.0<\/td>\n<td>14260<\/td>\n<td>Pave<\/td>\n<td>NaN<\/td>\n<td>IR1<\/td>\n<td>Lvl<\/td>\n<td>AllPub<\/td>\n<td>FR2<\/td>\n<td>Gtl<\/td>\n<td>NoRidge<\/td>\n<td>Norm<\/td>\n<td>Norm<\/td>\n<td>1Fam<\/td>\n<td>2Story<\/td>\n<td>8<\/td>\n<td>5<\/td>\n<td>2000<\/td>\n<td>2000<\/td>\n<td>Gable<\/td>\n<td>CompShg<\/td>\n<td>VinylSd<\/td>\n<td>VinylSd<\/td>\n<td>BrkFace<\/td>\n<td>350.0<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>PConc<\/td>\n<td>Gd<\/td>\n<td>TA<\/td>\n<td>Av<\/td>\n<td>GLQ<\/td>\n<td>655<\/td>\n<td>Unf<\/td>\n<td>0<\/td>\n<td>490<\/td>\n<td>1145<\/td>\n<td>GasA<\/td>\n<td>&#8230;<\/td>\n<td>Y<\/td>\n<td>SBrkr<\/td>\n<td>1145<\/td>\n<td>1053<\/td>\n<td>0<\/td>\n<td>2198<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>4<\/td>\n<td>1<\/td>\n<td>Gd<\/td>\n<td>9<\/td>\n<td>Typ<\/td>\n<td>1<\/td>\n<td>TA<\/td>\n<td>Attchd<\/td>\n<td>2000.0<\/td>\n<td>RFn<\/td>\n<td>3<\/td>\n<td>836<\/td>\n<td>TA<\/td>\n<td>TA<\/td>\n<td>Y<\/td>\n<td>192<\/td>\n<td>84<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>NaN<\/td>\n<td>0<\/td>\n<td>12<\/td>\n<td>2008<\/td>\n<td>WD<\/td>\n<td>Normal<\/td>\n<td>250000<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>\u30c7\u30fc\u30bf\u306e\u5909\u63db<\/h2>\n<p>\u307b\u3068\u3093\u3069\u306e\u30e2\u30c7\u30eb\u306f\u7279\u5fb4\u91cf\u53ca\u3073\u51fa\u529b\u304c\u30ac\u30a6\u30b9\u5206\u5e03\u306b\u5f93\u3063\u3066\u3044\u308b\u65b9\u304c\u3046\u307e\u304f\u3044\u304d\u307e\u3059\u3002\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0\u304c\u5de6\u53f3\u5bfe\u79f0\u306e\u300c\u30d9\u30eb\u30ab\u30fc\u30d6\u300d\u306b\u306a\u308b\u3088\u3046\u306b\u3001\u7279\u5fb4\u91cf\u53ca\u3073\u51fa\u529b\u306blog\u3092\u9069\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre>matplotlib.rcParams['figure.figsize'] = (12.0, 6.0)\nprices = pd.DataFrame({\"price\":train[\"SalePrice\"], \"log(price + 1)\":np.log1p(train[\"SalePrice\"])})\nprices.hist()\n<\/pre>\n<p><a href=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5399\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index-400x209.png\" alt=\"\" width=\"400\" height=\"209\" srcset=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index-400x209.png 400w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index-768x402.png 768w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index-602x315.png 602w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index.png 1424w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>\u51fa\u529b\u300cSalePrice\u300d\u306flog(price + 1)\u3067\u3001\u6b6a\u5ea6\u304c\u3060\u3044\u3076\u6e1b\u308a\u307e\u3057\u305f\u30021\u3092\u8db3\u3057\u3066\u308b\u306e\u306f\u3001\u30c6\u3099\u30fc\u30bf\u306b\u5024 0 \u304b\u3099\u3042\u308b\u306e\u3066\u3099(\u305d\u3057\u3066\u5bfe\u6570 \u306f0\u306b\u5bfe\u3057\u3066\u5b9a\u7fa9\u3066\u3099\u304d\u306a\u3044\u306e\u3066\u3099)\u3001\u76f4\u63a5log\u3092\u4f7f\u3046\u3053\u3068\u306f\u3066\u3099\u304d\u306a\u3044\u305f\u3081\u3067\u3059\u3002<\/p>\n<pre>train[\"SalePrice\"] = np.log1p(train[\"SalePrice\"])\n<\/pre>\n<p>\u7279\u5fb4\u91cf\u3067\u3001\u6570\u5024\u3067\u304b\u3064\u6b6a\u5ea6\u304c\u5927\u304d\u3044\u5834\u5408\u306e\u307f\u540c\u69d8\u306e\u5909\u63db\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<pre>all_data = pd.concat((train.loc[:,'MSSubClass':'SaleCondition'],\n                      test.loc[:,'MSSubClass':'SaleCondition']))\n# \u6570\u5024\u306e\u307f\nnumeric_feats = all_data.dtypes[all_data.dtypes != \"object\"].index\n\n# \u6b20\u640d\u5024NaN\u3092\u9664\u5916\u5f8c\u3001\u6b6a\u5ea6\u3092\u8a08\u7b97\nskewed_feats = train[numeric_feats].apply(lambda x: skew(x.dropna())) \nskewed_feats = skewed_feats[skewed_feats \uff1e 0.75]\nskewed_feats = skewed_feats.index\n\nall_data[skewed_feats] = np.log1p(all_data[skewed_feats])\n<\/pre>\n<h2>\u30ab\u30c6\u30b4\u30ea\u5909\u6570\u306e\u5909\u63db<\/h2>\n<p>\u7279\u5fb4\u91cf\u304c\u30ab\u30c6\u30b4\u30ea\u6587\u5b57\u5217\u306e\u30c7\u30fc\u30bf\u3092\u3001\u56de\u5e30\u3067\u6271\u3048\u308b\u3088\u3046\u3059\u308b\u305f\u3081\u6570\u5024\u306b\u5909\u63db\u3057\u307e\u3059\u3002\u30ef\u30f3\u30db\u30c3\u30c8\u30a8\u30f3\u30b3\u30fc \u30c6\u3099\u30a3\u30f3\u30af\u3099\u3068\u3044\u3046\u65b9\u6cd5\u3092\u4f7f\u3044\u3001\u30ab\u30c6\u30b3\u3099\u30ea\u5909\u6570\u30921\u3064\u4ee5\u4e0a\u306e0\u30681\u306e\u5024\u3092\u6301\u3064\u65b0\u3057\u3044\u7279\u5fb4\u91cf\u3066\u3099\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002<br \/>\n\u305f\u3068\u3048\u3070GarageQual\u3068\u3044\u3046\u7279\u5fb4\u91cf\u306f\u3001Ex(Excellent)\u3001Gd\uff08Good\uff09\u3001TA\uff08Typical\/Average\uff09\u3001Fa\uff08Fair\uff09\u3001Po\uff08Poor\uff09\u3001NA\uff08No Garage\uff09\u306e\u3044\u3065\u308c\u304b\u306e\u5024\u3092\u6301\u3061\u307e\u3059\u304c\u3001\u65b0\u305f\u306b\u4ee5\u4e0b\u306e0\u307e\u305f\u306f1\u306e\u5024\u3092\u6301\u3064\u7279\u5fb4\u91cf\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n<blockquote><p>GarageQual_Ex\u3001GarageQual_Gd\u3001GarageQual_TA\u3001GarageQual_Fa\u3001GarageQual_Po\u3001GarageQual_NA\u3002<\/p><\/blockquote>\n<p>\u3068\u3044\u3046\u306e\u3092\u4ee5\u4e0b\u306e\u4e00\u884c\u3067\u3084\u3063\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<pre>all_data = pd.get_dummies(all_data)\n<\/pre>\n<h2>\u6b20\u640d\u5024\u3092\u5e73\u5747\u5024\u3067\u57cb\u3081\u308b<\/h2>\n<pre>all_data = all_data.fillna(all_data.mean())\n<\/pre>\n<h1>\u30e2\u30c7\u30eb\u4f5c\u6210<\/h1>\n<p>\u7279\u5fb4\u91cf\u306e\u4e2d\u306b\u306f\u3042\u307e\u308a\u91cd\u8981\u3067\u306a\u3044\u3082\u306e\u304c\u3042\u308b\u3088\u3046\u306a\u306e\u3067\u3001L1\u6b63\u5247\u5316\u3092\u884c\u3046Lasso\u56de\u5e30\u3067\u30e2\u30c7\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002L1\u6b63\u5247\u5316\u3092\u884c\u3046\u3068\u3001\u3044\u304f\u3064\u304b\u306e\u4fc2\u6570\u306f\u7121\u8996\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre>X_train = all_data[:train.shape[0]]\nX_test = all_data[train.shape[0]:]\ny = train.SalePrice\n\nfrom sklearn.linear_model import Lasso\nmodel_lasso = Lasso()\nscores = cross_val_score(model_lasso, X_train, y) # \u4ea4\u5dee\u691c\u8a3c\u3067\u8a55\u4fa1\nscores.mean()\n<\/pre>\n<pre>0.54583131173476207<\/pre>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u3060\u3068\u30b9\u30b3\u30a2\u4f4e\u3044\u3067\u3059\u3002Lasso\u306e\u30d1\u30e9\u30e1\u30fc\u30bfalpha\u3092\u3044\u308d\u3044\u308d\u5909\u3048\u3066\u6700\u9069\u306a\u5024\u3092\u898b\u3064\u3051\u307e\u3059\u3002<br \/>\n\u3068\u3044\u3046\u306e\u3092\u3001\u4ea4\u5dee\u691c\u8a3c\u3092\u7528\u3044\u3066\u6700\u9069\u306aalpha\u3092\u63a2\u3057\u3066\u304f\u308c\u308bLassoCV\u304c\u3084\u3063\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<pre>from sklearn.linear_model import LassoCV\nmodel_lasso = LassoCV(alphas = [1, 0.1, 0.001, 0.0005]).fit(X_train, y)\nscores = cross_val_score(model_lasso, X_train, y) # \u4ea4\u5dee\u691c\u8a3c\u3067\u8a55\u4fa1\nscores.mean()\n<\/pre>\n<pre>0.90117979437604168<\/pre>\n<p>\u3069\u306e\u7279\u5fb4\u91cf\u304c\u5f71\u97ff\u3092\u53ca\u307c\u3057\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre>coef = pd.Series(model_lasso.coef_, index = X_train.columns)\nimp_coef = pd.concat([coef.sort_values().head(10),\n                     coef.sort_values().tail(10)]) \nmatplotlib.rcParams['figure.figsize'] = (8.0, 10.0)\nimp_coef.plot(kind = \"barh\")\nplt.title(\"Coefficients in the Lasso Model\")\n<\/pre>\n<p><a href=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5417\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2-400x400.png\" alt=\"\" width=\"400\" height=\"400\" srcset=\"https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2-400x400.png 400w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2-200x200.png 200w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2-602x604.png 602w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2-144x144.png 144w, https:\/\/www.lancard.com\/blog\/wp-content\/uploads\/2018\/06\/index2.png 1176w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a><\/p>\n<p>GrLivArea\u3068\u306f\u3001\u5730\u4e0a\u306e\u5efa\u7269\u9762\u7a4d\u3067\u3059\u3002<br \/>\n<em>Above grade (ground) living area square feet<\/em><\/p>\n<h2>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4e88\u6e2c<\/h2>\n<p>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4e88\u6e2c\u3057\u3001exp\u3092\u9069\u7528\u3057\u5143\u306b\u623b\u3057\u307e\u3059\u3002<\/p>\n<pre>y_test_pred = model_lasso.predict(X_test)\ny_test_pred = np.exp(y_test_pred)-1\n<\/pre>\n<h1>\u63d0\u51fa\u30d5\u30a1\u30a4\u30eb\u300csubmission.csv\u300d\u3092\u4f5c\u6210<\/h1>\n<pre>submission = pd.DataFrame({\"Id\": test[\"Id\"],\"SalePrice\": y_test_pred})\nsubmission.loc[submission['SalePrice'] &lt;= 0, 'SalePrice'] = 0\nfileName = \"submission.csv\"\nsubmission.to_csv(fileName, index=False)\n<\/pre>\n<p>\u3042\u3068\u306f\u3001output\u30bf\u30d6\u3092\u958b\u304d\u3001\u300cSubmit to Competition\u300d\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u30b5\u30d6\u30df\u30c3\u30c8\u3055\u308c\u3001Score\u8a08\u7b97\u304c\u884c\u308f\u308c\u3001\u7d50\u679c\u304cLeader board\u4e0a\u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5380&#038;t=kaggle%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5380&#038;p&#091;images&#093;&#091;0&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-content%2Fuploads%2F2018%2F06%2Findex-400x209.png&#038;p&#091;title&#093;=kaggle%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5380&#038;text=kaggle%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5380&#038;title=kaggle%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=kaggle%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5380\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=kaggle%E3%82%92%E8%A9%A6%E3%81%97%E3%81%A6%E3%81%BF%E3%81%9F&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F5380\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6a5f\u68b0\u5b66\u7fd2\u306e\u52c9\u5f37\u3092\u306f\u3058\u3081\u307e\u3057\u305f\u3002\u4f55\u518a\u304b\u672c\u3092\u8cfc\u5165\u3057\u30b6\u30fc\u30c3\u3068\u76ee\u3092\u901a\u3057\uff08\u6df1\u304f\u306f\u7406\u89e3\u3067\u304d\u3066\u307e\u305b\u3093\uff09\u3001\u6b21\u306b\u4f55\u304b\u9069\u5f53\u306a\u30b5\u30f3\u30d7\u30eb\u3067\u6a5f\u68b0\u5b66\u7fd2\u3092\u8a66\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3057\u305f\u304c\u3001\u306a\u304b\u306a\u304b\u90fd\u5408\u304c\u826f\u3044\u30c7\u30fc\u30bf\u3068\u3044\u3046\u306e\u306f\u306a\u3044\u3067\u3059\u3002 \u305d\u3093\u306a\u6642\u306bKagg [&hellip;]<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[181,182],"class_list":["post-5380","post","type-post","status-publish","format-standard","hentry","category-python","tag-kaggle","tag-182"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=5380"}],"version-history":[{"count":46,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5380\/revisions"}],"predecessor-version":[{"id":5428,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/5380\/revisions\/5428"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=5380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=5380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=5380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}