热线电话:13121318867

登录
2019-03-08 阅读量: 677
稚相关测试数据集

在我们演示秩相关方法之前,我们必须首先定义一个测试问题。这一次使用的是diamond数据集。下面是这个数据集的属性介绍

carat : ”Carat weight of the diamond

cutDescribe : cut quality of the diamond. Quality in increasing order Fair, Good, Very Good, Premium, Ideal

color :Color of the diamond, with D being the best and J the worst

clarity :How obvious inclusions are within the diamond:(in order from best to worst, FL = flawless, I3= level 3 inclusions) FL,IF, VVS1, VVS2, VS1, VS2, SI1, SI2, I1, I2, I3

depth :depth % :The height of a diamond, measured from the culet to the table, divided by its average girdle diameter

table :table%: The width of the diamond's table expressed as a percentage of its average diameter

price :the price of the diamond

x :length mm

y :width mm

z :depth mm

# -*- coding: utf-8 -*-

"""

Created on Tue Dec 25 20:44:45 2018

@author: czh

"""

%reset -f

%clear

# In[*]

from matplotlib import pyplot as plt

import numpy as np

import pandas as pd

import lifelines as ll

from IPython.display import HTML

%matplotlib inline

import matplotlib.pyplot as plt

import seaborn as sns

import plotly.plotly as py

import plotly.tools as tls

from plotly.graph_objs import *

import os

from scipy import stats

os.chdir("D:\\Rwork\\third\\Fig2")

# In[*]

data =pd.read_csv('https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/diamonds.csv',index_col=0)

cor_matrix = data.corr()

# In[*]

data.corr()

#可以直接给出数据框的相关系数矩阵

data.corr()['price']

#给出'price'变量与其他变量之间的相关系数

data['price'].corr(data["x"])

#计算'price'与"x"之间的相关系数

data.corr(method='pearson')

data.corr(method='pearson')['price']

data['price'].corr(method='pearson',data["x"])

method也可以指定spearman法和kendall法计算相关系数。

30.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子