差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
mselab:2012:stat:week2:r2 [2012/12/11 14:18] – watalu | mselab:2012:stat:week2:r2 [不明な日付] (現在) – 外部編集 (不明な日付) 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
===== 統計工学 2週目 ===== | ===== 統計工学 2週目 ===== | ||
==== はじめに ==== | ==== はじめに ==== | ||
+ | === 連絡 2012.12.11 === | ||
+ | |||
+ | * 自分で頑張って、とお願いした、回帰分析と決定木分析のコードを追記しました。 | ||
+ | * このページを実験時間中に改訂しましたが、[[http:// | ||
+ | * TICデータの[[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | |||
=== 概要 === | === 概要 === | ||
行 13: | 行 22: | ||
* 先週に続いてデータの把握、特にV86を中心に。 | * 先週に続いてデータの把握、特にV86を中心に。 | ||
- | * 回帰分析の2つの課題(自習、練習に相当) | + | * 回帰分析の2つの課題、同じ課題を決定木も(自習、練習に相当) |
* 解析データを用いた1つの課題(本番) | * 解析データを用いた1つの課題(本番) | ||
に取り組んで貰う。 | に取り組んで貰う。 | ||
- | |||
==== 実験の流れ ==== | ==== 実験の流れ ==== | ||
行 103: | 行 111: | ||
**問2:このplot関数の出力結果を、配付資料と対比させて理解せよ。** | **問2:このplot関数の出力結果を、配付資料と対比させて理解せよ。** | ||
- | == 重回帰分析 == | + | === 重回帰分析 |
表5.1のデータは次のように入力する。 | 表5.1のデータは次のように入力する。 | ||
行 134: | 行 142: | ||
**問4:このplot関数の出力結果を、配付資料と対比させて理解せよ。** | **問4:このplot関数の出力結果を、配付資料と対比させて理解せよ。** | ||
- | == 重回帰応用(水準変数が説明変数に含まれる場合) == | + | === 重回帰応用(水準変数が説明変数に含まれる場合) |
上のデータを、広さを「広め(w)」「狭め(n)」とし、築年数も「新しめ(new)」「古め(old)」にする | 上のデータを、広さを「広め(w)」「狭め(n)」とし、築年数も「新しめ(new)」「古め(old)」にする | ||
行 153: | 行 161: | ||
</ | </ | ||
- | === 時間内課題2:決定木分析の自習 === | + | ==== 時間内課題2:決定木分析の自習 |
まず、次の一行を実行しておく。 | まず、次の一行を実行しておく。 | ||
行 167: | 行 175: | ||
print(rpart.4.1) | print(rpart.4.1) | ||
summary(rpart.4.1) | summary(rpart.4.1) | ||
+ | plot(rpart.4.1) | ||
+ | text(rpart.4.1) | ||
+ | </ | ||
+ | |||
+ | < | ||
rpart.5.1 <- rpart(y~x.1+x.2, | rpart.5.1 <- rpart(y~x.1+x.2, | ||
print(rpart.5.1) | print(rpart.5.1) | ||
summary(rpart.5.1) | summary(rpart.5.1) | ||
+ | plot(rpart.5.1) | ||
+ | text(rpart.5.1) | ||
+ | </ | ||
+ | |||
+ | < | ||
rpart.5.1.c <- rpart(y~x.1+x.2, | rpart.5.1.c <- rpart(y~x.1+x.2, | ||
print(rpart.5.1.c) | print(rpart.5.1.c) | ||
summary(rpart.5.1.c) | summary(rpart.5.1.c) | ||
+ | plot(rpart.5.1.c) | ||
+ | text(rpart.5.1.c) | ||
</ | </ | ||
- | **問6:これらがどのようなモデルか、データと出力に照らして検討せよ。** | + | **問6:これらがどのようなモデルか、データと出力に照らして検討せよ。** |
==== 課題:保険会社の顧客データのデータマイニング ==== | ==== 課題:保険会社の顧客データのデータマイニング ==== | ||
行 209: | 行 228: | ||
[[http:// | [[http:// | ||
- | |変数|分類|メモ| | + | ^変数^分類^メモ^ |
|V1|顧客分類2|L0でコード化されている、数字の大きさに意味なし| | |V1|顧客分類2|L0でコード化されている、数字の大きさに意味なし| | ||
|V2|住居数|大きいほど住む箇所が多い| | |V2|住居数|大きいほど住む箇所が多い| | ||
行 242: | 行 261: | ||
</ | </ | ||
+ | == 変数詳細 == | ||
+ | |||
+ | ^Nr^Name^Description Domain^ | ||
+ | |V1|MOSTYPE|Customer Subtype see L0| | ||
+ | |V2|MAANTHUI|Number of houses 1 - 10| | ||
+ | |V3|MGEMOMV|Avg size household 1 - 6| | ||
+ | |V4|MGEMLEEF|Avg age see L1| | ||
+ | |V5|MOSHOOFD|Customer main type see L2| | ||
+ | |V6|MGODRK|Roman catholic see L3| | ||
+ | |V7|MGODPR|Protestant ...| | ||
+ | |V8|MGODOV|Other religion| | ||
+ | |V9|MGODGE|No religion (無宗教)| | ||
+ | |V10|MRELGE|Married (既婚)| | ||
+ | |V11|MRELSA|Living together (同居)| | ||
+ | |V12|MRELOV|Other relation (その他)| | ||
+ | |V13|MFALLEEN|Singles (独身)| | ||
+ | |V14|MFGEKIND|Household without children (子供のいない世帯)| | ||
+ | |V15|MFWEKIND|Household with children (子供のいる世帯)| | ||
+ | |V16|MOPLHOOG|High level education (高等教育)| | ||
+ | |V17|MOPLMIDD|Medium level education (中等教育)| | ||
+ | |V18|MOPLLAAG|Lower level education (初等教育)| | ||
+ | |V19|MBERHOOG|High status| | ||
+ | |V20|MBERZELF|Entrepreneur| | ||
+ | |V21|MBERBOER|Farmer (農業)| | ||
+ | |V22|MBERMIDD|Middle management (中間管理職)| | ||
+ | |V23|MBERARBG|Skilled labourers (熟練労働者)| | ||
+ | |V24|MBERARBO|Unskilled labourers (非熟練労働者)| | ||
+ | |V25|MSKA|Social class A| | ||
+ | |V26|MSKB1|Social class B1| | ||
+ | |V27|MSKB2|Social class B2| | ||
+ | |V28|MSKC|Social class C| | ||
+ | |V29|MSKD|Social class D| | ||
+ | |V30|MHHUUR|Rented house| | ||
+ | |V31|MHKOOP|Home owners| | ||
+ | |V32|MAUT1|1 car (保有車1台)| | ||
+ | |V33|MAUT2|2 cars (保有車2台)| | ||
+ | |V34|MAUT0|No car (保有車なし)| | ||
+ | |V35|MZFONDS|National Health Service| | ||
+ | |V36|MZPART|Private health insurance| | ||
+ | |V37|MINKM30|Income < 30.000| | ||
+ | |V38|MINK3045|Income (収入) 30-45.000| | ||
+ | |V39|MINK4575|Income (収入) 45-75.000| | ||
+ | |V40|MINK7512|Income (収入) 75-122.000| | ||
+ | |V41|MINK123M|Income (収入) > | ||
+ | |V42|MINKGEM|Average income (平均収入)| | ||
+ | |V43|MKOOPKLA|Purchasing power class| | ||
+ | |V44|PWAPART|Contribution (契約高) private third party insurance see L4| | ||
+ | |V45|PWABEDR|Contribution (契約高) third party insurance (firms) ...| | ||
+ | |V46|PWALAND|Contribution (契約高) third party insurane (agriculture)| | ||
+ | |V47|PPERSAUT|Contribution (契約高) car policies| | ||
+ | |V48|PBESAUT|Contribution (契約高) delivery van policies| | ||
+ | |V49|PMOTSCO|Contribution (契約高) motorcycle/ | ||
+ | |V50|PVRAAUT|Contribution (契約高) lorry policies| | ||
+ | |V51|PAANHANG|Contribution (契約高) trailer policies| | ||
+ | |V52|PTRACTOR|Contribution (契約高) tractor policies| | ||
+ | |V53|PWERKT|Contribution (契約高) agricultural machines policies | | ||
+ | |V54|PBROM|Contribution (契約高) moped policies| | ||
+ | |V55|PLEVEN|Contribution (契約高) life insurances| | ||
+ | |V56|PPERSONG|Contribution (契約高) private accident insurance policies| | ||
+ | |V57|PGEZONG|Contribution (契約高) family accidents insurance policies| | ||
+ | |V58|PWAOREG|Contribution (契約高) disability insurance policies| | ||
+ | |V59|PBRAND|Contribution (契約高) fire policies| | ||
+ | |V60|PZEILPL|Contribution (契約高) surfboard policies| | ||
+ | |V61|PPLEZIER|Contribution (契約高) boat policies| | ||
+ | |V62|PFIETS|Contribution (契約高) bicycle policies| | ||
+ | |V63|PINBOED|Contribution (契約高) property insurance policies| | ||
+ | |V64|PBYSTAND|Contribution (契約高) social security insurance policies| | ||
+ | |V65|AWAPART|Number of (契約口数) private third party insurance 1 - 12| | ||
+ | |V66|AWABEDR|Number of (契約口数) third party insurance (firms) ...| | ||
+ | |V67|AWALAND|Number of (契約口数) third party insurane (agriculture)| | ||
+ | |V68|APERSAUT|Number of (契約口数) car policies| | ||
+ | |V69|ABESAUT|Number of (契約口数) delivery van policies| | ||
+ | |V70|AMOTSCO|Number of (契約口数) motorcycle/ | ||
+ | |V71|AVRAAUT|Number of (契約口数) lorry policies| | ||
+ | |V72|AAANHANG|Number of (契約口数) trailer policies| | ||
+ | |V73|ATRACTOR|Number of (契約口数) tractor policies| | ||
+ | |V74|AWERKT|Number of (契約口数) agricultural machines policies| | ||
+ | |V75|ABROM|Number of (契約口数) moped policies| | ||
+ | |V76|ALEVEN|Number of (契約口数) life insurances| | ||
+ | |V77|APERSONG|Number of (契約口数) private accident insurance policies| | ||
+ | |V78|AGEZONG|Number of (契約口数) family accidents insurance policies| | ||
+ | |V79|AWAOREG|Number of (契約口数) disability insurance policies| | ||
+ | |V80|ABRAND|Number of (契約口数) fire policies| | ||
+ | |V81|AZEILPL|Number of (契約口数) surfboard policies| | ||
+ | |V82|APLEZIER|Number of (契約口数) boat policies| | ||
+ | |V83|AFIETS|Number of (契約口数) bicycle policies| | ||
+ | |V84|AINBOED|Number of (契約口数) property insurance policies| | ||
+ | |V85|ABYSTAND|Number of (契約口数) social security insurance policies| | ||
+ | |V86|CARAVAN|Number of (契約口数) mobile home policies 0 - 1| | ||
== 各変数のコーディング == | == 各変数のコーディング == | ||
行 247: | 行 355: | ||
L0: | L0: | ||
- | |Value|Label| | + | ^Value^Label^ |
|1|High Income, expensive child| | |1|High Income, expensive child| | ||
|2|Very Important Provincials| | |2|Very Important Provincials| | ||
行 362: | 行 470: | ||
tic.eval <- ticdata[5823: | tic.eval <- ticdata[5823: | ||
</ | </ | ||
- | |||
=== 準備 === | === 準備 === | ||
行 1295: | 行 1402: | ||
|V84|5777|44|1| | | | | | |V84|5777|44|1| | | | | | ||
- | === 参考 === | + | ==== 参考 |
- | == 少し加工する == | + | === V86も因子変数にしてみると == |
- | 以下の6行は、実行しない方がいい場合もある。 | + | V86まで因子変数に変えると、glm関数の挙動が少し変わるかも。 |
< | < | ||
- | tic.learn$V1 <- as.factor(tic.learn$V1) | + | tic.learn$V86f <- as.factor(tic.learn$V86) |
- | tic.learn$V5 <- as.factor(tic.learn$V5) | + | |
- | tic.learn$V86 <- as.factor(tic.learn$V86) | + | |
- | tic.eval$V1 <- as.factor(tic.eval$V1) | + | |
- | tic.eval$V5 <- as.factor(tic.eval$V5) | + | |
- | tic.eval$V86 <- as.factor(tic.eval$V86) | + | |
</ | </ | ||
- | あとはそのまま。 | + | === 訪問客リストを作成したい場合 === |
== 考えたルールに基づく対象限定 == | == 考えたルールに基づく対象限定 == | ||
行 1392: | 行 1493: | ||
で38.275%となる。 | で38.275%となる。 | ||
- | == 想定される困難 == | + | === TICデータでロジスティック回帰を行う場合のメモ === |
+ | == 想定される困難 | ||
次の1行を実行すると、かなり時間がかかってエラーになる。 | 次の1行を実行すると、かなり時間がかかってエラーになる。 | ||
行 1439: | 行 1541: | ||
V61+V62+V63+V64, | V61+V62+V63+V64, | ||
</ | </ | ||
+ |