Finding minimum value dependent variable from model and extracting values of independent variables - python

12 views Asked by At

For a project I had to use machine learning with regression with mulitple independent variables I now have a well fitting model based on random forest regression in python

the next step is to find the global minimum of that model by setting ranges for the independent variables and then have the code spit out the values of these independent variables that result in the minimum

so basicly

find minimum of model (y) --> give values of independent variables at y (x1, x2,x3,x5...,xn), where independents have a certain range, and there is a lower limit of y which cannot be suprassed

any clue how to do this?

sofar the model seems to be able to also predict the value of dependent variable by importing another csv file with random values for each indpendent variable, what I want is to have the code find the minimum value of dependent variable by altering the independent variables and then also give an array of values for these independent variables as the minimum found.

The part of training/testing the model and also predicting new data is below, I want to add the "optimisation by minimization" to this

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

%matplotlib inline

#Importing data
#Make sure data set is in CSV format and in same folder as code
df = pd.read_csv('N2PSA_1.csv')
df

# Splitting data into X - variables and Y - target
X = df[['Temperature [C]', 'Oxygen Concentration [ppm]', 'HCT [sec]',
       'Purge [%]', 'Purge [nm3/h]', 'Ratio Receiver/Bed Volume',
       'Ratio Void/Bed Volume', 'Ratio Bed Length/Diameter',
       'Bed density [g/l]']]
y = df['MFC Air Demand']

# Split into training and testing set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.29, random_state=50)

# Model 4 Random Forest Regression
from sklearn.ensemble import RandomForestRegressor
RF = RandomForestRegressor()
# Train the model
RF.fit(X_train,y_train)
# Predict on test data
predictRF=RF.predict(X_test)

from sklearn.metrics import mean_squared_error, r2_score
plt.scatter(y_test, predictRF)
plt.ylabel('Predicted')
plt.xlabel('Actual RF')
print('RMSE: %.4f' % np.sqrt(mean_squared_error(y_test, predictRF)))
print('r2 score: %.4f' % r2_score(y_test, predictRF))

# Below untested data is put in to predict results based on chosen model

# Importing experimental data variables (variables should be of same type as test/train variables)
# Make sure dataset is in CSV format and in same folder as code
X_exp = pd.read_csv('N2PSA_test.csv')
X_exp
# Predict on experimental data
predictexp=RF.predict(X_exp)
predictexp

# Lets optimise the process
# Should spit out values of input variables by finding the minima of dependent variable


0

There are 0 answers