Question: Python Help! I do not undertsand why I am getting this following error: TypeError: euclidean_distance() missing 1 required positional argument: 'pt2' How do I correct
Python Help! I do not undertsand why I am getting this following error:
TypeError: euclidean_distance() missing 1 required positional argument: 'pt2'
How do I correct it?


In [3]: df.head) Out[3]: trainPoints_x1 trainPoints_x2 trainLabel testPoints_x1 testPoints_x2 testLabel 0 1.947005 4256560 -1.888977 -4.622611 1 1 0.794931 3.558851 -1 4.233796 3.851680 1 2 -0.284977 2.128280 -0.897926 4.132888 -1 3 -1.555300 -3.151837 -1 0.408163 -0.991254 2.961839 -4.012877 4 -0.956221 -1 4.048810 1 Knn Test Euclidean Distance Function In [27]: def euclidean_distance (pti, pt2): distance = np.sqrt(np.sum(pt1-pt2)**2) return distance KNN Algorthim In [34]: def KNN_method (X-train, x_test, Y_train, y_test, *args, k_value): #Empty List where predictions are stored y_hat = [] #Iteration through data for test_pts in x_test.to_numpy: distances = [] for i in range(len(X_train)): #Euclidean distance applied to train and test distances.append(euclidean_distance(np.array(X_train.iloc[i])), test_pts) #Data coverted into Dataframe distance_data = pd.DataFrame(data= distances, columns=['distance'], index= Y_train.index) #stores distance data and selects k_value(closest neighbors) k_neighbors_list = distance_data.sort_values (by=['distance'], axis)[:k_value] #Y values for for k_neighbors List labels = Y_train.loc[k_neighbors_list.index] #Occurences voting = mode(labels).mode[@] #Append it to prediction y_hat.append(voting) return y_hat In [35]: x_train = df.trainPoints_x1 X_test = df.testpoints_x1 Y_test = df [['testlabel"]] Y_train = df[['trainLabel' ]] In [36]: y_hat_test = KNN_method (X_train, x_test, Y_train, y_test, k_value=3) = TypeError Traceback (most recent call last) \AppData\Local\Temp/ipykernel_3840/2565767690.py in
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
