выполняю в юпител лаб вроде все по книге сделал но выдает в конце ошибку import numpy as np import matplotlib.pyplot as plt def visualize_classifier(classifier, X, y, title=''): # Define the minimum and maximum values for X and Y # that will be used in the mesh grid min_x, max_x = X[:, 0].min() - 1.0, X[:, 0].max() + 1.0 min_y, max_y = X[:, 1].min() - 1.0, X[:, 1].max() + 1.0 # Define the step size to use in plotting the mesh grid mesh_step_size = 0.01 # Define the mesh grid of X and Y values x_vals, y_vals = np.meshgrid(np.arange(min_x, max_x, mesh_step_size), np.arange(min_y, max_y, mesh_step_size)) # Run the classifier on the mesh grid output = classifier.predict(np.c_[x_vals.ravel(), y_vals.ravel()]) # Reshape the output array output = output.reshape(x_vals.shape) # Create a plot plt.figure() # Specify the title plt.title(title) # Choose a color scheme for the plot plt.pcolormesh(x_vals, y_vals, output, cmap=plt.cm.gray) # Overlay the training points on the plot plt.scatter(X[:, 0], X[:, 1], c=y, s=75, edgecolors='black', linewidth=1, cmap=plt.cm.Paired) # Specify the boundaries of the plot plt.xlim(x_vals.min(), x_vals.max()) plt.ylim(y_vals.min(), y_vals.max()) # Specify the ticks on the X and Y axes plt.xticks((np.arange(int(X[:, 0].min() - 1), int(X[:, 0].max() + 1), 1.0))) plt.yticks((np.arange(int(X[:, 1].min() - 1), int(X[:, 1].max() + 1), 1.0))) plt.show() from sklearn import linear_model import matplotlib.pyplot as plt from sklearn import linear_model import matplotlib.pyplot as plt #Определение образца входных данных X=np.array([[3.1,7.2],[4,6.7],[2.9,8],[5.1,4.5],[6,5],[5.6,5],[3.3,0.4],[3.9,0.9],[2.8,1],[0.5,3.4],[1,4],[0.6,4.9]]) y=np.array([0,0,0,1,1,1,2,2,2,3,3,3]) #Определение образца входных данных X=np.array([[3.1,7.2],[4,6.7],[2.9,8],[5.1,4.5],[6,5],[5.6,5],[3.3,0.4],[3.9,0.9],[2.8,1],[0.5,3.4],[1,4],[0.6,4.9]]) y=np.array([0,0,0,1,1,1,2,2,2,3,3,3]) #Создание логистического классификатора classifier = linear_model.LogisticRegression(solver='liblinear',C=100) #Создание логистического классификатора classifier = linear_model.LogisticRegression(solver='liblinear',C=100) #Тренировка классификатора classifier.fit(X,y) C:\Users\Ayanami\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:469: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning. "this warning.", FutureWarning) LogisticRegression(C=100, class_weight=None, dual=False, fit_intercept=True, intercept_scaling=1, l1_ratio=None, max_iter=100, multi_class='warn', n_jobs=None, penalty='l2', random_state=None, solver='liblinear', tol=0.0001, verbose=0, warm_start=False) #Визуализация работы классификатора visualize_classifier(classifier,X,y)
from sklearn.naive_bayes import GaussianNB from sklearn.model_selection import cross_validate input_file='data_multivar_nb.txt' data = np.loadtxt(input_file, delimiter=',') X = data[:,:-1] y = data[:,:-1] #Создание наивного байесовского классификатора classifier=GaussianNB #Тренировка классификатора classifier.fit(X,y) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 1 #Тренировка классификатора ----> 2 classifier.fit(X,y)
вроде все по книге сделал
но выдает в конце ошибку
import numpy as np
import matplotlib.pyplot as plt
def visualize_classifier(classifier, X, y, title=''):
# Define the minimum and maximum values for X and Y
# that will be used in the mesh grid
min_x, max_x = X[:, 0].min() - 1.0, X[:, 0].max() + 1.0
min_y, max_y = X[:, 1].min() - 1.0, X[:, 1].max() + 1.0
# Define the step size to use in plotting the mesh grid
mesh_step_size = 0.01
# Define the mesh grid of X and Y values
x_vals, y_vals = np.meshgrid(np.arange(min_x, max_x, mesh_step_size), np.arange(min_y, max_y, mesh_step_size))
# Run the classifier on the mesh grid
output = classifier.predict(np.c_[x_vals.ravel(), y_vals.ravel()])
# Reshape the output array
output = output.reshape(x_vals.shape)
# Create a plot
plt.figure()
# Specify the title
plt.title(title)
# Choose a color scheme for the plot
plt.pcolormesh(x_vals, y_vals, output, cmap=plt.cm.gray)
# Overlay the training points on the plot
plt.scatter(X[:, 0], X[:, 1], c=y, s=75, edgecolors='black', linewidth=1, cmap=plt.cm.Paired)
# Specify the boundaries of the plot
plt.xlim(x_vals.min(), x_vals.max())
plt.ylim(y_vals.min(), y_vals.max())
# Specify the ticks on the X and Y axes
plt.xticks((np.arange(int(X[:, 0].min() - 1), int(X[:, 0].max() + 1), 1.0)))
plt.yticks((np.arange(int(X[:, 1].min() - 1), int(X[:, 1].max() + 1), 1.0)))
plt.show()
from sklearn import linear_model
import matplotlib.pyplot as plt
from sklearn import linear_model
import matplotlib.pyplot as plt
#Определение образца входных данных
X=np.array([[3.1,7.2],[4,6.7],[2.9,8],[5.1,4.5],[6,5],[5.6,5],[3.3,0.4],[3.9,0.9],[2.8,1],[0.5,3.4],[1,4],[0.6,4.9]])
y=np.array([0,0,0,1,1,1,2,2,2,3,3,3])
#Определение образца входных данных
X=np.array([[3.1,7.2],[4,6.7],[2.9,8],[5.1,4.5],[6,5],[5.6,5],[3.3,0.4],[3.9,0.9],[2.8,1],[0.5,3.4],[1,4],[0.6,4.9]])
y=np.array([0,0,0,1,1,1,2,2,2,3,3,3])
#Создание логистического классификатора
classifier = linear_model.LogisticRegression(solver='liblinear',C=100)
#Создание логистического классификатора
classifier = linear_model.LogisticRegression(solver='liblinear',C=100)
#Тренировка классификатора
classifier.fit(X,y)
C:\Users\Ayanami\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:469: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
"this warning.", FutureWarning)
LogisticRegression(C=100, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='warn', n_jobs=None, penalty='l2',
random_state=None, solver='liblinear', tol=0.0001, verbose=0,
warm_start=False)
#Визуализация работы классификатора
visualize_classifier(classifier,X,y)
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import cross_validate
input_file='data_multivar_nb.txt'
data = np.loadtxt(input_file, delimiter=',')
X = data[:,:-1]
y = data[:,:-1]
#Создание наивного байесовского классификатора
classifier=GaussianNB
#Тренировка классификатора
classifier.fit(X,y)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
1 #Тренировка классификатора
----> 2 classifier.fit(X,y)
TypeError: fit() missing 1 required positional argument: 'y'