EdBoy2202 commited on
Commit
11ed7a1
·
verified ·
1 Parent(s): 32f8cee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -70,6 +70,9 @@ def preprocess_car_data(df):
70
  df[col] = le.fit_transform(df[col])
71
  label_encoders[col] = le
72
 
 
 
 
73
  return df, label_encoders
74
 
75
  # Calculate similarity between the classified car and entries in the CSV
@@ -85,6 +88,9 @@ def find_closest_car(df, label_encoders, make, model, year):
85
  feature_columns = ['make', 'model', 'year']
86
  df_feature_vectors = df[feature_columns].values
87
 
 
 
 
88
  # Compute cosine similarity between the classified car and all entries in the CSV
89
  similarity_scores = cosine_similarity(classified_car_vector, df_feature_vectors)
90
 
 
70
  df[col] = le.fit_transform(df[col])
71
  label_encoders[col] = le
72
 
73
+ # Handle NaN values by filling them with a placeholder (e.g., -1 for categorical columns)
74
+ df.fillna(-1, inplace=True)
75
+
76
  return df, label_encoders
77
 
78
  # Calculate similarity between the classified car and entries in the CSV
 
88
  feature_columns = ['make', 'model', 'year']
89
  df_feature_vectors = df[feature_columns].values
90
 
91
+ # Handle NaN values before calculating similarity
92
+ df_feature_vectors = np.nan_to_num(df_feature_vectors) # Converts NaN to 0
93
+
94
  # Compute cosine similarity between the classified car and all entries in the CSV
95
  similarity_scores = cosine_similarity(classified_car_vector, df_feature_vectors)
96