공지사항 :
2025년 4월 15일 전에 Earth Engine 사용을 위해 등록된 모든 비상업용 프로젝트는 액세스 권한을 유지하기 위해
비상업용 자격 요건을 인증 해야 합니다. 2025년 9월 26일까지 인증하지 않으면 액세스가 보류될 수 있습니다.
의견 보내기
ee.Classifier.smileKNN
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
빈 k-NN 분류기를 만듭니다.
k-최근접 이웃 알고리즘 (k-NN)은 이웃의 다수결로 객체를 분류하는 방법으로, 객체는 k-최근접 이웃 중 가장 일반적인 클래스에 할당됩니다 (k는 양의 정수이며 일반적으로 작고 일반적으로 홀수임).
사용 반환 값 ee.Classifier.smileKNN(k , searchMethod , metric )
분류기
인수 유형 세부정보 k
정수, 기본값: 1 분류를 위한 이웃 수입니다. searchMethod
문자열, 기본값: 'AUTO' 검색 방법입니다. 유효한 값은 [AUTO, LINEAR_SEARCH, KD_TREE, COVER_TREE]입니다.
AUTO는 차원 수에 따라 KD_TREE와 COVER_TREE 중에서 선택합니다. 거리 동점 및 확률 값의 경우 검색 방법에 따라 결과가 다를 수 있습니다. 성능과 결과는 다를 수 있으므로 SMILE 문서 및 기타 문헌을 참고하세요. metric
문자열, 기본값: 'EUCLIDEAN' 사용할 거리 측정항목입니다. 참고: KD_TREE (및 낮은 차원의 경우 AUTO)는 선택한 측정항목을 사용하지 않습니다. 옵션은 다음과 같습니다.
'EUCLIDEAN' - 유클리드 거리입니다.
'MAHALANOBIS' - Mahalanobis 거리입니다.
'MANHATTAN' - 맨해튼 거리입니다.
'BRAYCURTIS' - Bray-Curtis 거리입니다.
예
코드 편집기 (JavaScript)
// Cloud masking for Landsat 8.
function maskL8sr ( image ) {
var qaMask = image . select ( 'QA_PIXEL' ). bitwiseAnd ( parseInt ( '11111' , 2 )). eq ( 0 );
var saturationMask = image . select ( 'QA_RADSAT' ). eq ( 0 );
// Apply the scaling factors to the appropriate bands.
var opticalBands = image . select ( 'SR_B.' ). multiply ( 0.0000275 ). add ( - 0.2 );
var thermalBands = image . select ( 'ST_B.*' ). multiply ( 0.00341802 ). add ( 149.0 );
// Replace the original bands with the scaled ones and apply the masks.
return image . addBands ( opticalBands , null , true )
. addBands ( thermalBands , null , true )
. updateMask ( qaMask )
. updateMask ( saturationMask );
}
// Map the function over one year of data.
var collection = ee . ImageCollection ( 'LANDSAT/LC08/C02/T1_L2' )
. filterDate ( '2020-01-01' , '2021-01-01' )
. map ( maskL8sr );
// Make a median composite.
var composite = collection . median ();
// Demonstration labels.
var labels = ee . FeatureCollection ( 'projects/google/demo_landcover_labels' )
// Use these bands for classification.
var bands = [ 'SR_B2' , 'SR_B3' , 'SR_B4' , 'SR_B5' , 'SR_B6' , 'SR_B7' ];
// The name of the property on the points storing the class label.
var classProperty = 'landcover' ;
// Sample the composite to generate training data. Note that the
// class label is stored in the 'landcover' property.
var training = composite . select ( bands ). sampleRegions (
{ collection : labels , properties : [ classProperty ], scale : 30 });
// Train a kNN classifier.
var classifier = ee . Classifier . smileKNN ( 5 ). train ({
features : training ,
classProperty : classProperty ,
});
// Classify the composite.
var classified = composite . classify ( classifier );
Map . setCenter ( - 122.184 , 37.796 , 12 );
Map . addLayer ( classified , { min : 0 , max : 2 , palette : [ 'red' , 'green' , 'blue' ]});
Python 설정
Python API 및 geemap
를 사용한 대화형 개발에 관한 자세한 내용은
Python 환경 페이지를 참고하세요.
import ee
import geemap.core as geemap
Colab (Python)
# Cloud masking for Landsat 8.
def mask_l8_sr ( image ):
qa_mask = image . select ( 'QA_PIXEL' ) . bitwiseAnd ( int ( '11111' , 2 )) . eq ( 0 )
saturation_mask = image . select ( 'QA_RADSAT' ) . eq ( 0 )
# Apply the scaling factors to the appropriate bands.
optical_bands = image . select ( 'SR_B.' ) . multiply ( 0.0000275 ) . add ( - 0.2 )
thermal_bands = image . select ( 'ST_B.*' ) . multiply ( 0.00341802 ) . add ( 149.0 )
# Replace the original bands with the scaled ones and apply the masks.
return (
image . addBands ( optical_bands , None , True )
. addBands ( thermal_bands , None , True )
. updateMask ( qa_mask )
. updateMask ( saturation_mask )
)
# Map the function over one year of data.
collection = (
ee . ImageCollection ( 'LANDSAT/LC08/C02/T1_L2' )
. filterDate ( '2020-01-01' , '2021-01-01' )
. map ( mask_l8_sr )
)
# Make a median composite.
composite = collection . median ()
# Demonstration labels.
labels = ee . FeatureCollection ( 'projects/google/demo_landcover_labels' )
# Use these bands for classification.
bands = [ 'SR_B2' , 'SR_B3' , 'SR_B4' , 'SR_B5' , 'SR_B6' , 'SR_B7' ]
# The name of the property on the points storing the class label.
class_property = 'landcover'
# Sample the composite to generate training data. Note that the
# class label is stored in the 'landcover' property.
training = composite . select ( bands ) . sampleRegions (
collection = labels , properties = [ class_property ], scale = 30
)
# Train a kNN classifier.
classifier = ee . Classifier . smileKNN ( 5 ) . train (
features = training , classProperty = class_property
)
# Classify the composite.
classified = composite . classify ( classifier )
m = geemap . Map ()
m . set_center ( - 122.184 , 37.796 , 12 )
m . add_layer (
classified , { 'min' : 0 , 'max' : 2 , 'palette' : [ 'red' , 'green' , 'blue' ]}
)
m
의견 보내기
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스 에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스 에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책 을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
의견을 전달하고 싶나요?
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[]]