I have satellite image which contains 3 different bands. I'm using Python (jupyter notebook) in order to calculate new band by applying random forest regression. My problem is that after I have predict all the values for the new pixels, I don't know how to take it back to the original dataframe with the original bands in order to create in the end new image.
This is the process I did:
- open the 3 bands image with rasterio, the band has this shape: (3, 869, 1202)
dfwhen each row represents a pixel and each column is a band :
train the data and fit to random forest:
#split the data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) #import the algorithm rf=RandomForestRegressor() #reshape the y_train to fit the the model y_train=y_train.values.ravel() #fit the model rf.fit(X_train,y_train) rf_pred=rf.predict(X_test)
after checking the results, apply it to the full dataset and not only to training and set in order to predict the new band:
#create the data data=df.iloc[:,1:] pred_all=rf.predict(data) #reshape to one column: pred_all.reshape(1006560,1)
So after this, I don't know how to take this predicted values back to my table or to "link" it with the original pixel entities.
My end goal is to be able in the end to have this predicted values as new band so I can create image with the new predicted values.