SPRING CAMP RECRUITMENT TASK import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsRegressor from sklearn.cluster import KMeans import matplotlib.pyplot as plt import gradio as gr
url = "link_to_kaggle_dataset" df = pd.read_csv(url)
print(df.head()) print(df.info())
X = df.drop('SalePrice', axis=1) y = df['SalePrice']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
knn_model = KNeighborsRegressor(n_neighbors=5) knn_model.fit(X_train, y_train)
accuracy = knn_model.score(X_test, y_test) print(f"KNN Model Accuracy: {accuracy}")
kmeans = KMeans(n_clusters=3, random_state=42) df['cluster'] = kmeans.fit_predict(X)
plt.scatter(df['Feature1'], df['Feature2'], c=df['cluster'], cmap='viridis') plt.title('Clustering of Houses based on Features') plt.xlabel('Feature1') plt.ylabel('Feature2') plt.show()
def predict_price(features): features = np.array(features).reshape(1, -1) prediction = knn_model.predict(features)[0] return f'Predicted House Price: ${prediction:.2f}'
iface = gr.Interface(fn=predict_price, inputs="text", outputs="text") iface.launch(share=True)