I have just created a KNN model to train on basic iris data, but when I train and test it, it returns the predicted values but I can’t auto test the accuracy. It is giving me a inhomogeneous error for the shape. Here is the code of the training model.
import numpy as np from sklearn import datasets from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap from KNN import KNN cmap = ListedColormap(['#FF0000','#00FF00','#0000FF']) iris = datasets.load_iris() X, y = iris.data, iris.target X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234) plt.figure() plt.scatter(X[:,2],X[:,3], c=y, cmap=cmap, edgecolor='k', s=20) plt.show() clf = KNN(k=5) clf.fit(X_train, y_train) predictions = clf.predict(X_test) print(predictions) acc = np.sum((predictions == y_test) / len(y_test)) print(acc)
acc = accuracy
Here is the error message
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (30,) + inhomogeneous part.
submitted by /u/Big-Shake1559
[link] [comments]
r/learnpython I have just created a KNN model to train on basic iris data, but when I train and test it, it returns the predicted values but I can’t auto test the accuracy. It is giving me a inhomogeneous error for the shape. Here is the code of the training model. import numpy as np from sklearn import datasets from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap from KNN import KNN cmap = ListedColormap([‘#FF0000′,’#00FF00′,’#0000FF’]) iris = datasets.load_iris() X, y = iris.data, iris.target X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234) plt.figure() plt.scatter(X[:,2],X[:,3], c=y, cmap=cmap, edgecolor=’k’, s=20) plt.show() clf = KNN(k=5) clf.fit(X_train, y_train) predictions = clf.predict(X_test) print(predictions) acc = np.sum((predictions == y_test) / len(y_test)) print(acc) acc = accuracy Here is the error message ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (30,) + inhomogeneous part. submitted by /u/Big-Shake1559 [link] [comments]
I have just created a KNN model to train on basic iris data, but when I train and test it, it returns the predicted values but I can’t auto test the accuracy. It is giving me a inhomogeneous error for the shape. Here is the code of the training model.
import numpy as np from sklearn import datasets from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap from KNN import KNN cmap = ListedColormap(['#FF0000','#00FF00','#0000FF']) iris = datasets.load_iris() X, y = iris.data, iris.target X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234) plt.figure() plt.scatter(X[:,2],X[:,3], c=y, cmap=cmap, edgecolor='k', s=20) plt.show() clf = KNN(k=5) clf.fit(X_train, y_train) predictions = clf.predict(X_test) print(predictions) acc = np.sum((predictions == y_test) / len(y_test)) print(acc)
acc = accuracy
Here is the error message
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (30,) + inhomogeneous part.
submitted by /u/Big-Shake1559
[link] [comments]