admin管理员组

文章数量:1356873

I'm hoping to get some advice on approaching a clustering problem. I have two separate spatial datasets, being real data and modelled data. The real data contains a binary output (0,1), which is displayed in the figure below. The green scatter points represent 1 and red is 0.

Is it possible to assign a probability (of being 1 attributed to real data) to the modelled data based on the binary output of the real data? On face value, a nearest neighbour approach makes the most sense but are there any other approaches that may be applicable?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from itertools import cycle

real_data = pd.DataFrame(np.random.randint(0,100,size=(100, 2)), columns=['x1','y1'])
outcome = cycle([0,1])
real_data['Outcome'] = [next(outcome) for fruit in range(len(real_data))]
colors = np.where(real_data["Outcome"]==1,'green','red')

model_data = pd.DataFrame(np.random.randint(-25,125,size=(1000, 2)), columns=['x2','y2'])

fig, ax = plt.subplots()

ax.scatter(model_data['x2'], model_data['y2'], alpha=0.5, color = 'blue', zorder = -1)
ax.scatter(real_data['x1'], real_data['y1'], color = colors, s = 100, zorder = 0)

plt.show()

I'm hoping to get some advice on approaching a clustering problem. I have two separate spatial datasets, being real data and modelled data. The real data contains a binary output (0,1), which is displayed in the figure below. The green scatter points represent 1 and red is 0.

Is it possible to assign a probability (of being 1 attributed to real data) to the modelled data based on the binary output of the real data? On face value, a nearest neighbour approach makes the most sense but are there any other approaches that may be applicable?

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from itertools import cycle

real_data = pd.DataFrame(np.random.randint(0,100,size=(100, 2)), columns=['x1','y1'])
outcome = cycle([0,1])
real_data['Outcome'] = [next(outcome) for fruit in range(len(real_data))]
colors = np.where(real_data["Outcome"]==1,'green','red')

model_data = pd.DataFrame(np.random.randint(-25,125,size=(1000, 2)), columns=['x2','y2'])

fig, ax = plt.subplots()

ax.scatter(model_data['x2'], model_data['y2'], alpha=0.5, color = 'blue', zorder = -1)
ax.scatter(real_data['x1'], real_data['y1'], color = colors, s = 100, zorder = 0)

plt.show()

Share Improve this question edited Mar 28 at 4:36 Ken White 126k15 gold badges236 silver badges466 bronze badges asked Mar 28 at 3:48 jonboyjonboy 3925 gold badges18 silver badges56 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If your data isn't governed by an underlying law involving regularities (which seems to be the case in your example), Knn is indeed what makes the most sense, and linear methods (Gaussian modeling, regression, etc.) won't help you.

The best is to use nonlinear methods. You could try using a random forest method. Decision trees create a tree structure that delineates areas and identifies clusters. You just need to limit the number of parameters to avoid overfitting (like max depth or min samples per leaf), especially on ambiguous data like the one you've shown.

本文标签: pythonSpatial clustering with two separate datasetsStack Overflow