Let's use another type of visualization that's helpful for seeing
the distribution of a variable called a box plot. Now if
you're unfamiliar with a box plot, you can find resources in
the instructor notes, and there's also a link to [UNKNOWN] statistic
class so you can test your own knowledge. You may recall
earlier that we split friend count by gender in a pair
of histograms using facet wrap. The code looked like this. Instead
of using these histograms we're going to generate box plots of friend
count by gender, so we can quickly see the differences between
the distributions. And in particular we're going to see the difference between
the median of the two groups. And remember again the the
q plot function automatically generates histograms (/g) when we pass it a
single variable. So we need to add a parameter to tell
q plot that we want a different type of plot. To
do that, we're going to use the gym called box plot. Now,
I'm going to use the same data set as before. So I'm going to
keep this and q plot. Now, what's different about box
plots is that the y axis is going to be
our friend count. The x axis, on the other hand,
is going to be our categorical variables for male and female, or
gender. Notice that we use the continuous variables. Friend count
as y. And the grouping, or the categorical variable as x.
This will always be true for your box plots. I
forgot a parenthesis here and then let me just reformat my
code so it looks a little bit cleaner. There we go.
Running this code, we can see that we get our two box
plots. Let's zoom in to get a closer look. The boxes here
and here cover the middle 50% of values, or what's called the
inner quartile range. And I know these boxes are hard to see,
since we have so many outliers on this plot. Each of these
tiny little dots is an outlier in our data. We can also
see that the y axis is capturing all the friend counts from
zero all the way up to 5,000. So we're not
omitting any user data in this plot. And finally, this horizontal
line, which you may have noticed at first, is the
median for the two box plots. And you might be wondering
what makes an outlier an actual outlier. And well, we
usually consider outliers to be just outside of, one and a
half times the IQR from the media. Since there's so
many outliers in these plots, let's adjust our code to focus
on just these two boxes. We'll have you do this in the next
programming exercise. See, if you can altar our code to make that adjustment.
فلنستخدم نوعًا آخر من التصورات المرئية يساعد على رؤية
توزيع أحد المتغيرات ويطلق عليه رسم مربع. والآن، إذا
كنتم غير معتادين على رسم مربع، فيمكنكم أن تعثروا على موارد في
ملاحظات المدرب، ويوجد أيضًا رابط [UNKNOWN] للاختبار الإحصائي
حتى يمكنكم أن تختبروا معرفتكم الخاصة. وربما تتذكرون
أننا في السابق قسمنا friend_count حسب النوع في زوجٍ
من المدرجات التكرارية باستخدام facet_wrap. وتبدو التعليمة البرمجية هكذا. بدلاً من
استخدام هذه المدرجات التكرارية سننشئ رسومات مربعة خاصة بـ friend_count
حسب النوع، حتى يمكننا أن نرى بسرعة الاختلافات بين
التوزيعات. وتحديدًا سنرى الاختلاف بين
الوسيط الخاص بالمجموعتين. وتذكروا مرة أخرى أن
دالة q plot تنشئ تلقائيًا المدرجات التكرارية (/g) عندما نمرر فيها
متغيرًا مفردًا. لذا، نحتاج أن نضيف معلمة لتخبر الدالة
.q plot أننا نريد نوع رسم مختلفًا
،ولفعل ذلك، سنستخدم gym التي يطلق عليه اسم رسم مربع. والآن
سأستخدم نفس مجموعة البيانات كما فعلنا من قبل. لذا سأحتفظ بهذا
وبدالة q plot. الآن، وجه الاختلاف في رسومات المربع
أن المحور y سيكون
friend_count. ومن ناحية أخرى، سيكون
المحور x هو المتغيرات المطلقة للذكور والإناث
أو النوع. لاحظوا أننا نستخدم المتغيرات المستمرة. Friend_count
.على المحور y والتجميع أو المتغير المطلق على المحور x
.ويُعد هذا صحيحًا دائمًا في حالة الرسومات المربعة
نسيت وضع قوس هنا، فدعوني أُعِد تنسيق
.التعليمة البرمجية حتى تبدو أوضح قليلاً. هكذا نعمل بصورة صحيحة
بتشغيل هذه التعليمة البرمجية يمكننا أن نرى أننا حصلنا على
رسمين مربعين. سنقوم بالتكبير لنحصل على صورة مقربة. تغطي المربعات هنا
وهنا نسبة 50% في وسط القيم، أو ما يطلق عليه اسم
،نطاق الربع الإحصائي الداخلي. وأعرف أنه من الصعب رؤية هذه المربعات
لأن لدينا العديد من القيم الخارجية في هذا الرسم. تمثل كل من هذه النقاط الدقيقة القليلة
قيمة خارجية في البيانات. يمكننا أن نرى
أيضًا أن المحور y يسجل كل قيم friend_count من
الصفر حتى 5000. لذلك لا نحذف
أي بيانات للمستخدم في هذا الرسم. وأخيرًا، هذا الخط
الأفقي، الذي ربما لاحظتموه في البداية يمثل
الوسيط للرسمين المربعين. وقد تتساءلون
،ما الذي يجعل القيمة الخارجية قيمة خارجية فعلية. حسنًا
عادةً ما نعتبر القيم الخارجية خارج
IQR بمقدار مرة ونصف من الوسائط. ونظرًا لوجود
العديد من القيم الخارجية في هذه الرسومات، فلنعدّل التعليمة البرمجية لتركز على
هذين المربعين فقط. وسنجعلكم تقومون بهذا في التدريب
.التالي على البرمجة. ولتقرروا هل بإمكانكم تعديل التعليمة البرمجية لتنفيذ هذا الضبط
Let's use another type of visualization that's helpful for seeing
the distribution of a variable called a box plot. Now if
you're unfamiliar with a box plot, you can find resources in
the instructor notes, and there's also a link to Udacity statistic
class so you can test your own knowledge. You may recall
earlier that we split friend count by gender in a pair
of histograms using facet wrap. The code looked like this. Instead
of using these histograms we're going to generate box plots of friend
count by gender, so we can quickly see the differences between
the distributions. And in particular we're going to see the difference between
the median of the two groups. And remember again the the
q plot function automatically generates histograms (/g) when we pass it a
single variable. So we need to add a parameter to tell
q plot that we want a different type of plot. To
do that, we're going to use the gym called box plot. Now,
I'm going to use the same data set as before. So I'm going to
keep this and q plot. Now, what's different about box
plots is that the y axis is going to be
our friend count. The x axis, on the other hand,
is going to be our categorical variables for male and female, or
gender. Notice that we use the continuous variables. Friend count
as y. And the grouping, or the categorical variable as x.
This will always be true for your box plots. I
forgot a parenthesis here and then let me just reformat my
code so it looks a little bit cleaner. There we go.
Running this code, we can see that we get our two box
plots. Let's zoom in to get a closer look. The boxes here
and here cover the middle 50% of values, or what's called the
inner quartile range. And I know these boxes are hard to see,
since we have so many outliers on this plot. Each of these
tiny little dots is an outlier in our data. We can also
see that the y axis is capturing all the friend counts from
zero all the way up to 5,000. So we're not
omitting any user data in this plot. And finally, this horizontal
line, which you may have noticed at first, is the
median for the two box plots. And you might be wondering
what makes an outlier an actual outlier. And well, we
usually consider outliers to be just outside of, one and a
half times the IQR from the media. Since there's so
many outliers in these plots, let's adjust our code to focus
on just these two boxes. We'll have you do this in the next
programming exercise. See, if you can altar our code to make that adjustment.
箱ひげ図という別のタイプの可視化を使って
変数分布を見てみましょう
箱ひげ図の情報はインストラクターノートにあり
UDACITY統計学クラスのリンクもあるので
そこで知識を確認することもできます
先ほど友達数のヒストグラムを
facet_wrapを使い
性別ごとに分割した時のコードはこうでした
今度は性別ごとの友達数の箱ひげ図を作成します
そうすれば分布の違いを一目で確認できます
特に2つのグループの中央値の違いを見ていきます
qplot関数は
1つの変数を与えると自動でヒストグラムを作成します
なのでqplotに違うタイプの図を作成するように
パラメータを追加して指示する必要があります
boxplotというジオメトリを使います
データ集合は以前と同じものです
なのでこれとqplotはそのままにします
箱ひげ図ではy軸が友達数を表す度数になり
x軸がカテゴリ変数になるので
男性、女性と性別が表示されます
yつまりfriend_countが
連続変数であることに注意してください
グループ分けのカテゴリ変数がxとなります
箱ひげ図は常にこの形式になります
ここの括弧を忘れたのでコードを再編成して整えます
コードを実行すると
2つの箱ひげ図ができました
クローズアップして見てみましょう
この箱は中間の50%の値を占める
四分位数範囲と呼ばれるものです
多くの外れ値が存在するため
この箱は見にくいですね
この小さな点がこのデータの外れ値です
またy軸の友達数はゼロから
最高値の5,000まで表示されています
ユーザデータをすべて反映しているのです
そしてこの水平線の部分が
2つの箱ひげ図の中央値となります
実際に外れ値と見なされるのはどの値でしょうか
通常は中央値の四分位数範囲(IQR)から
1.5倍のすぐ外にあるものを外れ値と考えます
この図は外れ値を多く含むのでコードを調整します
次のプログラミング練習問題に取り組み
コードを変更してその調整ができるか試してみましょう
Vamos usar outro tipo de visualização que será útil para ver
a distribuição de uma variável chamada de gráfico de caixa. Se você
não estiver familiarizado com um gráfico de caixa, você pode localizar recursos nas
notas do instrutor e há também um link para classe estatística [UNKNOWN]
, dessa forma, você pode testar seu próprio conhecimento. Lembre-se que
anteriormente dividimos a contagem de amigos por sexo em um par de
histogramas que usam o envoltório de faceta. O código era assim. Em vez
de usar esses histogramas, vamos gerar gráficos de caixa de contagem de
amigos por sexo, dessa forma, poderemos ver rapidamente as diferenças entre
as distribuições. E, particularmente, vamos ver a diferença entre
a média de dois grupos. Lembre-se novamente de que a
função q plot gera, automaticamente, histogramas (/g) quando a passamos para uma
variável simples. Precisamos adicionar um parâmetro para informar a
q plot que precisamos de um tipo diferente de gráfico. Para
fazer isso, vamos usar o geom chamado gráfico de caixa. Vou
usar o mesmo conjunto de dados de antes. Vou
manter este e o q plot. O que é diferente no gráfico
de caixa é que o eixo y será
nossa contagem de amigos. O eixo x, por outro lado,
trata-se de nossas variáveis de categoria para masculinos e feminino, ou
sexo. Observe que usamos as variáveis contínuas. Contagem de amigos,
como y; e o agrupamento ou variável de categoria, como x.
Isso sempre ocorrerá para seus gráficos de caixa. Esqueci
um parêntese aqui, então deixe-me apenas reformatar meu
código, para que ele pareça um pouco mais claro. Aqui está.
Ao executar este código, temos nossos dois gráficos
de caixa. Vamos ampliar para um olhar mais atento. As caixas aqui
e aqui abrangem a média de 50% dos valores ou o que chamamos de
intervalo de quartis interno. E sei que essas caixas são difíceis de ver,
pois temos muitas exceções nesta caixa. Cada um desses
minúsculos pontos significam uma exceção em nossos dados. Também podemos ver que
o eixo y está capturando todas as contagens de amigos de
zero até 5.000. Não estamos
omitindo nenhum dado do usuário neste gráfico. E finamente, esta linha
horizontal, que você pode ter observado primeiro, é a
média para os dois gráficos de caixa. E você pode estar se perguntando
o que transforma uma exceção em uma exceção real. Geralmente,
consideramos exceções fora, um e metade
do IQR da média. Como há
muitas exceções nestes gráficos, vamos ajustar nosso código para focar
apenas nestas duas caixas. Vamos fazer isso no próximo
exercício de programação. Veja se pode alterar nosso código para fazer ajustes.
我们来使用另一种可视化来帮助我们观察变量的分布
叫做箱线图
如果你不熟悉箱线图 可在讲师注释中查找资源
那儿也有优达学城统计课程的链接
你可以测试一下自己的知识
你可能记起以前我们按性别划分好友数
使用琢面包裹创建成对直方图 代码就像这样
我们不用这些直方图 而是按性别生成好友数箱线图
这样可以快速看到分布之间的差异
特别是我们将要看到两个组中位数之间的差异
还要记住
当我们传递单个变量时 qplot 函数会自动生成直方图 (/g)
所以我们需要添加一个参数
告诉 qplot 我们需要不同类型的图形
做法是使用叫做箱线图的 geom
现在我要使用与以前相同的数据集
所以我们要保留这个和 qplot
箱线图的差别是 y 轴将为好友数
另一方面 x 轴将是
我们的类别变量男性和女性 或者性别
注意我们使用连续变量 好友数为 y
分组或者类别变量为 x
对于箱线图将始终是这样的
这里我忘掉一个括号 我来重新调整代码格式
让它看起来整洁一些 就这样了
运行此代码 可以看到我们获得两个箱线图
我们放大来仔细观察 此处和此处的箱体
涵盖了值的中间 50% 或者称为内四分位范围
我知道这些箱体很难观察
因为我们的这幅图中有很多异常值
所有这些小点点都是我们数据中的异常值
我们还可以看到 y 轴捕获全部好友数
从 0 一直到 5000
所以我们在图中没有遗漏任何用户数据
最后 这条水平线 你可能开始时并没有注意到
是两个箱线图的中位数 你可能在怀疑
异常值怎么就实际成了异常值 好的
通常我们认为异常值是
位于中位数 IQR 的 1.5倍以外
所以 这些图中有很多异常值 我们来调整代码
仅关注这两个箱体 我们在下一个编程练习中要让你来做这个工作
看看你是否可以修改代码来进行调整