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

bro's coding

sklearn.영향력 없는 column 찾기(knn) 본문

[AI]/python.sklearn

sklearn.영향력 없는 column 찾기(knn)

givemebro 2020. 4. 9. 16:01
반응형
# data 준비
X=iris.data
y=iris.target

# score 수집
scores=[]

for i in range(4):
    col=(np.array([1,2,3])+i)%4
    train_X,test_X,train_y,test_y=train_test_split(X[:,col],y)
    '''
	print(col)
    	[1 2 3]
	[2 3 0]
	[3 0 1]
	[0 1 2]
    '''
    
    # model 설정(k=5)
    model=KNeighborsClassifier(5)
    # model 훈련
    model.fit(train_X,train_y)
    # score 수집
    scores.append(model.score(test_X,test_y))
    
# 시각적 표현
plt.plot(scores)
plt.xticks([0,1,2,3])
plt.ylabel('score',rotation=70)
plt.xlabel('with out(x)')
    


# 정확도 올리기

X=iris.data
y=iris.target
scores=[]

for i in range(4):
    result=[]
    col=(np.array([1,2,3])+i)%4

    for j in range(1000):
        train_X,test_X,train_y,test_y=train_test_split(X[:,col],y)
        model=KNeighborsClassifier(5)
        model.fit(train_X,train_y)
        result.append(model.score(test_X,test_y))
    scores.append(np.array(result).mean())

plt.plot(scores)
plt.xticks([0,1,2,3])
plt.ylabel('score',rotation=70)
plt.xlabel('with out(x)')
    

반응형
Comments