Создание REM с использованием модели регрессии [закрыто]Python

Программы на Python
Anonymous
Создание REM с использованием модели регрессии [закрыто]

Сообщение Anonymous »

Для лучшего понимания откройте изображения.
Было собрано два набора данных: один из Hovermap («522_502_map_Final.csv»), а другой — из Turtlebot3 («merged_data_7_29.csv»).
/>Я хочу, чтобы значение прогноза было только внутри области, собранной с помощью hovermap («522_502_map_Final.csv»). Я хочу сделать REM, используя Python. Раньше у меня был небольшой опыт создания РЭМ, но меня рассматривали только одну комнату. Но сейчас я рассматриваю и коридор своей лаборатории. Я собирал данные через Turtlebot3. Мне удалось сделать REM, используя только одну комнату, но сейчас я не могу этого сделать. Нужна помощь.
Прикрепляю код, над которым работаю.

Код: Выделить всё

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Load the data
df2 = pd.read_csv("522_502_map_Final.csv")

x0, x1 = df2["//X"].min()-0.005 , df2["//X"].max()+0.005 #Longitude x0, x1 = features[:, 0].min()-0.00005 , features[:, 0].max()+0.00005 #Longitude
y0, y1 = df2["Y"].min()+0.005 , df2["Y"].max()+0.005 #LAtitude #y0, y1 = df2["Y"].min()-0.00005 , df2["Y"].max()+0.00005 #LAtitude

plt.scatter(df2["//X"], df2["Y"] ,alpha=0.002)
#plt.savefig('Troom-515.png', dpi=400, bbox_inches='tight')

import numpy as np
import csv
from matplotlib import pylab as pl
import matplotlib.pyplot as plt
from sklearn.ensemble import ExtraTreesRegressor, BaggingRegressor, RandomForestRegressor, AdaBoostRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.svm import SVR
import timeit
# Reading the training data
file_path = 'merged_data_7_29.csv'
data_initial_orig = []

with open(file_path, "r") as file:
reader = csv.reader(file, delimiter=",")
header = next(reader)  # Skip header
for row in reader:
if len(row) == 4:  # Ensure the row has exactly 4 columns
data_initial_orig.append(row)
else:
print(f"Skipping row with incorrect format: {row}")

# Convert to numpy array
try:
data_initial_orig = np.array(data_initial_orig).astype("float")
except ValueError as e:
print(f"Error converting data to float: {e}")

data_initial = data_initial_orig

n_seed = 1
np.random.seed(n_seed)  # Seed for generating random numbers
np.random.shuffle(data_initial)

labels = data_initial[:, 3]
x_train = data_initial[:, 0]
y_train = data_initial[:, 1]
features = data_initial[:, 0:2]

data_train = data_initial

# Define the grid limits
x0, x1 = features[:, 0].min() * 0.95, features[:, 0].max() * 1.05
y0, y1 = features[:, 1].min() * 0.9, features[:, 1].max() * 1.1

interval = 100  # How many internal points does the mesh have on each axis?
X = np.linspace(x0, x1, interval)
Y = np.linspace(y0, y1, interval)
X, Y = np.meshgrid(X, Y)

X_F = np.array([])
for i in range(interval):
X_F = np.append(X_F, X[1, :])

# Normalize - It only affects predicting the field value.

features_N = features.copy()
features_N -= features.mean(0)
features_N /= features.std(0)
#Grid
features_test=np.vstack([X.ravel(), Y.ravel()]).T
features_test_N = features_test.copy()
features_test_N -= features.mean(0)
features_test_N /= features.std(0)

`n_seed=1

regressor = ExtraTreesRegressor(n_estimators=160, min_samples_leaf = 1, max_depth =50)

regressor.fit(features_N, labels)

predicted = regressor.predict(features_test_N)
cm = plt.cm.get_cmap('jet')
plt.figure(figsize=(8,15))
plt.scatter(df2["Y"], df2["//X"], s=0.00006,alpha=1)
plt.scatter(y_train, x_train, s=20, c=labels, cmap=cm, alpha=0.1)
plt.scatter(Y.ravel(), X.ravel(), s=100, c=predicted,cmap=cm,alpha=0.1)
plt.clim(min(predicted), max(predicted))
plt.colorbar().solids.set(alpha=0.8)
Это путь робота из одной комнаты в другую.
Это REM с использованием дополнительного регрессора дерева.
Это карта, которую я создал ранее. п>

Подробнее здесь: https://stackoverflow.com/questions/788 ... sion-model

Вернуться в «Python»