import streamlit as stl import numpy as np from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsRegressor stl.write('this is knn regressor') # Dataset X = np.array([ [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], [9, 10, 11], [10, 11, 12], [11, 12, 13], [12, 13, 14], [13, 14, 15], [14, 15, 16], [15, 16, 17] ]) y = np.array([3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5, 10.0, 10.5]) x_train,x_test,y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=42) from sklearn.neighbors import KNeighborsRegressor from sklearn.metrics import root_mean_squared_error model= KNeighborsRegressor(n_neighbors=3,metric='euclidean') model.fit(x_train,y_train) y_pred = model.predict(x_test) stl.write('this is x_test records') stl.write(x_test) stl.write('this is y_pred') stl.write(y_pred) stl.write('this is y test') stl.write(y_test) if stl.button('click to know error'): stl.write(root_mean_squared_error(y_test,y_pred)) lis = [] for i in range(3): j = stl.number_input(f'enter {i+1} value') lis.append(j) y_pred = model.predict([lis]) if stl.button('click to predict'): stl.write(y_pred)