text_plain_output_1.png
from sklearn.metrics import mean_squared_error

from sklearn.tree import DecisionTreeRegressor

import numpy as np

import random

import random
import numpy as np
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
def perform_operation(a, b, op):
    if op == 0:
        return a + b
    elif op == 1:
        return a - b
    elif op == 2:
        return a * b
    elif op == 3:
        return a / b if b != 0 else 0
train_x = []
train_y = []
for i in range(50000000):
    a = random.randint(0, 10000)
    b = random.randint(0, 10000)
    op = random.randint(0, 3)
    result = perform_operation(a, b, op)
    train_x.append([a, b, op])
    train_y.append(result)
train_x = np.array(train_x)
train_y = np.array(train_y)
model = DecisionTreeRegressor()
model.fit(train_x, train_y)
test_x = np.array([[5, 10, 0], [15, 20, 1], [30, 40, 2], [50, 60, 3]])
predictions = model.predict(test_x)
print(predictions)
mse = mean_squared_error(train_y, model.predict(train_x))
print('Mean squared error: ', mse)