I am working on LULC classification of sentinel-2 image(4-bands) using Machine Learning algorithms. I split the whole image into 64*64 patches and assigned class label (builtup, barren land, water and vegetation) to selected patches. For each class patch spectral features (mean, variance values of each band, mean normalized difference vegetation index(NDVI) for each class patch, texture features (grey-level co-occurrence matrix (GLCM) contrast, homogeneity, dissimilarity and correlation for NIR band of each class patch were calculated. I split the features into training and testing dataset and trained random forest classifier on training dataset. The problem is I don't know how to classify the whole image using trained classifier and visualize it as a classified image. '''

import numpy as np 
import pandas as pd 
from sklearn.metrics import accuracy_score
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score
from sklearn.metrics import confusion_matrix
train = pd.read_excel(r'D:\band_composite\traning_data\training.xls')#import traing dataset
test=pd.read_excel(r"D:\band_composite\test_data\test.xls")#import testing daatset
# (Xtrain,Ytrain for training dataset)
X_train = train.drop(['class'], axis=1)
y_train = pd.DataFrame(train['class'].values)
X_test = test.drop(['class'], axis=1)
y_test = test['class']
# Random forest model training
clf = RandomForestClassifier(max_depth=2, random_state=0)
model=clf.fit(X_train, y_train)


# X_train shape
    (141, 15)
# y_train.shape
    (141, 1)

#X_training dataset excel image
  [ist five rows of X_train dataset][1]

  [1]: https://i.stack.imgur.com/uYjTy.png

I think this may help you (https://github.com/florianbeyer/RandomForest-Classification/blob/master/Classification_script.ipynb)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.