SlideShare a Scribd company logo
1 of 127
高校生のためのデータ分析
情報科 山岸直生
目次
• テーマ0 : はじめに
• テーマ1 : 点差はどれくらい?
• テーマ2 :理科と数学の点数の関係
• テーマ3 :因果と相関
• テーマ4 : 直線を使って予想する
• テーマ5 : サイコロは偏っている?
• テーマ6 : 偏差値の計算
コンビニのカード
もっていますか?
カードを使うと
割引されるのは
なぜ?
カードを使うと
割引されるのは
なぜ?
どういう人が、
どういうときにどんな商品を、
どんな商品と一緒に、
購入しているかがわかる
カードを使うと
割引されるのは
なぜ?
・在庫管理
・棚の配置
・割引企画
・新商品開発
などに役立つ
学校にもデータは
たくさんある
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
テスト結果
から何が
わかるだろうか?
テスト結果からわかること
• どのくらいの難易度だったか
• どのくらい点差がついたか
• だれがどのくらいできるか
⇒他にもいっぱいある
テスト結果からわかること
• どのくらいの難易度だったか
⇒平均
• どのくらい点差がついたか
⇒偏差
• だれがどのくらいできるか
⇒合計
学校にもデータは
たくさんある
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
自力でできるなら・・・
⑥各生徒の平均点を出せ
⑦各科目の中央値(メジアン)を出せ
⑧各生徒の順位を出せ
⑨この試験問題において、
数学で90点とるのと理科で90点とるのとでは、
どちらがより「すごい」と考えられるか。
テーマ1:
点差はどのくらい?
どのくらいの差がついた?
国語 数学
49 0
51 0
48 100
52 100
平均を引いてみよう
国語 数学
49(-1) 0(-50)
51(+1) 0(-50)
48(-2) 100(+50)
52(+2) 100(+50)
( )の中の数値:偏差
国語 数学
49(-1) 0(-50)
51(+1) 0(-50)
48(-2) 100(+50)
52(+2) 100(+50)
どのくらいの差?
国語 数学
-1 -50
+1 -50
-2 +50
+2 +50
平均を計算する??
国語
-1
+1
-2
+2
点差はどのくらい?
数学
-50
-50
+50
+50
偏差の平均は0
国語 数学
-1 -50
+1 -50
-2 +50
+2 +50
差を計算するには?
国語 数学
-1 -50
+1 -50
-2 +50
+2 +50
偏差の「絶対値」を使えばいい?
国語 数学
-1(1) -50(50)
+1(1) -50(50)
-2(2) +50(50)
+2(2) +50(50)
偏差の絶対値
国語 数学
1 50
1 50
2 50
2 50
偏差の絶対値の平均
国語
1
1
2
2
偏差の絶対値の平均
数学
50
50
50
50
偏差の絶対値の平均
国語:1.5
数学:50
なので数学の方が
48.5点分
点差がつきやすい
国語 数学
49 0
51 0
48 100
52 100
偏差の絶対値の平均=平均偏差
国語 数学
49 0
51 0
48 100
52 100
平均偏差 1.5 50
どのくらい
点差がつきやすいか
を調べるには
平均偏差(Average Deviation)
を計算すればいい
Excelで計算
似てるけど少し違う用語
平均偏差より標準偏差
の方がよく使う?
• 平均偏差(Average Deviation)
⇒偏差の絶対値の平均
• 標準偏差(Standard Deviation)
⇒偏差の二乗の平均のルート
標準偏差の計算をしてみよう
国語 数学
49 0
51 0
48 100
52 100
偏差
国語 数学
-1 -50
+1 -50
-2 50
+2 50
二乗
国語 数学
1 2500
1 2500
4 2500
4 2500
平均
国語 数学
1 2500
1 2500
4 2500
4 2500
平均 2.5 2500
ルート
国語 数学
1 2500
1 2500
4 2500
4 2500
平均 2.5 2500
ルート 1.58 50
計算結果
国語 数学
49 0
51 0
48 100
52 100
平均偏差 1.5 50
標準偏差 1.58 50
Excelで計算
Rで計算
まとめ
• データを見たらまず
・平均(average)
・標準偏差(standard deviation)
をチェックしよう
課題
• 偏差値について調べてみよう。
• 五数要約について調べてみよう。
練習:標準偏差を求めてみよう
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
テーマ2:
数学の点が高い人は
理科の点も高い?
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
数学と理科の関係をどう示す?
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
数学ー理科の散布図を描く
30
40
50
60
70
80
90
100
30 40 50 60 70 80 90 100
理科
数学
右に行くほど
上にデータがある感じがする?
30
40
50
60
70
80
90
100
30 40 50 60 70 80 90 100
理科
数学
右に行くほど上にデータがある
⇒正の相関がある という
30
40
50
60
70
80
90
100
30 40 50 60 70 80 90 100
理科
数学
正の相関がある散布図の例
負の相関がある散布図の例
散布図を描けば
2つの科目間の
関係がわかる
Excelで散布図を描く
「相関」は計算できる?
相関は計算できる?
相関は計算できる?
相関係数
• R
• correlation coefficient
• 右に行くほど
上に行けば大きくなる
相関係数R
⇒Rが大きいほど、正の相関が大きい
⇒Rが小さいほど、負の相関が大きい
相関係数
• −1 ≤ 𝑅 ≤ 1の範囲の値をとる
• R=1: 右上がりの直線
• R=-1 : 右下がりの直線
• R > 0 : 正の相関がある
• R < 0 :負の相関がある
𝑅 = −0.76
𝑅 = −0.05
R=0.24
相関係数からわかること
• 数学と理科の相関係数はR=0.91
⇒強い正の相関がある
⇒数学ができる人は
理科もできる可能性が高い
まとめ
二変数データをみたら、
散布図を描こう
Rによる散布図行列
散布図行列を作成してみよう
国語<-c(85,70,40,60,90,45,86)
英語<-c(80,75,40,60,100,20,94)
数学<-c(65,90,30,100,60,45,86)
理科<-c(70,85,60,85,65,55,91)
test<-c(国語,英語,数学,理科)
テスト<-matrix(t(test),nrow=7,ncol=4)
colnames(テスト)<-c("国語","英語","数学","理科")
pairs(test,cex=3)
さらに工夫すると・・・
まとめ
多変数データをみたら、
散布図行列を描こう
練習:
他の科目間の相関係数を
求めてみましょう
テーマ3:
因果と相関
次の散布図からいえることは?
R = 0.905
散布図からいえること
• 気温が高いほど、売上が多い?
• 売上が多いほど、気温が高い?
• 気温が上がることによって、売上が変わる?
• 売上が上がることによって、気温が上がる?
散布図からいえること?
○気温が高いほど、売上が多い
○売上が多いほど、気温が高い
○気温が上がることによって、売上が上がる
×売上が上がることによって、気温が上がる
散布図からいえること?
○気温が上がる ⇒ 売上が変わる
×売上が上がる ⇒ 気温が上がる
散布図からいえること?
原因:気温が上がる
結果: 売上が変わる
散布図からいえること?
原因:気温が上がる
結果: 売上が変わる
直接関係
R = 0.81
散布図からいえること?
気温が上がる
水難事故が増える
散布図からいえること?
気温が上がる
海水浴客が増える
水難事故が増える
散布図からいえること?
気温が上がる
海水浴客が増える
水難事故が増える
間
接
関
係
R = 0.85
R = 0.98
Rの計算結果
気温が上がる
海水浴客が増える
水難事故が増える
間
接
関
係
R = 0.81
R = 0.98
R = 0.85
R = 0.86
• 原因:水難事故件数
• 結果:アイスの売り上げ個数
• 原因:水難事故件数
• 結果:アイスの売り上げ個数
ではないよね?
気温
アイス
水難事故
気温
アイス
水難事故
気温
アイス
水難事故
共通原因による
疑似相関
相関があっても、
原因結果関係があるとは
限らない!
課題
• 疑似相関について
調べてみよう
参考
テーマ4:
直線を使って予想する
理科が80点の人の数学の点数は?
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
理科が80点の人の
数学の点数は?
生徒番号 国語 英語 数学 理科
1 85 80 65 70
2 70 75 90 85
3 40 40 30 60
4 60 60 100 85
5 90 100 60 65
6 45 20 45 55
7 86 94 86 91
散布図を描いて予想してみよう
R = 0.91
回帰直線
理科が80点の生徒は
数学も80点くらいだと予想される
数学=理科×1.7-50
課題
• Excelまたは統計処理ソフトRで、
同じようなことをやってみよう。
• 英語が50点の人の国語の点数は?
テーマ5:
サイコロの出た目は
偏ってるの?
乱数とヒストグラム
0~1が同じ確率
で出る乱数をパソコンは
発生させることができる
1~6が同じ確率
で出る乱数をパソコンは
発生させることができる
このようにつくった
サイコロの目は偏って
いないだろうか?
10万回サイコロ
を振ってみよう
各目10万÷6=16667回
ずつ目が出るはず
0 5 10 15 20 25
1
2
3
4
5
6
まとめ
かなり多くの回数さいころを振らないと
「本当に偏っているか」はわからない
テーマ6:
実際に「偏差値」を
計算してみよう
「偏差」を計算することで
平均が0のデータをつくれる
「偏差」を計算することで
平均が0のデータをつくれる
標準偏差が同じデータを
つくるには?
復習
国語 数学
49 0
51 0
48 100
52 100
偏差
国語 数学
-1 -50
+1 -50
-2 +50
+2 +50
平均は0
国語 数学
-1 -50
+1 -50
-2 +50
+2 +50
標準偏差は「ばらつき」度合い
国語 数学
49 0
51 0
48 100
52 100
標準偏差 1.58 50
「ばらつき度合い」を
同じにするには?
「ばらつき度合い」を
同じにするには?
バラつき度合い:標準偏差
で割ればいい
偏差に直す
国語 数学
-1 -50
+1 -50
-2 +50
+2 +50
標準偏差で割った
国語 数学
-1(-0.63) -50(-1)
+1(0.63) -50(-1)
-2(-1.26) +50(1)
+2(1.26) +50(1)
標準偏差 1.58 50
これをZ値という
国語 数学
-0.63 -1
0.63 -1
-1.26 1
1.26 1
Z値
国語 数学
-0.63 -1
0.63 -1
-1.26 1
1.26 1
標準偏差 1.0 1.0
平均 0 0
Z値の性質
• 平均0
• 標準偏差1
• 普通、-1~1の間に70%
くらいのデータが含まれる

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Data analysis-for-highschool-students

