So I have my type error says “float() argument must be a string or a real number, not ‘dict'”.
How could I fix this problem?
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
def get_user_input():
features = {}
features["Relative Compactness"] = float(input("Enter Relative Compactness: "))
features["Surface Area"] = float(input("Enter Surface Area (m^2): "))
features["Wall Area"] = float(input("Enter Wall Area (m^2): "))
features["Roof Area"] = float(input("Enter Roof Area (m^2): "))
features["Overall Height"] = float(input("Enter Overall Height (m): "))
features["Orientation"] = input("Enter Orientation (e.g., North, South): ")
features["Glazing Area"] = float(input("Enter Glazing Area (m^2): "))
features["Glazing Area Distribution"] = float(input("Enter Glazing Area Distribution: "))
return features
def build_models(data_path):
data = pd.read_csv(data_path)
features = ["Relative Compactness", "Surface Area", "Wall Area",
"Roof Area", "Overall Height", "Orientation", "Glazing Area",
"Glazing Area Distribution"]
heating_load = data["Heating Load"]
cooling_load = data["Cooling Load"]
X_train, X_test, y_train_heating, y_test_heating = train_test_split(
data[features], heating_load, test_size=0.2, random_state=42)
X_train, X_test, y_train_cooling, y_test_cooling = train_test_split(
data[features], cooling_load, test_size=0.2, random_state=42)
heating_model = LinearRegression()
heating_model.fit(X_train, y_train_heating)
cooling_model = LinearRegression()
cooling_model.fit(X_train, y_train_cooling)
return heating_model, cooling_model
def predict_loads(features, heating_model, cooling_model):
features_reshaped = np.array([features]) # Reshape to 2D array
heating_prediction = heating_model.predict(features_reshaped)[0]
cooling_prediction = cooling_model.predict(features_reshaped)[0]
return heating_prediction, cooling_prediction
def main():
data_path = "ENB2012data.csv" # Replace with your actual data path
heating_model, cooling_model = build_models(data_path)
user_features = get_user_input()
heating_load, cooling_load = predict_loads(user_features, heating_model, cooling_model)
print(f"nPredicted Heating Load: {heating_load:.2f}")
print(f"Predicted Cooling Load: {cooling_load:.2f}")
if __name__ == "__main__":
main()
I have tried searching for results but most of the results are for when the argument is a “list” and not a “dict”
New contributor
Moises is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1