RuntimeError: внутренняя ошибка NumPy: не удалось найти функцию numpy.core._methods._amin - PullRequest
0 голосов
/ 28 октября 2018

Попытка запустить следующий код:

from __future__ import division, print_function
import numpy as np
import pandas as pd
from sklearn import datasets, svm 
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn import preprocessing, neighbors, svm 

#reads the file and prints it out
df = pd.read_csv('cancer1.txt')
#repalaces all missing values with -99999 because when running 
the program python wil treat those missing values as an 
outlier
# Replace the unassigned values with -99999 and drop the id 
column
df.replace('?', 0, inplace=True)
df.drop(['id'], 1, inplace=True)

print(df)
# Get the features and labels
X1 = np.array(df.drop(['class'], 1))
y1= np.array(df['class'])
X=X1[:120]
y=y1[:120]

X_train, X_test, y_train, y_test = train_test_split(X, y, 
test_size=0.25, random_state=42)
def evaluate_on_test_data(model=None):
predictions = model.predict(X_test)
correct_classifications = 0
for i in range(len(y_test)):
    if predictions[i] == y_test[i]:
        correct_classifications += 1
accuracy = 100*correct_classifications/len(y_test) #Accuracy 
as a percentage
return accuracy
kernels = ('linear','poly','rbf')
accuracies = []
for index, kernel in enumerate(kernels):
model = svm.SVC(kernel=kernel)
model.fit(X_train, y_train)
acc = evaluate_on_test_data(model)
accuracies.append(acc)
print("{} % accuracy obtained with kernel = {}".format(acc, 
kernel))
#Train SVMs with different kernels
svc = svm.SVC(C=1000,kernel='linear').fit(X_train, y_train)
rbf_svc = svm.SVC(C=1000,kernel='rbf', gamma=0.7).fit(X_train, 
y_train)
poly_svc = svm.SVC(C=1000,kernel='poly', 
degree=2).fit(X_train, y_train)

#Create a mesh to plot in
h = .02  # step size in the mesh
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
                 np.arange(y_min, y_max, h))

#Define title for the plots
titles = ['SVC with linear kernel',
      'SVC with RBF kernel',
      'SVC with polynomial (degree 2) kernel']


for i, clf in enumerate((svc, rbf_svc, poly_svc)):
# Plot the decision boundary. For that, we will assign a color 
to each
# point in the mesh [x_min, m_max]x[y_min, y_max].
plt.figure(i)

Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.contourf(xx, yy, Z, cmap=plt.cm.Paired, alpha=0.8)

# Plot also the training points
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.ocean)
plt.xlabel('')
plt.ylabel('')
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.xticks(())
plt.yticks(())
plt.title(titles[i])

plt.show()

But after running it gives me the following error:
File "C:/Users/Jay/Documents/untitled5.py", line 48, in <module>
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
RuntimeError: NumPy internal error: could not find function 
numpy.core._methods._amin

код будет работать до точности, но после этого он выдаст эту ошибку.Любая помощь будет решить это было бы здорово.

1 Ответ

0 голосов
/ 28 октября 2018

Кажется, что установка numpy не работает.

Сначала попробуйте это:

import numpy
numpy.core._methods._amin

Этодолжен вернуть:

<function numpy.core._methods._amin>

Если вы все еще получаете сообщение об ошибке, выполните в терминале следующее:

pip install numpy
...