Issue
I have a regression code which takes data and converts it into numerical one using the one-hot encoder and .. for numerical and categorical values and predicts the temperature (target class). I want to display the actual predicted values for the code rather than the encoded ones.
Here is the code:
# Feature Engineering steps (scaling and encoding)
numerical_cols = data.select_dtypes(include=['number']).columns
categorical_cols = data.select_dtypes(exclude=['number']).columns
scaler = MinMaxScaler()
data[numerical_cols] = scaler.fit_transform(data[numerical_cols])
data = pd.get_dummies(data, columns=categorical_cols, drop_first=True)
# Reverse the temperature scaling to get original values
temperature_scaler = MinMaxScaler()
temperature = data['Temperature set at home '].values.reshape(-1, 1)
data['Temperature set at home '] = temperature_scaler.fit_transform(temperature)
# Split the data into features (X) and target variable (y)
X = data.drop(columns=['Temperature set at home '])
y = data['Temperature set at home ']
# Split the data into training (X_train) and testing sets (X_test, y_train, y_test)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
How to display the predicted actual values rather than the encoded predicted ones?
Solution
y_pred = reg_model.predict(X_test)
predicted_values = temperature_scaler.inverse_transform(y_pred.reshape(-1,1))
print(predicted_values)
Answered By - vinayjr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.