রিডুসার ব্যবহার করে রৈখিক রিগ্রেশন সঞ্চালনের জন্য আর্থ ইঞ্জিনের বিভিন্ন পদ্ধতি রয়েছে:
-
ee.Reducer.linearFit()
-
ee.Reducer.linearRegression()
-
ee.Reducer.robustLinearRegression()
-
ee.Reducer.ridgeRegression()
সহজ রৈখিক রিগ্রেশন রিডুসার হল linearFit()
যা একটি ধ্রুবক পদের সাথে একটি ভেরিয়েবলের একটি রৈখিক ফাংশনের সর্বনিম্ন বর্গক্ষেত্রের অনুমান গণনা করে। রৈখিক মডেলিংয়ের জন্য আরও নমনীয় পদ্ধতির জন্য, রৈখিক রিগ্রেশন রিডিউসারগুলির একটি ব্যবহার করুন যা পরিবর্তনশীল সংখ্যার স্বাধীন এবং নির্ভরশীল ভেরিয়েবলের জন্য অনুমতি দেয়। linearRegression()
সাধারণ সর্বনিম্ন স্কোয়ার রিগ্রেশন (OLS) প্রয়োগ করে। robustLinearRegression()
ডেটাতে পুনরাবৃত্তভাবে ডি-ওয়েট আউটলারের জন্য রিগ্রেশন রেসিডুয়ালের উপর ভিত্তি করে একটি খরচ ফাংশন ব্যবহার করে ( O'Leary, 1990 )। ridgeRegression()
L2 নিয়মিতকরণের সাথে লিনিয়ার রিগ্রেশন করে।
এই পদ্ধতিগুলির সাথে রিগ্রেশন বিশ্লেষণ ee.ImageCollection
, ee.Image
, ee.FeatureCollection
, এবং ee.List
অবজেক্টগুলি হ্রাস করার জন্য উপযুক্ত৷ নিম্নলিখিত উদাহরণ প্রতিটি জন্য একটি আবেদন প্রদর্শন. উল্লেখ্য যে linearRegression()
, robustLinearRegression()
, এবং ridgeRegression()
সকলেরই একই ইনপুট এবং আউটপুট কাঠামো রয়েছে, তবে linearFit()
একটি দ্বি-ব্যান্ড ইনপুট আশা করে (X এর পরে Y) এবং ridgeRegression()
একটি অতিরিক্ত প্যারামিটার ( lambda
, ঐচ্ছিক ) এবং আউটপুট ( pValue
) আছে।
ইই। ইমেজ কালেকশন
linearFit()
ডেটা দুটি-ব্যান্ড ইনপুট চিত্র হিসাবে সেট আপ করা উচিত, যেখানে প্রথম ব্যান্ডটি স্বাধীন পরিবর্তনশীল এবং দ্বিতীয় ব্যান্ডটি নির্ভরশীল পরিবর্তনশীল। নিম্নলিখিত উদাহরণটি জলবায়ু মডেল দ্বারা অনুমান করা ভবিষ্যত বৃষ্টিপাতের রৈখিক প্রবণতা ( NEX-DCP30 ডেটাতে 2006-এর পরে) অনুমান দেখায়। নির্ভরশীল ভেরিয়েবলটি অনুমানকৃত বৃষ্টিপাত এবং স্বাধীন পরিবর্তনশীল হল সময়, linearFit()
কল করার আগে যোগ করা হয় :
কোড এডিটর (জাভাস্ক্রিপ্ট)
// This function adds a time band to the image. var createTimeBand = function(image) { // Scale milliseconds by a large constant to avoid very small slopes // in the linear regression output. return image.addBands(image.metadata('system:time_start').divide(1e18)); }; // Load the input image collection: projected climate data. var collection = ee.ImageCollection('NASA/NEX-DCP30_ENSEMBLE_STATS') .filter(ee.Filter.eq('scenario', 'rcp85')) .filterDate(ee.Date('2006-01-01'), ee.Date('2050-01-01')) // Map the time band function over the collection. .map(createTimeBand); // Reduce the collection with the linear fit reducer. // Independent variable are followed by dependent variables. var linearFit = collection.select(['system:time_start', 'pr_mean']) .reduce(ee.Reducer.linearFit()); // Display the results. Map.setCenter(-100.11, 40.38, 5); Map.addLayer(linearFit, {min: 0, max: [-0.9, 8e-5, 1], bands: ['scale', 'offset', 'scale']}, 'fit');
লক্ষ্য করুন যে আউটপুটে দুটি ব্যান্ড রয়েছে, 'অফসেট' (ইন্টারসেপ্ট) এবং 'স্কেল' (এই প্রসঙ্গে 'স্কেল' লাইনের ঢালকে বোঝায় এবং অনেক রিডিউসারে স্কেল প্যারামিটার ইনপুট দিয়ে বিভ্রান্ত করা যাবে না, যা স্থানিক স্কেল)। ফলস্বরূপ, নীল রঙে ক্রমবর্ধমান প্রবণতা, লাল রঙে হ্রাস প্রবণতা এবং সবুজ রঙে কোন প্রবণতা চিত্র 1 এর মতো দেখতে হবে।
চিত্র 1. linearFit()
এর আউটপুট অনুমানকৃত বৃষ্টিপাতের জন্য প্রয়োগ করা হয়েছে। বর্ধিত বৃষ্টিপাতের অনুমান করা অঞ্চলগুলি নীল রঙে এবং হ্রাসকৃত বৃষ্টিপাত লাল রঙে দেখানো হয়েছে।
linearRegression()
উদাহরণস্বরূপ, ধরুন দুটি নির্ভরশীল চলক রয়েছে: বৃষ্টিপাত এবং সর্বোচ্চ তাপমাত্রা এবং দুটি স্বাধীন চলক: একটি ধ্রুবক এবং সময়। সংগ্রহটি পূর্ববর্তী উদাহরণের সাথে অভিন্ন, তবে ধ্রুবক ব্যান্ডটি হ্রাস করার আগে ম্যানুয়ালি যোগ করতে হবে। ইনপুটের প্রথম দুটি ব্যান্ড হল 'X' (স্বাধীন) ভেরিয়েবল এবং পরের দুটি ব্যান্ড হল 'Y' (নির্ভরশীল) ভেরিয়েবল। এই উদাহরণে, প্রথমে রিগ্রেশন সহগগুলি পান, তারপর আগ্রহের ব্যান্ডগুলি বের করতে অ্যারে চিত্রটিকে সমতল করুন:
কোড এডিটর (জাভাস্ক্রিপ্ট)
// This function adds a time band to the image. var createTimeBand = function(image) { // Scale milliseconds by a large constant. return image.addBands(image.metadata('system:time_start').divide(1e18)); }; // This function adds a constant band to the image. var createConstantBand = function(image) { return ee.Image(1).addBands(image); }; // Load the input image collection: projected climate data. var collection = ee.ImageCollection('NASA/NEX-DCP30_ENSEMBLE_STATS') .filterDate(ee.Date('2006-01-01'), ee.Date('2099-01-01')) .filter(ee.Filter.eq('scenario', 'rcp85')) // Map the functions over the collection, to get constant and time bands. .map(createTimeBand) .map(createConstantBand) // Select the predictors and the responses. .select(['constant', 'system:time_start', 'pr_mean', 'tasmax_mean']); // Compute ordinary least squares regression coefficients. var linearRegression = collection.reduce( ee.Reducer.linearRegression({ numX: 2, numY: 2 })); // Compute robust linear regression coefficients. var robustLinearRegression = collection.reduce( ee.Reducer.robustLinearRegression({ numX: 2, numY: 2 })); // The results are array images that must be flattened for display. // These lists label the information along each axis of the arrays. var bandNames = [['constant', 'time'], // 0-axis variation. ['precip', 'temp']]; // 1-axis variation. // Flatten the array images to get multi-band images according to the labels. var lrImage = linearRegression.select(['coefficients']).arrayFlatten(bandNames); var rlrImage = robustLinearRegression.select(['coefficients']).arrayFlatten(bandNames); // Display the OLS results. Map.setCenter(-100.11, 40.38, 5); Map.addLayer(lrImage, {min: 0, max: [-0.9, 8e-5, 1], bands: ['time_precip', 'constant_precip', 'time_precip']}, 'OLS'); // Compare the results at a specific point: print('OLS estimates:', lrImage.reduceRegion({ reducer: ee.Reducer.first(), geometry: ee.Geometry.Point([-96.0, 41.0]), scale: 1000 })); print('Robust estimates:', rlrImage.reduceRegion({ reducer: ee.Reducer.first(), geometry: ee.Geometry.Point([-96.0, 41.0]), scale: 1000 }));
linearRegression()
আউটপুট linearFit()
রিডুসার দ্বারা অনুমান করা সহগগুলির সমতুল্য, যদিও linearRegression()
আউটপুটে অন্যান্য নির্ভরশীল ভেরিয়েবল, tasmax_mean
জন্যও সহগ রয়েছে তা আবিষ্কার করতে ফলাফলগুলি পরিদর্শন করুন। দৃঢ় রৈখিক রিগ্রেশন সহগগুলি OLS অনুমান থেকে আলাদা। উদাহরণ একটি নির্দিষ্ট বিন্দুতে বিভিন্ন রিগ্রেশন পদ্ধতি থেকে সহগ তুলনা করে।
ইই।ইমেজ
একটি ee.Image
অবজেক্টের পরিপ্রেক্ষিতে, রিগ্রেশন রিডিউসারগুলি reduceRegion
বা reduceRegions
সাথে ব্যবহার করা যেতে পারে যাতে অঞ্চল(গুলি) পিক্সেলে লিনিয়ার রিগ্রেশন করা যায়। নিম্নলিখিত উদাহরণগুলি দেখায় যে কীভাবে একটি নির্বিচারে বহুভুজে ল্যান্ডস্যাট ব্যান্ডগুলির মধ্যে রিগ্রেশন সহগ গণনা করা যায়।
linearFit()
অ্যারে ডেটা চার্ট বর্ণনাকারী গাইড বিভাগটি Landsat 8 SWIR1 এবং SWIR2 ব্যান্ডের মধ্যে পারস্পরিক সম্পর্কের একটি স্ক্যাটার প্লট দেখায়। এখানে, এই সম্পর্কের জন্য রৈখিক রিগ্রেশন সহগ গণনা করা হয়। 'offset'
(y-ইন্টারসেপ্ট) এবং 'scale'
(ঢাল) বৈশিষ্ট্য সম্বলিত একটি অভিধান ফিরিয়ে দেওয়া হয়েছে।
কোড এডিটর (জাভাস্ক্রিপ্ট)
// Define a rectangle geometry around San Francisco. var sanFrancisco = ee.Geometry.Rectangle([-122.45, 37.74, -122.4, 37.8]); // Import a Landsat 8 TOA image for this region. var img = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318'); // Subset the SWIR1 and SWIR2 bands. In the regression reducer, independent // variables come first followed by the dependent variables. In this case, // B5 (SWIR1) is the independent variable and B6 (SWIR2) is the dependent // variable. var imgRegress = img.select(['B5', 'B6']); // Calculate regression coefficients for the set of pixels intersecting the // above defined region using reduceRegion with ee.Reducer.linearFit(). var linearFit = imgRegress.reduceRegion({ reducer: ee.Reducer.linearFit(), geometry: sanFrancisco, scale: 30, }); // Inspect the results. print('OLS estimates:', linearFit); print('y-intercept:', linearFit.get('offset')); print('Slope:', linearFit.get('scale'));
linearRegression()
পূর্ববর্তী linearFit
বিভাগের একই বিশ্লেষণ এখানে প্রয়োগ করা হয়েছে, এই সময় ee.Reducer.linearRegression
ফাংশনটি ব্যবহার করা ছাড়া। মনে রাখবেন যে একটি রিগ্রেশন ইমেজ তিনটি আলাদা ইমেজ থেকে তৈরি করা হয়েছে: একটি ধ্রুবক ইমেজ এবং একই ল্যান্ডস্যাট 8 ইমেজ থেকে SWIR1 এবং SWIR2 ব্যান্ডের প্রতিনিধিত্ব করে। মনে রাখবেন যে আপনি ee.Reducer.linearRegression
দ্বারা অঞ্চল হ্রাসের জন্য একটি ইনপুট চিত্র তৈরি করতে ব্যান্ডগুলির যে কোনও সেটকে একত্রিত করতে পারেন, তাদের একই উত্স চিত্রের অন্তর্গত হতে হবে না।
কোড এডিটর (জাভাস্ক্রিপ্ট)
// Define a rectangle geometry around San Francisco. var sanFrancisco = ee.Geometry.Rectangle([-122.45, 37.74, -122.4, 37.8]); // Import a Landsat 8 TOA image for this region. var img = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044034_20140318'); // Create a new image that is the concatenation of three images: a constant, // the SWIR1 band, and the SWIR2 band. var constant = ee.Image(1); var xVar = img.select('B5'); var yVar = img.select('B6'); var imgRegress = ee.Image.cat(constant, xVar, yVar); // Calculate regression coefficients for the set of pixels intersecting the // above defined region using reduceRegion. The numX parameter is set as 2 // because the constant and the SWIR1 bands are independent variables and they // are the first two bands in the stack; numY is set as 1 because there is only // one dependent variable (SWIR2) and it follows as band three in the stack. var linearRegression = imgRegress.reduceRegion({ reducer: ee.Reducer.linearRegression({ numX: 2, numY: 1 }), geometry: sanFrancisco, scale: 30, }); // Convert the coefficients array to a list. var coefList = ee.Array(linearRegression.get('coefficients')).toList(); // Extract the y-intercept and slope. var b0 = ee.List(coefList.get(0)).get(0); // y-intercept var b1 = ee.List(coefList.get(1)).get(0); // slope // Extract the residuals. var residuals = ee.Array(linearRegression.get('residuals')).toList().get(0); // Inspect the results. print('OLS estimates', linearRegression); print('y-intercept:', b0); print('Slope:', b1); print('Residuals:', residuals);
'coefficients'
এবং 'residuals'
বৈশিষ্ট্য সম্বলিত একটি অভিধান ফেরত দেওয়া হয়। 'coefficients'
বৈশিষ্ট্য হল মাত্রা সহ একটি অ্যারে (numX, numY); প্রতিটি কলাম সংশ্লিষ্ট নির্ভরশীল ভেরিয়েবলের সহগ ধারণ করে। এই ক্ষেত্রে, অ্যারের দুটি সারি এবং একটি কলাম রয়েছে; সারি এক, কলাম এক হল y-ইন্টারসেপ্ট এবং সারি দুই, কলাম এক হল ঢাল। 'residuals'
বৈশিষ্ট্য হল প্রতিটি নির্ভরশীল পরিবর্তনশীলের অবশিষ্টাংশের মূল গড় বর্গক্ষেত্রের ভেক্টর। ফলাফলটিকে একটি অ্যারে হিসাবে ঢালাই করে এবং তারপরে পছন্দসই উপাদানগুলিকে স্লাইস করে বা অ্যারেটিকে একটি তালিকায় রূপান্তর করে এবং সূচকের অবস্থান অনুসারে সহগ নির্বাচন করে সহগগুলি বের করুন।
ee. বৈশিষ্ট্য সংগ্রহ
ধরুন আপনি Sentinel-2 এবং Landsat 8 SWIR1 প্রতিফলনের মধ্যে রৈখিক সম্পর্ক জানতে চান। এই উদাহরণে, পয়েন্টের একটি বৈশিষ্ট্য সংগ্রহ হিসাবে বিন্যাসিত পিক্সেলের একটি র্যান্ডম নমুনা সম্পর্ক গণনা করতে ব্যবহৃত হয়। সর্বোত্তম ফিটের সর্বনিম্ন বর্গাকার লাইন সহ পিক্সেল জোড়াগুলির একটি স্ক্যাটার প্লট তৈরি করা হয়েছে (চিত্র 2)।
কোড এডিটর (জাভাস্ক্রিপ্ট)
// Import a Sentinel-2 TOA image. var s2ImgSwir1 = ee.Image('COPERNICUS/S2/20191022T185429_20191022T185427_T10SEH'); // Import a Landsat 8 TOA image from 12 days earlier than the S2 image. var l8ImgSwir1 = ee.Image('LANDSAT/LC08/C02/T1_TOA/LC08_044033_20191010'); // Get the intersection between the two images - the area of interest (aoi). var aoi = s2ImgSwir1.geometry().intersection(l8ImgSwir1.geometry()); // Get a set of 1000 random points from within the aoi. A feature collection // is returned. var sample = ee.FeatureCollection.randomPoints({ region: aoi, points: 1000 }); // Combine the SWIR1 bands from each image into a single image. var swir1Bands = s2ImgSwir1.select('B11') .addBands(l8ImgSwir1.select('B6')) .rename(['s2_swir1', 'l8_swir1']); // Sample the SWIR1 bands using the sample point feature collection. var imgSamp = swir1Bands.sampleRegions({ collection: sample, scale: 30 }) // Add a constant property to each feature to be used as an independent variable. .map(function(feature) { return feature.set('constant', 1); }); // Compute linear regression coefficients. numX is 2 because // there are two independent variables: 'constant' and 's2_swir1'. numY is 1 // because there is a single dependent variable: 'l8_swir1'. Cast the resulting // object to an ee.Dictionary for easy access to the properties. var linearRegression = ee.Dictionary(imgSamp.reduceColumns({ reducer: ee.Reducer.linearRegression({ numX: 2, numY: 1 }), selectors: ['constant', 's2_swir1', 'l8_swir1'] })); // Convert the coefficients array to a list. var coefList = ee.Array(linearRegression.get('coefficients')).toList(); // Extract the y-intercept and slope. var yInt = ee.List(coefList.get(0)).get(0); // y-intercept var slope = ee.List(coefList.get(1)).get(0); // slope // Gather the SWIR1 values from the point sample into a list of lists. var props = ee.List(['s2_swir1', 'l8_swir1']); var regressionVarsList = ee.List(imgSamp.reduceColumns({ reducer: ee.Reducer.toList().repeat(props.size()), selectors: props }).get('list')); // Convert regression x and y variable lists to an array - used later as input // to ui.Chart.array.values for generating a scatter plot. var x = ee.Array(ee.List(regressionVarsList.get(0))); var y1 = ee.Array(ee.List(regressionVarsList.get(1))); // Apply the line function defined by the slope and y-intercept of the // regression to the x variable list to create an array that will represent // the regression line in the scatter plot. var y2 = ee.Array(ee.List(regressionVarsList.get(0)).map(function(x) { var y = ee.Number(x).multiply(slope).add(yInt); return y; })); // Concatenate the y variables (Landsat 8 SWIR1 and predicted y) into an array // for input to ui.Chart.array.values for plotting a scatter plot. var yArr = ee.Array.cat([y1, y2], 1); // Make a scatter plot of the two SWIR1 bands for the point sample and include // the least squares line of best fit through the data. print(ui.Chart.array.values({ array: yArr, axis: 0, xLabels: x}) .setChartType('ScatterChart') .setOptions({ legend: {position: 'none'}, hAxis: {'title': 'Sentinel-2 SWIR1'}, vAxis: {'title': 'Landsat 8 SWIR1'}, series: { 0: { pointSize: 0.2, dataOpacity: 0.5, }, 1: { pointSize: 0, lineWidth: 2, } } }) );
চিত্র 2. সেন্টিনেল-2 এবং ল্যান্ডস্যাট 8 SWIR1 TOA প্রতিফলন প্রতিনিধিত্বকারী পিক্সেলের একটি নমুনার জন্য স্ক্যাটার প্লট এবং সর্বনিম্ন বর্গক্ষেত্রের রৈখিক রিগ্রেশন লাইন।
ee.তালিকা
2-D ee.List
অবজেক্টের কলাম রিগ্রেশন রিডিউসারের ইনপুট হতে পারে। নিম্নলিখিত উদাহরণগুলি সহজ প্রমাণ প্রদান করে; স্বাধীন ভেরিয়েবল হল নির্ভরশীল ভেরিয়েবলের একটি অনুলিপি যা 0 এর সমান y-ইন্টারসেপ্ট এবং 1 এর সমান ঢাল তৈরি করে।
linearFit()
কোড এডিটর (জাভাস্ক্রিপ্ট)
// Define a list of lists, where columns represent variables. The first column // is the independent variable and the second is the dependent variable. var listsVarColumns = ee.List([ [1, 1], [2, 2], [3, 3], [4, 4], [5, 5] ]); // Compute the least squares estimate of a linear function. Note that an // object is returned; cast it as an ee.Dictionary to make accessing the // coefficients easier. var linearFit = ee.Dictionary(listsVarColumns.reduce(ee.Reducer.linearFit())); // Inspect the result. print(linearFit); print('y-intercept:', linearFit.get('offset')); print('Slope:', linearFit.get('scale'));
তালিকাটি স্থানান্তর করুন যদি ভেরিয়েবলগুলিকে একটি ee.Array
তে রূপান্তর করে সারি দ্বারা প্রতিনিধিত্ব করা হয়, এটি স্থানান্তরিত করে, তারপরে একটি ee.List
এ রূপান্তর করে।
কোড এডিটর (জাভাস্ক্রিপ্ট)
// If variables in the list are arranged as rows, you'll need to transpose it. // Define a list of lists where rows represent variables. The first row is the // independent variable and the second is the dependent variable. var listsVarRows = ee.List([ [1, 2, 3, 4, 5], [1, 2, 3, 4, 5] ]); // Cast the ee.List as an ee.Array, transpose it, and cast back to ee.List. var listsVarColumns = ee.Array(listsVarRows).transpose().toList(); // Compute the least squares estimate of a linear function. Note that an // object is returned; cast it as an ee.Dictionary to make accessing the // coefficients easier. var linearFit = ee.Dictionary(listsVarColumns.reduce(ee.Reducer.linearFit())); // Inspect the result. print(linearFit); print('y-intercept:', linearFit.get('offset')); print('Slope:', linearFit.get('scale'));
linearRegression()
ee.Reducer.linearRegression()
এর প্রয়োগ উপরের linearFit() উদাহরণের অনুরূপ, একটি ধ্রুবক স্বাধীন পরিবর্তনশীল অন্তর্ভুক্ত করা ছাড়া।
কোড এডিটর (জাভাস্ক্রিপ্ট)
// Define a list of lists where columns represent variables. The first column // represents a constant term, the second an independent variable, and the third // a dependent variable. var listsVarColumns = ee.List([ [1, 1, 1], [1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 5, 5] ]); // Compute ordinary least squares regression coefficients. numX is 2 because // there is one constant term and an additional independent variable. numY is 1 // because there is only a single dependent variable. Cast the resulting // object to an ee.Dictionary for easy access to the properties. var linearRegression = ee.Dictionary( listsVarColumns.reduce(ee.Reducer.linearRegression({ numX: 2, numY: 1 }))); // Convert the coefficients array to a list. var coefList = ee.Array(linearRegression.get('coefficients')).toList(); // Extract the y-intercept and slope. var b0 = ee.List(coefList.get(0)).get(0); // y-intercept var b1 = ee.List(coefList.get(1)).get(0); // slope // Extract the residuals. var residuals = ee.Array(linearRegression.get('residuals')).toList().get(0); // Inspect the results. print('OLS estimates', linearRegression); print('y-intercept:', b0); print('Slope:', b1); print('Residuals:', residuals);