import pandas as pd
import numpy as np
from gekko.ML import Gekko_NN_SKlearn, CustomMinMaxGekkoScaler
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPRegressor
from gekko import GEKKO
# Define inputs and output
X = ['Tco', 'Tci', 'Teo', 'Tei', 'Tcset', 'Tbuh', 'Twar', 'm_evap', 'm_cond', 'Qth_Total', 'CompOn']
Y = ['Pel']
# Splitting the data into training and testing sets
train, test = train_test_split(df, test_size=0.2, shuffle=True)
# Scaling the data using CustomMinMaxGekkoScaler
s = CustomMinMaxGekkoScaler(df, X, Y)
ds = s.scaledData()
mma = s.minMaxValues()
# Further splitting the scaled data into training and testing sets
trains, tests = train_test_split(ds, test_size=0.2, shuffle=True)
# Define the structure of the neural network
hl = [25, 15]
mlp = MLPRegressor(hidden_layer_sizes=hl, activation='relu',
solver='adam', batch_size=32,
learning_rate='adaptive', learning_rate_init=.0005,
tol=1e-6, n_iter_no_change=200,
max_iter=12000)
# Train the MLPRegressor model
mlp.fit(trains[X], np.ravel(trains[Y]))
# Evaluate the model on the test data
r2 = mlp.score(tests[X], np.ravel(tests[Y]))
# Print the R-squared score of the model
print('nnSK r2:', r2)
Во втором коде нет ошибки, поскольку я использую одну переменную, т.е. Tco
# Create a Gekko model
m = GEKKO()
# Define Tco as a decision variable
Tco = m.Var(value=(df['Tco'].min() + df['Tco'].max()) / 2, lb=df['Tco'].min(), ub=df['Tco'].max())
# Predict Pel using the trained neural network and Tco as input
predicted_Pel = Gekko_NN_SKlearn(mlp, mma, m).predict([Tco])
# Set the predicted Pel value as the objective to minimize
m.Minimize(predicted_Pel)
# Solve the optimization problem
m.solve(disp=False)
# Print the optimized Tco and corresponding predicted Pel value
print('Optimized Tco:', Tco.value[0])
print('Optimized Predicted Pel:', predicted_Pel.value[0])
print('Gekko Solvetime:', m.options.SOLVETIME, 's')
# Create a Gekko model
m = GEKKO()
# Define Tco as a decision variable
Tco = m.Var(value=(df['Tco'].min() + df['Tco'].max()) / 2, lb=df['Tco'].min(), ub=df['Tco'].max())
Tei = m.Var(value=(df['Tei'].min() + df['Tei'].max()) / 2, lb=df['Tei'].min(), ub=df['Tei'].max())
# Predict Pel using the trained neural network and Tco as input
predicted_Pel = Gekko_NN_SKlearn(mlp, mma, m).predict([Tco, Tei])
# Set the predicted Pel value as the objective to minimize
m.Minimize(predicted_Pel)
# Solve the optimization problem
m.solve(disp=False)
# Print the optimized Tco and corresponding predicted Pel value
print('Optimized Tco:', Tco.value[0])
print('Optimized Predicted Pel:', predicted_Pel.value[0])
print('Gekko Solvetime:', m.options.SOLVETIME, 's')
Появляется эта ошибка
Ошибка значения: операнды не могут быть переданы вместе с фигурами (11,) (2,)< /strong>
[list] [*]В первом коде нет ошибок [/list] [code]import pandas as pd import numpy as np from gekko.ML import Gekko_NN_SKlearn, CustomMinMaxGekkoScaler from sklearn.model_selection import train_test_split from sklearn.neural_network import MLPRegressor from gekko import GEKKO
# Define inputs and output X = ['Tco', 'Tci', 'Teo', 'Tei', 'Tcset', 'Tbuh', 'Twar', 'm_evap', 'm_cond', 'Qth_Total', 'CompOn'] Y = ['Pel']
# Splitting the data into training and testing sets train, test = train_test_split(df, test_size=0.2, shuffle=True)
# Scaling the data using CustomMinMaxGekkoScaler s = CustomMinMaxGekkoScaler(df, X, Y) ds = s.scaledData() mma = s.minMaxValues()
# Further splitting the scaled data into training and testing sets trains, tests = train_test_split(ds, test_size=0.2, shuffle=True)
# Define the structure of the neural network hl = [25, 15] mlp = MLPRegressor(hidden_layer_sizes=hl, activation='relu', solver='adam', batch_size=32, learning_rate='adaptive', learning_rate_init=.0005, tol=1e-6, n_iter_no_change=200, max_iter=12000)
# Train the MLPRegressor model mlp.fit(trains[X], np.ravel(trains[Y]))
# Evaluate the model on the test data r2 = mlp.score(tests[X], np.ravel(tests[Y]))
# Print the R-squared score of the model print('nnSK r2:', r2) [/code] [list] [*]Во втором коде нет ошибки, поскольку я использую одну переменную, т.е. Tco [/list] [code]# Create a Gekko model m = GEKKO()
# Define Tco as a decision variable Tco = m.Var(value=(df['Tco'].min() + df['Tco'].max()) / 2, lb=df['Tco'].min(), ub=df['Tco'].max())
# Predict Pel using the trained neural network and Tco as input predicted_Pel = Gekko_NN_SKlearn(mlp, mma, m).predict([Tco])
# Set the predicted Pel value as the objective to minimize m.Minimize(predicted_Pel)
# Solve the optimization problem m.solve(disp=False)
# Print the optimized Tco and corresponding predicted Pel value print('Optimized Tco:', Tco.value[0]) print('Optimized Predicted Pel:', predicted_Pel.value[0]) print('Gekko Solvetime:', m.options.SOLVETIME, 's') [/code] [b]SOLUTION = Оптимизированная Tco: 297,87489593 Оптимизированный прогнозируемый Pel: 73,999990155 Gekko Solvetime: 0,10799999999 с[/b] [list] [*]В третьем коде отображается ошибка при использовании двух переменных Tco и Tei [/list] [code]# Create a Gekko model m = GEKKO()
# Predict Pel using the trained neural network and Tco as input predicted_Pel = Gekko_NN_SKlearn(mlp, mma, m).predict([Tco, Tei])
# Set the predicted Pel value as the objective to minimize m.Minimize(predicted_Pel)
# Solve the optimization problem m.solve(disp=False)
# Print the optimized Tco and corresponding predicted Pel value print('Optimized Tco:', Tco.value[0]) print('Optimized Predicted Pel:', predicted_Pel.value[0]) print('Gekko Solvetime:', m.options.SOLVETIME, 's') [/code] [list] [*]Появляется эта ошибка Ошибка значения: операнды не могут быть переданы вместе с фигурами (11,) (2,)< /strong> [/list]
При архивировании файлов с помощью конвейера я получаю следующую ошибку:
Cleaning up project directory and file based variables 00:01 ERROR: Job failed: exit status 1
Но при этом все файлы перенес в архив
Вот как выглядит мой пайплайн:...