Editor's Notes

  1. これを応用したのが偏差値である
  2. 以下のコードをRに打ち込んで作成した。 国語<-c(85,70,40,60,90,45,86) 英語<-c(80,75,40,60,100,20,94) 数学<-c(65,90,30,100,60,45,86) 理科<-c(70,85,60,85,65,55,91) test<-c(国語,英語,数学,理科) テスト<-matrix(t(test),nrow=7,ncol=4) colnames(テスト)<-c("国語","英語","数学","理科") pairs(test,cex=3)
  3. library(psych) pairs.panels(テスト,cex=1.1)
  4. <R言語にて下のコードを打ち込んで作成> 気温<-c(17.1,17.2,17.5,17.7,18,18.2,18.3,18.5,18.8,18.9,19,19.3,19.4,19.5,19.5,19.6,19.7,19.7,19.8,19.9,20.0,20,20,20,20.1,20.1,20.2 ,20.3,20.4,20.5,20.6,20.7,20.7,20.7,20.8,20.9,21,21.1,21.2,21.3,21.4,21.5,21.6,21.7,22,22.1,22.3,22.5,22.6,23,23.2,23.2,23.3,23.5, 24,24.1,24.3,25,25.1,25.3,25.4,25.5,25.6,26) 売上個数<- round((70+sqrt(気温)*5+気温*8+((気温-13)^2)/3.0+((気温-16)^3)/12.0+((気温-17)^4)/35.0+rnorm(length(気温))*15+5*(rnorm(length(気温))^2)+(rnorm(length(気温))^3)*4.0+(rnorm(length(気温))^4)*2.0+(rnorm(length(気温))^5))/2.5) plot(気温,売上個数,xlim=c(17,26),ylim=c(50,280),main="気温とアイスの売り上げ数",lwd=2,cex=2.5,cex.lab=2,cex.axis=1.5,cex.main=3)
  5. 風<-rnorm(length(気温)) 海水浴客<-round(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(floor(abs(abs(abs(abs(round(abs(floor(floor(floor(abs(abs(abs(abs(abs(abs((abs(abs(abs(round(((気温-17.1)*50+((気温-17.1)^2)*400+((気温-17.1)^3)*150+((気温-17.1)^4)*50+((気温-17.1)^5)*5+rnorm(length(気温))*100+(rnorm(length(気温))^2)-4)*50))-15)-10)*(5-風))-8)-6)-5)-4)-3)-2)/200.0)-1)/10))/2)-5)-4)-3)-2)/2.0)-20)-19)-18)-17)-16)-15)-14)-13)-12)-11)-10)-9)-8)-7)-6)-5)-4)-3)-2)-1)-1)+rnorm(気温)^6-3)-2)-1)/2.5) set.seed(2) 水難事故<- round((海水浴客*5+(rnorm(length(気温))^2)*100)/10000*(4-風)) plot(気温,水難事故,xlim=c(17,26),ylim=c(0,30),main="気温と水難事故件数",lwd=2,cex=2.5,cex.lab=2,cex.axis=1.5,cex.main=3)
  6. 普通は疑似相関の方がRが小さくなります
  7. 普通は疑似相関の方がRが小さくなります
  8. http://pub.maruzen.co.jp/book_magazine/support/support.html
  9. 因果<-c(気温,売上個数,海水浴客,水難事故) 因果律<-matrix(t(因果),nrow=length(気温),ncol=4) colnames(因果律)<-c("気温","売上","海水浴","水事") pairs.panels(因果律)
  10. 数学<-c(65,90,30,100,60,45,86) 理科<-c(70,85,60,85,65,55,91) cor(数学,理科) plot(理科,数学,xlim=c(50,100),ylim=c(30,100),main="理科と数学の点数",lwd=2,cex=2.5,cex.lab=2,cex.axis=1.5,cex.main=3) lm.obj<-lm(数学~理科) abline(lm.obj,col=2) lm.obj