반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

머신러닝.상관계수 구하기 본문

[AI]/python.sklearn

머신러닝.상관계수 구하기

givemebro 2020. 4. 16. 10:01
반응형
import numpy as np
import matplotlib.pyplot as plt

 

#data 준비
from sklearn.datasets import load_breast_cancer
cancer=load_breast_cancer()
col1=0
col2=3
X=cancer.data[:,col1]
y=cancer.data[:,col2]

 

corr=((X-X.mean())*(y-y.mean())).mean()/(X.std()*y.std())
# 0.9873571700566123


np.corrcoef(X.T,y)
# array([[1.        , 0.98735717],
       [0.98735717, 1.        ]])

 

 

 

 

 

from sklearn.linear_model import LinearRegression
X=cancer.data[:,[col1]]
y=cancer.data[:,col2]
model=LinearRegression()
model.fit(X,y)
X=cancer.data[:,col1]
plt.scatter(X,y,c=cancer.target)
xxx=[X.min()-.5,X.max()+.5]
yyy=model.coef_*xxx+model.intercept_
plt.plot(xxx,yyy,':r')
display(model.coef_,model.intercept_,corr)

# array([98.59821922])
# -738.036704195749
# 0.9873571700566123

반응형
Comments