
數(shù)據(jù)分析之_散點(diǎn)圖_數(shù)據(jù)分析師
一:什么是散點(diǎn)圖 - What is a scatter plot
任何數(shù)據(jù)分析的第一步是圖形化曲線顯示數(shù)據(jù),根據(jù)相互關(guān)系,圖形曲線被稱(chēng)為散點(diǎn)圖。散點(diǎn)圖可以表示兩個(gè)變量之間真實(shí)的關(guān)系強(qiáng)度,關(guān)系的趨勢(shì),是否存在Outliers
二:散點(diǎn)圖的目的是什么
ü 觀察變量之間的關(guān)系,發(fā)現(xiàn)統(tǒng)計(jì)數(shù)據(jù)中是否存在問(wèn)題,或者特殊值和感興趣的數(shù)據(jù)
ü 數(shù)據(jù)是如何被離散化的
ü 通過(guò)眼睛觀察是否存在Outliers
三:示例說(shuō)明
一個(gè)人的肺活量和屏住呼吸時(shí)間的研究,一個(gè)人能屏住呼吸多久,一個(gè)研究者選擇一組人作為研究對(duì)象,測(cè)量每個(gè)人的肺活量作為第一個(gè)變量,屏住呼吸時(shí)間作為第二個(gè)變量,研究者將使用散點(diǎn)圖來(lái)描述數(shù)據(jù),假設(shè)肺活量作為水平軸,屏住呼吸時(shí)間做為垂直軸。
四:代碼實(shí)現(xiàn)
基于Java開(kāi)源的數(shù)據(jù)圖形顯示組件-JFreeChart已經(jīng)實(shí)現(xiàn)了離散圖,只要我們提供數(shù)據(jù)即可
基于上面描述的演示如下:
五:相關(guān)性系數(shù) correlation coefficient – R/r
Relationship Between X and Y Axis |
||
r = + 1.0 |
Strong - Positive |
As X goes up, Y always also goes up |
r = + 0.5 |
Weak - Positive |
As X goes up, Y tends to usually also go up |
r = 0 |
- No Correlation - |
X and Y are not correlated |
r = - 0.5 |
Weak - Negative |
As X goes up, Y tends to usually go down |
r = - 1.0 |
Strong - Negative |
As X goes up, Y always goes down |
本例中的r值為0.9814324978439516,顯然肺活量跟屏住呼吸時(shí)間長(zhǎng)短有很強(qiáng)的正相關(guān)性。
以下為源代碼:
package com.dataanalysis.plots; import java.awt.Color; import javax.swing.JPanel; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.xy.DefaultXYDataset; import org.jfree.data.xy.XYDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities; // - http://en.wikipedia.org/wiki/Scatter_plot public class ScatterPlotDemo extends ApplicationFrame { /** * */ private static final long serialVersionUID = 1L; private static double[][] data; /** * A demonstration application showing a scatter plot. * * @param title the frame title. */ public ScatterPlotDemo(String title) { super(title); JPanel chartPanel = createDemoPanel(); chartPanel.setPreferredSize(new java.awt.Dimension(600, 400)); setContentPane(chartPanel); } private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "lung capacity(ml)", "time holding breath(s)", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesOutlinePaint(0, Color.black); renderer.setUseOutlinePaint(true); // x axis NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); // Y axis NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); XYTextAnnotation textAnnotation = new XYTextAnnotation("R = " + calculateCoefficient(data), 370, 25); // r value textAnnotation.setPaint(Color.BLUE); textAnnotation.setToolTipText("Correlation Coefficient"); plot.addAnnotation(textAnnotation); return chart; } /** * Creates a panel for the demo (used by SuperDemo.java). * * @return A panel. */ public static JPanel createDemoPanel() { JFreeChart chart = createChart(createXYDataset()); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPopupMenu(null); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); return chartPanel; } public static XYDataset createXYDataset() { DefaultXYDataset xyDataset = new DefaultXYDataset(); data = new double[2][12]; // x axis data - lung capacity(ml) data[0] = new double[]{400,397,360,402,413,427,389,388,405,422,411,433}; // y axis data - time holding breath(s) data[1] = new double[]{21.7,20.7,17.7,21.9,23.7,25.7,20.4,20.1,22.9,24.8,22.5,25.9}; xyDataset.addSeries("Research Data", data); System.out.println("Correlation Coefficient = " + calculateCoefficient(data)); return xyDataset; } public static double calculateCoefficient(double[][] data) { DescriptiveStatistics xDataSet = new DescriptiveStatistics(); for(int i=0; i<data[0].length; i="" xdataset="" descriptivestatistics="" ydataset="new" descriptivestatistics="" for="" i="0;" i="" i="" ydataset="" double="" n="yDataSet.getValues().length;" double="" xysum="0.0d;" double="" xpowsum="0.0d;" double="" ypowsum="0.0d;" for="" i="0;" i="" i="" xysum="" xdataset="" ydataset="" xpowsum="" math="" ypowsum="" double="" s1="xySum" -="" ydataset="" double="" xs="xPowSum" -="" double="" ys="yPowSum" -="" double="" s2="Math.sqrt(xS" ys="" return="" s2="" starting="" point="" for="" the="" demonstration="" application="" args="" ignored="" public="" static="" void="" main="" args="" scatterplotdemo="" demo="new" scatterplotdemo="" plot="" demo="" demo="" refineryutilities="" demo=""> </data[0].length;>
數(shù)據(jù)分析咨詢(xún)請(qǐng)掃描二維碼
若不方便掃碼,搜微信號(hào):CDAshujufenxi
SQL Server 中 CONVERT 函數(shù)的日期轉(zhuǎn)換:從基礎(chǔ)用法到實(shí)戰(zhàn)優(yōu)化 在 SQL Server 的數(shù)據(jù)處理中,日期格式轉(zhuǎn)換是高頻需求 —— 無(wú)論 ...
2025-09-18MySQL 大表拆分與關(guān)聯(lián)查詢(xún)效率:打破 “拆分必慢” 的認(rèn)知誤區(qū) 在 MySQL 數(shù)據(jù)庫(kù)管理中,“大表” 始終是性能優(yōu)化繞不開(kāi)的話題。 ...
2025-09-18CDA 數(shù)據(jù)分析師:表結(jié)構(gòu)數(shù)據(jù) “獲取 - 加工 - 使用” 全流程的賦能者 表結(jié)構(gòu)數(shù)據(jù)(如數(shù)據(jù)庫(kù)表、Excel 表、CSV 文件)是企業(yè)數(shù)字 ...
2025-09-18DSGE 模型中的 Et:理性預(yù)期算子的內(nèi)涵、作用與應(yīng)用解析 動(dòng)態(tài)隨機(jī)一般均衡(Dynamic Stochastic General Equilibrium, DSGE)模 ...
2025-09-17Python 提取 TIF 中地名的完整指南 一、先明確:TIF 中的地名有哪兩種存在形式? 在開(kāi)始提取前,需先判斷 TIF 文件的類(lèi)型 —— ...
2025-09-17CDA 數(shù)據(jù)分析師:解鎖表結(jié)構(gòu)數(shù)據(jù)特征價(jià)值的專(zhuān)業(yè)核心 表結(jié)構(gòu)數(shù)據(jù)(以 “行 - 列” 規(guī)范存儲(chǔ)的結(jié)構(gòu)化數(shù)據(jù),如數(shù)據(jù)庫(kù)表、Excel 表、 ...
2025-09-17Excel 導(dǎo)入數(shù)據(jù)含缺失值?詳解 dropna 函數(shù)的功能與實(shí)戰(zhàn)應(yīng)用 在用 Python(如 pandas 庫(kù))處理 Excel 數(shù)據(jù)時(shí),“缺失值” 是高頻 ...
2025-09-16深入解析卡方檢驗(yàn)與 t 檢驗(yàn):差異、適用場(chǎng)景與實(shí)踐應(yīng)用 在數(shù)據(jù)分析與統(tǒng)計(jì)學(xué)領(lǐng)域,假設(shè)檢驗(yàn)是驗(yàn)證研究假設(shè)、判斷數(shù)據(jù)差異是否 “ ...
2025-09-16CDA 數(shù)據(jù)分析師:掌控表格結(jié)構(gòu)數(shù)據(jù)全功能周期的專(zhuān)業(yè)操盤(pán)手 表格結(jié)構(gòu)數(shù)據(jù)(以 “行 - 列” 存儲(chǔ)的結(jié)構(gòu)化數(shù)據(jù),如 Excel 表、數(shù)據(jù) ...
2025-09-16MySQL 執(zhí)行計(jì)劃中 rows 數(shù)量的準(zhǔn)確性解析:原理、影響因素與優(yōu)化 在 MySQL SQL 調(diào)優(yōu)中,EXPLAIN執(zhí)行計(jì)劃是核心工具,而其中的row ...
2025-09-15解析 Python 中 Response 對(duì)象的 text 與 content:區(qū)別、場(chǎng)景與實(shí)踐指南 在 Python 進(jìn)行 HTTP 網(wǎng)絡(luò)請(qǐng)求開(kāi)發(fā)時(shí)(如使用requests ...
2025-09-15CDA 數(shù)據(jù)分析師:激活表格結(jié)構(gòu)數(shù)據(jù)價(jià)值的核心操盤(pán)手 表格結(jié)構(gòu)數(shù)據(jù)(如 Excel 表格、數(shù)據(jù)庫(kù)表)是企業(yè)最基礎(chǔ)、最核心的數(shù)據(jù)形態(tài) ...
2025-09-15Python HTTP 請(qǐng)求工具對(duì)比:urllib.request 與 requests 的核心差異與選擇指南 在 Python 處理 HTTP 請(qǐng)求(如接口調(diào)用、數(shù)據(jù)爬取 ...
2025-09-12解決 pd.read_csv 讀取長(zhǎng)浮點(diǎn)數(shù)據(jù)的科學(xué)計(jì)數(shù)法問(wèn)題 為幫助 Python 數(shù)據(jù)從業(yè)者解決pd.read_csv讀取長(zhǎng)浮點(diǎn)數(shù)據(jù)時(shí)的科學(xué)計(jì)數(shù)法問(wèn)題 ...
2025-09-12CDA 數(shù)據(jù)分析師:業(yè)務(wù)數(shù)據(jù)分析步驟的落地者與價(jià)值優(yōu)化者 業(yè)務(wù)數(shù)據(jù)分析是企業(yè)解決日常運(yùn)營(yíng)問(wèn)題、提升執(zhí)行效率的核心手段,其價(jià)值 ...
2025-09-12用 SQL 驗(yàn)證業(yè)務(wù)邏輯:從規(guī)則拆解到數(shù)據(jù)把關(guān)的實(shí)戰(zhàn)指南 在業(yè)務(wù)系統(tǒng)落地過(guò)程中,“業(yè)務(wù)邏輯” 是連接 “需求設(shè)計(jì)” 與 “用戶(hù)體驗(yàn) ...
2025-09-11塔吉特百貨孕婦營(yíng)銷(xiāo)案例:數(shù)據(jù)驅(qū)動(dòng)下的精準(zhǔn)零售革命與啟示 在零售行業(yè) “流量紅利見(jiàn)頂” 的當(dāng)下,精準(zhǔn)營(yíng)銷(xiāo)成為企業(yè)突圍的核心方 ...
2025-09-11CDA 數(shù)據(jù)分析師與戰(zhàn)略 / 業(yè)務(wù)數(shù)據(jù)分析:概念辨析與協(xié)同價(jià)值 在數(shù)據(jù)驅(qū)動(dòng)決策的體系中,“戰(zhàn)略數(shù)據(jù)分析”“業(yè)務(wù)數(shù)據(jù)分析” 是企業(yè) ...
2025-09-11Excel 數(shù)據(jù)聚類(lèi)分析:從操作實(shí)踐到業(yè)務(wù)價(jià)值挖掘 在數(shù)據(jù)分析場(chǎng)景中,聚類(lèi)分析作為 “無(wú)監(jiān)督分組” 的核心工具,能從雜亂數(shù)據(jù)中挖 ...
2025-09-10統(tǒng)計(jì)模型的核心目的:從數(shù)據(jù)解讀到?jīng)Q策支撐的價(jià)值導(dǎo)向 統(tǒng)計(jì)模型作為數(shù)據(jù)分析的核心工具,并非簡(jiǎn)單的 “公式堆砌”,而是圍繞特定 ...
2025-09-10