Commit 60e83747 authored by Maneka Wijesundara's avatar Maneka Wijesundara

first commit.can input rating and see vet clinics.

parent 29a98757
import pandas as pd
from sklearn.cluster import KMeans
from sklearn.preprocessing import StandardScaler
# Step 1: Collect data (example data)
#data = {
# 'Clinic': ['Clinic A', 'Clinic B', 'Clinic C', 'Clinic D', 'Clinic E'],
# 'Location': [1, 3, 2, 1, 3], # Example feature: Location (1=City, 2=Suburb, 3=Rural)
# 'Rating': [4.5, 3.8, 4.2, 4.9, 3.6] # Example feature: Rating (1-5 scale)
#}
mydf = pd.read_csv('vetClinics.csv',encoding='cp1252')
df=mydf.dropna()
#df = pd.DataFrame(data)
# Step 2: Preprocess the data
features = [ 'rating']
df_features = df[features] # Selecting relevant features
# Standardize the features
scaler = StandardScaler()
df_features_scaled = scaler.fit_transform(df_features)
# Step 3: Apply K-means clustering
k = 2 # Number of clusters
kmeans = KMeans(n_clusters=k, random_state=42)
kmeans.fit(df_features_scaled)
# Step 4: Evaluate and interpret the clusters
df['Cluster'] = kmeans.labels_
# Step 5: Make recommendations
#user_location = int(input("Enter your location (1=City, 2=Suburb, 3=Rural): "))
user_rating = float(input("Enter your preferred rating (1-5 scale): "))
# Scale the user input features
user_input = scaler.transform([[ user_rating]])
# Assign the user input to a cluster
user_cluster = kmeans.predict(user_input)[0]
# Find the unique best clinics in the user's cluster
best_clinics = set(df[df['Cluster'] == user_cluster]['veterinary clinic name'])
print("The suggested vet clinic(s) based on your input are:")
for clinic in best_clinics:
print(clinic)
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment